Go Fish/Go: Difference between revisions
Content added Content deleted
(Less idiosyncratic and gofmt'ed.) |
(Improved quality.) |
||
Line 54: | Line 54: | ||
card := gm.deck[0] |
card := gm.deck[0] |
||
gm.deck = gm.deck[1:] |
gm.deck = gm.deck[1:] |
||
if gm. |
if gm.isPlayerTurn() { |
||
fmt.Printf("You drew a %s.\n", card) |
fmt.Printf("You drew a %s.\n", card) |
||
} |
} |
||
Line 60: | Line 60: | ||
//Check for books |
//Check for books |
||
gm.checkForBooks() |
gm.checkForBooks() |
||
⚫ | |||
⚫ | |||
// endPly ends the current person's turn. |
|||
// It then either calls the next person's |
|||
// turn or prints a game over message. |
|||
⚫ | |||
⚫ | |||
if gameOver { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
} |
} |
||
Line 114: | Line 100: | ||
func (gm *GoFishGame) isGameOver() bool { |
func (gm *GoFishGame) isGameOver() bool { |
||
return gm.scores[0]+gm.scores[1] == 13 |
return gm.scores[0]+gm.scores[1] == 13 |
||
⚫ | |||
// isPlayerTurn returns if its the player's turn to move. |
|||
⚫ | |||
⚫ | |||
} |
} |
||
Line 167: | Line 158: | ||
} |
} |
||
} |
} |
||
gm.endPly() |
|||
} |
} |
||
Line 192: | Line 182: | ||
func (gm *GoFishGame) stealCards(purge string, side int) int { |
func (gm *GoFishGame) stealCards(purge string, side int) int { |
||
count := 0 |
count := 0 |
||
tList := gm.hands[side] |
|||
var filtered []string |
var filtered []string |
||
for _, card := range |
for _, card := range gm.hands[side] { |
||
if purge == card { |
if purge == card { |
||
count++ |
count++ |
||
Line 218: | Line 207: | ||
scores[1] = 0 |
scores[1] = 0 |
||
game := GoFishGame{hands, deck, 0, scores} |
game := GoFishGame{hands, deck, 0, scores} |
||
for { |
|||
game.playerTurn(getPickUser) |
|||
if game.isPlayerTurn() { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
break |
|||
} |
|||
⚫ | |||
⚫ | |||
} |
} |
||
</lang> |
</lang> |