'21 is a two player game, the game is played by choosing a number
'(1, 2, or 3) to be added to the running total.
'The game is won by the player whose chosen number causes
'the running total to reach exactly 21.
'The running total starts at zero. One player will be the computer.
'Players alternate supplying a number to be added to the running total.
'Task
'Write a computer program that will:
'do the prompting (or provide a button menu),
'check for errors and display appropriate error messages,
'do the additions (add a chosen number to the running total),
'display the running total,
'provide a mechanism for the player to quit/exit/halt/stop/close the program,
'issue a notification when there is a winner, and
'determine who goes first (maybe a random or user choice, or
'can be specified when the game begins).
Const Errline
= 18, Promtline
= 14, Ends
= 27 intro
Initialize NamePl1, NamePl2, TotalScore
ActivePlayer = NamePl1
TotalScore = TotalScore + ChooseCPU(TotalScore)
Valchoose = ChooseHuman(ActivePlayer)
If Valchoose
= 0 Then Valchoose
= Quit
(ActivePlayer
) TotalScore = TotalScore + Valchoose
If TotalScore
< 21 Then If ActivePlayer
= NamePl1
Then ActivePlayer
= NamePl2
Else ActivePlayer
= NamePl1
Winning ActivePlayer
Quit = 0
char = ""
box 10, 10, 12, 75
Quit = ChooseHuman(who)
box 5 + count, 10 + count, 20 - count, 75 - count
Print "WINNER IS...." + who
ChooseHuman = 0
char = ""
box 10, 10, 12, 75
Locate 11, 11:
Print who;
" Make your choice...1,2,3 or 0 to quit ";
Pl1 = TakeName("player1")
Pl2 = TakeName("player2")
Pl1 = TakeName("player1")
Pl2 = "CPU"
Pl1 = "CPU"
Pl2 = TakeName("player2")
Pl1 = "CPU"
Pl2 = TakeName("player2")
Pl1 = TakeName("player1")
Pl2 = "CPU"
Tscore = 0
TakeName$ = ""
Name1 = ""
Cancelbox 10, 10, 24, 75
box 10, 10, 12, 70
If char
<> "" And InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", char
) Then Name1
= Name1
+ char
TakeName$ = Name1
whatTurn = 0
While choice
<> "F" And choice
<> "S" And choice
<> "R" box Promtline - 1, 10, Promtline + 2, 75
Locate Promtline
, 11:
Print "Do you play as First (F) or Second (S) or at Random (R)? ";
box Errline - 1, 10, Errline + 2, 75
If choice
<> "F" And choice
<> "S" And choice
<> "R" Then choice
= "":
Locate Errline
, 11:
Print "Please choose F, S or R "
ink = 0
box Promtline - 1, 10, Promtline + 2, 75
Locate Promtline
, 11:
Print "Do you play against a friend (F) or CPU (C)? ";
box Errline - 1, 10, Errline + 2, 75
If Choice
<> "F" And Choice
<> "C" Then Locate Errline
, 11:
Print "Please choose F or C": Choice
= ""
box 9, 9, 18, 75
Locate 12, 10:
Print " This is the 21 game. Rules are easy, you must reach 21 score:" Locate , 10:
Print " 1. you can choose if you play against a friend (F) or CPU (C)" Locate , 10:
Print " 2. you can choose to start as First (F) or Second (S) player " Locate , 10:
Print " 3. finally you can play choosing 1,2 or 3 and 0 to quit."
For count
= 1 To (x2
- x1
- 1)
Sub Cancelbox
(x1
, y1
, x2
, y2
)