Download presentation
Presentation is loading. Please wait.
Published byLewis Hood Modified over 9 years ago
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# 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”
2
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 4 gPlayerHand(counter) = “” gComputerHand(counter) = “” END FOR FOR 0 to 51 gPlayPack(counter) = “” END FOR gPlayerScore = 0 gComputerScore = 0
3
ShufflePack Used(52) is an integer array Valid is a Boolean Index is an integer FOR 0 to 51 REPEAT valid = true INPUT Index randomly IF Used(Index) = TRUE then valid = false ELSE Used(Index) = TRUE ENDIF UNTIL Valid = true gPlayPack(counter) = gPack(Index) END FOR
4
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
5
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
6
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. OutcomePlayerComputerWho has won BustYes Draw BustYesNoComputer BustNoYesPlayer 21YesNoPlayer 21NoYesComputer 21Yes Computer 5 CardYesNoPlayer 5 CardNoYesComputer 5 CardYes Computer Higher scoreYesNoPlayer Higher scoreNoYesComputer Higher scoreNo Computer
7
DrawCard REPEAT valid = TRUE Index = random number 0-51 IF gPlayPack(index) = “” THEN valid = FALSE ELSE card = gPlayPack(Index) gPlayPack(Index) = “” ENDIF UNTIL valid = true RETURN card NOTE: If you have implemented the Shuffle function you could just draw cards from gPlayPack in sequence rather than randomly.
8
ReturnValue FOR 0 to 4 SELECT CASE Cards(Counter) Case Aces value = value + 1 or value = value + 11 Case 2svalue = value + 2 Case 3svalue = value + 3 Case 4svalue = value + 4 Case 5svalue = value + 5 Case 6svalue = value + 6 Case 7svalue = value + 7 Case 8svalue = value + 8 Case 9svalue = value + 9 Case 10svalue = value + 10 Case Jacksvalue = value + 10 Case Queensvalue = value + 10 Case Kingsvalue = value + 10 OUTPUT Value RETURN VALUE
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.