275_Final_Project

.pdf

School

California State University, Long Beach *

*We aren’t endorsed by this school

Course

275

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

61

Uploaded by KidMosquitoMaster430

Report
Final Report Introduction: We will write a C++ program that will simulate the Go Fish Card Game for multiple players including A.I. The project will contain the following classes: GoFishGame, Player, Mode, PlayerProfile, PlayByPlay, Account, and more if needed, each providing many functions and dynamics of the game. A menu will also be provided for easy accessing for the user and records that will allow the player to see game statistics. At the start of the game, each player is given $2000. A victory will earn players $1000 while losing results in $1000 loss. The distribution of money depends on the number of players involved, further influencing strategy players must make throughout the game. Through this simulation, the project will provide players to enjoy the Go Fish Game while learning the ins and outs of the code. Pseudocodes: card.cpp Rank (integer variable) Suit (integer variable) - Card(): Set rank to 0 Set suit to 0 - printCard(): Output “Rank: <rank value>” Output “Suit: <suit value>” deck.cpp - Deck():
Array with 52 card objects Set numCards to 52 Set count to 0 For each rank from 0 to 12 (13 ranks) For each from 0 to 3 (4 suits) Set cards[count] rank to rank Set cards[count] suit to suit Increment count - ~Deck(): Delete the cards array - getCards(): Return the cards array - shuffleDeck(): Random number generator Repeat 1000 times: Generate two random cards Swap cards - deal(): Create Card object draw and set it to cards Subtract numCards by 1 Return draw - printDeck(): For each card in cards up to numCards: Output “Rank: <rank value> Suit: <suit value>” game.cpp - Game():
Set isGameOver to false - intToRank(rank): Create an array with ranks Return ranks - gameOver(): If the game is over: set isGameOver to true Else: set isGameOver to false - displayGame(): Output the current status of the game - checkInput(question, valid): Do-while loop using question to only accept inputs that are valid Return integer input - checkAndChoose(): If player has fewer than 1 card in hand and the game is not over: Draw a card Display current game status Set index to checkInput, asks user to select a card Set rankChosen to the rank of card at index in player’s hand Output result Return rankChosen - checkAndRand(): Computer draws a card (if cpu game) Add card to hand Display game status Generate a random index randInd Set rankChosen to a randInd
Computer asks for the chosen randInd card Return rankChosen - compHasMatch(rankChosen): Count and remove cards of rankChosen from player’s hand Add the removed cards to player’s hand If count > 0: Computer gives you count If the player's hand has a book of rankChosen: “You got a book!” Remove the book from player - humHasMatch(rankChosen): Similar to the above code - humFish(rankChosen, &myTurn): Output “You Go Fish.” Deal a card from the deck and gets its rank Output “You draw a <rank value>” Add dealt card to hand If rankDealt is equal to rankChosen: Output “You fished for what you wanted!” Remove the book from players Else: If players hand has a book of rankChosen: Output “You got a book!” Remove the book from players Output “COMPUTER’S TURN!” - compFish(rankChosen, &compTurn): Output "Computer Go Fish."
Deal a card from the deck and get its rank rankDealt Output "Computer draws a card." Add the dealt card to players’s hand If rankDealt is equal to rankChosen: Output "Computer fished for what it wanted!" If players[0]'s hand has a book of rankChosen: Output "Computer got a book!" Remove the book from players Else: If players's hand has a book of rankDealt: Output "Computer got a book!" Remove the book from players Output "YOUR TURN!" - humanTurn(): Display the current game status Set myTurn to true While the game is not over and myTurn: Get rankChosen from checkAndChoose() If player's hand has a rank of rankChosen: Call compHasMatch(rankChosen) Else: Call humFish(rankChosen, myTurn) Call gameOver() - compTurn(): Display the current game status Set compTurn to true
While the game is not over and compTurn: Get rankChosen from checkAndRand() If player's hand has a rank of rankChosen: Call humHasMatch(rankChosen) Else: Call compFish(rankChosen, compTurn) Call gameOver() - beginTurns(): Shuffle the deck For i from 0 to 6: Add a card dealt from the deck to players[0]'s hand For i from 0 to 6: Add a card dealt from the deck to players[1]'s hand While the game is not over: Call humanTurn() Call compTurn() Output "GAME OVER" Display the current game status If players[0] has more books than players[1]: Output "Computer Wins!" Else: Output "You Win!" GoFishGame.cpp - Card: contains rank and suit - Getters and setters: for rank and suit - Deck class: array of cards that contains up to 52, ranks from 0 to 12 and suit from 0 to 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help