Design8Solution - CSE 335 Design Assignment 8 Solution A...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 335 Design Assignment 8 Solution A Simple Blackjack Game You are designing the code for a simplified game of Black ack. lam proViding you With the class for the main Window for this game below. The user interface Will call funmions in that class to play the game. The game proceeds as follows When the game begins, the player has $1000 in chips There are three decks of cards in the shoe, a box that holds decks of cards and allows the dealer to draw one card at a time. The system displays a message asking the user to place a bet The user enters a number in a box in the user interface and hits the Bet button That amount is not dedumed from their chips at this time The system then gives the player two cards face up and the dealer one card face up and one card face down (the hole card). Cards are removed from the shoe The player can press the Hit or Stand buttons. Hit means a new card is added to the player‘s hand. If the total exceeds 21, the player is bust and the system displays “Bust” for2 seconds, discards all hands, and returns to asking for a bet. lf the total does not exceed 2‘l, they player can again press Hit or Stand Then Stand is pressed, the system proceeds to the dealer phase. After the player stands, the dealer reveals the hole card for one second lfthe dealer total equals or EXCEEdS l7, the dealer phase is complete and we move to the scoring phase. OtherWise, the dealerdraws another card Drawmg continues until the dealer reaches at least 17 orgoes bust (more than ET) The bet is deducted from the player‘s chips. The scoring works like this: Ifthe playerhas a blackjack (a ‘lO [‘lO,Jack, Queen, or King] and an ace) and the dealerdoes not, the player Is paid ‘l.5times the bet lfthe player and dealer both have blackjack, nobody is paid anything (a push). lfthe player total eXCeeds the dealer, the player is paid the amount of the bet. lfthe player equals the dealer, nobody is paid (a push). Otherwrse, the player loses the bet The scoring resutt is presented for2 seconds, then the system returns to Waiting for the user to place a bet. At any time the user can hit the Quit button to quit the game. That closes the Window. The Blackjack Class Here is the Blackiack class you Will start With: wxWindow playerChips double = 1000 Start() SetTimer(in seconds: double) OnTirnerO OnPaintl) OnHit() OnStandO OnBet(in amount : double) OnQurtn The function Start is called to stan a game lt initializes the system A call to SetTimer with an amount of Seconds Will result in OnTimer being called that many seconds later. OnPaint is called to draw the screen. You may assume all functionality to draw Is contained in OnPaint (don‘t worry about the draWing part ofthis). DnHit, DnStand, OnBet, and DnQuit are called by pressing buttons on the screen You may add anything you want to the Blackiack class Tasks l. Design a set of classes to implement the game ofBlackjack and draw a UML class diagram of your design. lnclude all of attributes and operations you feel you need at this time to implement game play Don‘t worry about the Window drawmg functionality. <<enum>> Suite wxWindow DrawCard() Card ShuffleO Blackjack playerChips double : 1000 bet: double = 0 Start() SetTimer(in seconds double) OnTimer() OnPaint OnHit() 0 p'ayermm ClearHand() <<enum>> OnSIando 1 AddCard(in card Card) Value OnBet(in amount : double) IsBustO ' bool Ace: OnQU|[() AddHoleCardtin card: Card) Two: RevealHoIeCard() Three : deale‘Hand1 Total() int Four: mate Five: <<enum>> i Six: “3'”? Seven: WaitingForBet : Eight: HitOrStand : Nine : Bust: Ten: RevealHoleCard : Jack: DisplayScoring: Queen: Done. King: I did say to not worry about Window drawrng functionality, sol left out operations to draw the hands and show At the Very lead you needed a representation for the cards, shoe, and two hands You also needed the state variable to support the state machine 2. Create a UML sequence diagram to illustrate the process starting With the call to DnHitO all of the way until the new card is shown, assuming the player does not go bust. 3% :Player | | | l OnHitt) | l LJI Hwbdl UU card AddCardt) u. IsBust() g —.r < ................................... "false. ........... .. ¢—' Retresn This was pretty straight—forward You draw a card from the shoe and add it to the hand You could have had a return value from AddCard rather than the separate lsBustl) function. 3, Create a UML state diagram for this system including all events, guard conditions, and efiects after 2 seconds I discard onQUIt RevealHoleCard aflert second [total < 17 afterl second [total<17]idraw . g - DealerDraw after 1 second [total >= 17] f drawCar DisplayScoring second [total > 17] after 2 seconds Winning a hand is not a state, A state is display the scoring, be it a win or a loss in my implementation, i assume DealerDraw scan draw the card, then test the guard condition, That‘s easy to Implement, but would have to he made clear In the documentation, Using a nested state made this diagram much simpler. Notes No, this does not include all of the rules of Blackjack, it‘s scaled down for your enjoyment, In Bouml you have to create a state machine first (right click) Then you create a state machine diagram by right clicking on the state machine You can drag a state into another state in the state machine in Bouml to make nested states, In Bouml, doubleclick on a transition in a state diagram, SEIEIII the Dcl tab and you can enter the trigger (event), guard condition, and effect (adiwty expression), You‘ll haVe to change thedrawing settings to enable show transition definition to see this information, Be sure you repreSent your cards and where they can be at any given time, Many elements otthe game description won't appear in any of your diagrams. Be careful how you represent the shoe rt's a “thing” Design as ifyou were going to implement your design Who knows, maybe that will be Project 3? Do not expend to do #1, then #2, then #3 You‘ll have to move back and forth betWeen the steps as you refine your design and you may find that you want to do a completely different order l have intentionally left many details up to you For example, i indicated a couple oftimes that the sys1em should pause for 2 Seconds But, if you want to have cards appear suddenly or one at a time, that is up to you Be sure your sequence diagram matches who you chose to implement this, You may just delete cards when you are done with them or you can create a discard pile Don‘t worry about what happens when the shOe is empty We‘re not designing that far ahead right now, Be careful about what states are, For example is Winning a hand a state? ...
View Full Document

This note was uploaded on 12/12/2010 for the course CSE CSE 335 taught by Professor Owen during the Fall '10 term at Michigan State University.

Page1 / 2

Design8Solution - CSE 335 Design Assignment 8 Solution A...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online