Three Dice
' ############################################################
' Three Dice INTRODUCTION
' ############################################################
' Three Dice is a simple text gambling game. Naturally, it is
' also a dice game. If you want to know how the game is played
' give it a test run and read the instructions that are presented.
' ############################################################
' INITIALIZATION
' ############################################################
' This is the initialization section. This is where everything
' the game needs to run is set up.
' ============================================================
' SETTING UP FreeBASIC
' ============================================================
' The first thing that needs to be set up is FreeBASIC itself.
' ------------------------------------------------------------
' OPTION EXPLICIT
' ------------------------------------------------------------
' 'option explicit' forces the programmer to 'dim' all his
' variables before he attempts to use them. This is a way
' of preventing bugs (usually in the form of mispellings) from
' creeping into the game.
option explicit
' ------------------------------------------------------------
' RANDOMIZE TIMER
' ------------------------------------------------------------
' 'randomize timer' seeds the random number generator. This
' needs to be done if the game generates random numbers.
randomize timer
' ============================================================
' CREATING VARIABLES
' ============================================================
' Three Dice uses four variables. Variables are like boxes that
' hold information your game needs. All of the variabes are
' declared (created) with 'dim' and decalred as 'shared'. Using
' 'shared' with 'dim' allows subroutines ( ' sub ... end sub ')
' to "see" a variable.
' Otherwise, the subroutines wouldn't know they existed.
' ------------------------------------------------------------
' money variable
' ------------------------------------------------------------
' The player has a limited amount of money. The variable 'money'
' holds whatever money they player has. 'as integer' means that
' this variable can hold a whole number, as opposed to text
' (a string).
' The player begins with 100 dollars. This value is given to
' 'money' in the 'init' subroutine. (see below)
dim shared money as integer
' ------------------------------------------------------------
' dieNumber variable
' ------------------------------------------------------------
' During every "round" of play the player will be asked to enter
' the number of the face of the die that he wants to bet on.
' dieNumber is used to store this input.
dim shared dieNumber as integer
' ------------------------------------------------------------
' bet variable
' ------------------------------------------------------------
' The player can bet as much as he likes (assuming he has enough
' money). When the player is asked how much he bets, the 'bet'
' varaible holds the amount.
dim shared bet as integer
' ------------------------------------------------------------
' answer variable
' ------------------------------------------------------------
' In the 'init' subroutine, the player is asked if he wants
' instructions. He is instructed to enter a "y" or a "n".
' 'answer' holds the player's answer to this question.
dim shared answer as string
' ============================================================
' SUBROUTINES
' ============================================================
' To make the organization of the game code logical and easy
' to manage, most of the code is separated into subroutines
' that do a specific task. A subroutine begins with 'sub' and
' ends with 'end sub'. All the code in between is executed
' only when the subroutine name is called.
' For example, to show the title of the game, all the programmer
' has to do is use the 'title' subroutine's name. Like this :
' title
' You will see this in action during the game loop.
' ------------------------------------------------------------
' title Subroutine
' ------------------------------------------------------------
' The 'title' subroutine displays the title of the game. It is
' used only once at the beginning of the game.
sub title
' 'print', as it is used here, displays whatever text is between
' double quotes.
print "Three Dice"
print "by the Game Designers of Game Design Novice"
' 'sleep' pauses the game for a number of milliseconds. 1000
' miliseconds are 1 second.
sleep 1000
print "based on No Sweat by Tim Hartnell"
sleep 1000
end sub
' ------------------------------------------------------------
' init Subroutine
' ------------------------------------------------------------
' The 'init' subroutine sets the initial value of 'money' to
' 100 and thus gives the player his starting cash. It also
' asks
sub init
' Here 'money' is set to 100
money = 100
' If 'print' is used by itself it displays a blank line
print
print "Would you like instructions? (y/n)"
' 'input' stops the game and allows the player to enter a line of
' input. When the player is done, he hits ENTER. Then 'input' puts
' the entered information into a variable and resumes the game.
' In this case, 'input' will put the answer in the variable named
' 'answer'. The first part : " > ", is a prompt. It is displayed
' so the player will know where his text will appear as he types it.
input " > ", answer
' The 'if-then' statement below will execute the code between 'then'
' and 'end if' if the condition between 'if' and 'then' is true
' The condition tested may look a bit tricky at first. In essensce,
' if the player entered a "y" then 'answer = y' so the condition is
' true. 'lcase(answer)' converts whatever text the player entered to
' lower case text. This way, even if the player enters a capital "Y"
' the condition will be true.
if lcase(answer) = "y" then
sleep 1000
' 'cls' clears the screen.
cls
print "Three dice is a game of dice."
print "It is played like this :"
sleep 3000
print
print ,"1. You choose a number from 1 to 6"
sleep 2000
print ,"2. You place a bet."
sleep 2000
print ,"3. The bet is taken by the dice roller."
sleep 2000
print ,"4. Three dice are rolled, one by one."
sleep 2000
print ,"5. For every die that rolls your number,"
print ," you win the amount of your bet."
print
print "Press any key to continue..."
sleep
end if
end sub
page_revision: 1, last_edited: 1208998337|%e %b %Y, %H:%M %Z (%O ago)