Go Fish/Go: Difference between revisions

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