Example #1
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}))
}
Example #2
0
func broadcastNoContest(currentGame *game.Game) {
	var message = message.NewMessage(message.MESSAGE_TYPE_NO_CONTEST,
		message.NoContestMessagePart{})

	for _, playerId := range currentGame.Players {
		websocket.JSON.Send(connections[playerId], message)
	}
}
Example #3
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)
	}
}
Example #4
0
func sendDropGroupUpdate(playerId int, messagePart message.DropGroupUpdateMessagePart) {
	var msg = message.NewMessage(message.MESSAGE_TYPE_DROP_GROUP_UPDATE,
		messagePart)
	var ws = connections[activeGames[playerId].GetOpponentId(playerId)]
	websocket.JSON.Send(ws, msg)
}