8
Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack # a procedure to generate a random list of 52 cards call PlayerGo # a procedure to deal with the players go first call ComputerGo # a procedure to deal with the computers go call CheckResults # a procedure to check to see who has won REPEAT OUTPUT “Do you want to play again?” INPUT Choice UNTIL Choice = “Y” or “N” WHILE Choice = “Y”

Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

Embed Size (px)

Citation preview

Page 1: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

Main Program

Repeatcall InitialiseVar # a procedure to reset all variablescall ShufflePack # a procedure to generate a random list of 52 cardscall PlayerGo # a procedure to deal with the players go firstcall ComputerGo # a procedure to deal with the computers gocall CheckResults # a procedure to check to see who has won

REPEATOUTPUT “Do you want to play again?”INPUT Choice

UNTIL Choice = “Y” or “N”

WHILE Choice = “Y”

Page 2: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

InitialiseVar

gPack = "ac", "2c", "3c", "4c", "5c", "6c", "7c", "8c", "9c", "tc", "jc", "qc", "kc", "ad", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "td", "jd", "qd", "kd", "as", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "ts", "js", "qs", "ks", "ah", "2h", "3h", "4h", "5h", "6h", "7h", "8h", "9h", "th", "jh", "qh", "kh“

FOR 0 to 4gPlayerHand(counter) = “”gComputerHand(counter) = “”

END FOR

FOR 0 to 51gPlayPack(counter) = “”

END FOR

gPlayerScore = 0gComputerScore = 0

Page 3: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

ShufflePack

Used(52) is an integer arrayValid is a BooleanIndex is an integer

FOR 0 to 51REPEAT

valid = trueINPUT Index randomlyIF Used(Index) = TRUE then

valid = falseELSE

Used(Index) = TRUEENDIF

UNTIL Valid = true

gPlayPack(counter) = gPack(Index)END FOR

Page 4: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

PlayerGo

#Draw the first two starting cards.

• Draw the first two starting cards (This can be done with a DrawCard Function)• Display the cards drawn• Work out the value of these cards (This can be done with a ReturnValue function)• Display the value of these cards• Repeat until player “Sticks” or is bust or scores a 5 card trick

• Ask if player wants to twist or stick• Draw a new card if player “twists” (Using DrawCard)• Work out new value of hand (Using ReturnValue)• Check to see if you have bust (greater than 21)

• Work out the final score whether the player has bust or not

Page 5: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

ComputerGo

#Draw the first two starting cards.

• Draw the first two starting cards (This can be done with a DrawCard Function)• Display the cards drawn• Work out the value of these cards (This can be done with a ReturnValue function)• Display the value of these cards• Repeat until computer “Sticks” or is bust or scores a 5 card trick

• Computer will twist if cards are under a certain value (16) and not already 21• If twist - Draw a new card (DrawCard)• Work out new value of hand (Using ReturnValue)• Check to see if computer has bust (greater than 21)

• Work out the final score whether the player has bust or not

Page 6: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

CheckResults

• Count number of cards each play has got.• Display number of cards and total score for Player and the Computer• Check to see who has won.Outcome Player Computer Who has won

Bust Yes Yes Draw

Bust Yes No Computer

Bust No Yes Player

21 Yes No Player

21 No Yes Computer

21 Yes Yes Computer

5 Card Yes No Player

5 Card No Yes Computer

5 Card Yes Yes Computer

Higher score Yes No Player

Higher score No Yes Computer

Higher score No No Computer

Page 7: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

DrawCard

REPEATvalid = TRUEIndex = random number 0-51IF gPlayPack(index) = “” THEN

valid = FALSEELSE

card = gPlayPack(Index)gPlayPack(Index) = “”

ENDIFUNTIL valid = true

RETURN card

NOTE:If you have implemented the Shuffle function you could just draw cards from gPlayPack in sequence rather than randomly.

Page 8: Main Program Repeat call InitialiseVar # a procedure to reset all variables call ShufflePack# a procedure to generate a random list of 52 cards call PlayerGo#

ReturnValue

FOR 0 to 4

SELECT CASE Cards(Counter)Case Aces value = value + 1 or value = value + 11Case 2s value = value + 2Case 3s value = value + 3Case 4s value = value + 4Case 5s value = value + 5Case 6s value = value + 6Case 7s value = value + 7Case 8s value = value + 8Case 9s value = value + 9Case 10s value = value + 10Case Jacks value = value + 10Case Queens value = value + 10Case Kings value = value + 10

OUTPUT Value

RETURN VALUE