Blackjack
how to think of this design from stratch?
casual thought: abstract cards /// how to play? //// what's the role in the game? ///what's the process of game?
game OOD thought path:
- (static)游戏道具和游戏状态的描述
- (dynamic)游戏规则和游戏流程
道具:
- card (注意,这个时候不要引入游戏具体的规则)
- deck(公共牌堆) 目前还不用考虑弃牌堆,只要考虑如果deck没有足够的牌,需要reset就好了
- keep a list, store all the cards
- keep a boolean array, index, left of which is used, right of which is not used,
- set boolean array to the false, and shuffle the list.
游戏状态
- 公共牌堆的剩余的牌
- 每个玩家手里的牌,点数
- 玩家
step 1:
Design a generic deck of cards
- what kind of classes we need to define and
write the suit, card, deck class
for the deck class, there are some methods that we need to consider,
- dealhand()
- reset() -> shuffle()
step 2:
- design hand (手里的牌)
- List<Card> or Card[]
- addCards(Card[] ) 抓牌
- int getScore()
- BlackJackHand extends Hand {...}
- int getScore()...
step 3:
- How to simulate the BlackJack game?
- game status s1 -> rules + actions -> s2 -> check end ->continue;
- shuttle
- initialDeal
- for (every hand) {
- while (!checkhandend()) {
- dealtHand()
- }
- // get the score for this player
- while (!checkhandend()) {
- declare winner