示例#1
0
func broadcastStart(currentGame *game.Game) {
	// Initial drop will be the same for both players.
	var message = message.NewMessage(message.MESSAGE_TYPE_START,
		message.StartMessagePart{currentGame.InitialDrops()})

	for _, playerId := range currentGame.Players {
		websocket.JSON.Send(connections[playerId], message)
	}
}
示例#2
0
func signalNextTurn(playerId int, dropGroup *[2]gem.Gem, punishments *[][]*gem.Gem, playerLost bool) {
	var currentGame *game.Game = activeGames[playerId]
	var opponentId int = currentGame.GetOpponentId(playerId)
	var opponentPunishments int = currentGame.GetTotalPunishments(opponentId)
	var playerBoard = currentGame.Boards[currentGame.GetPlayerOrdinal(playerId)]
	var playerScore = currentGame.Scores[currentGame.GetPlayerOrdinal(playerId)]

	// Tell the player the next turn info
	var playerMessage = message.NewMessage(message.MESSAGE_TYPE_NEXT_TURN,
		message.NextTurnMessagePart{*dropGroup,
			punishments,
			playerScore,
			opponentPunishments,
			playerLost})

	websocket.JSON.Send(connections[playerId], playerMessage)

	websocket.JSON.Send(
		connections[opponentId],
		message.NewMessage(message.MESSAGE_TYPE_UPDATE,
			message.UpdateMessagePart{opponentPunishments,
				0,
				playerScore,
				playerBoard.Board,
				currentGame.CurrentDropForPlayer(playerId),
				playerLost}))
}