public void JoinGame(string creatorsIpAddress, PlayerDetails activePlayer) { if (!QueueContainsMessage(creatorsIpAddress, eProtocol.GameJoined)) { string messageText = Serialiser.SerializeToXml<PlayerDetails>(activePlayer); NetworkMessage message = new NetworkMessage() { RecipientsIP = creatorsIpAddress, MessagePacket = new NetworkMessagePacket() { Command = eProtocol.GameJoined, MessageText = messageText } }; AddMessageToQueue(message); } }
public void SetActivePlayer(string playerIP, PlayerDetails activePlayer) { string messageText = Serialiser.SerializeToXml<PlayerDetails>(activePlayer); NetworkMessage message = new NetworkMessage() { RecipientsIP = playerIP, MessagePacket = new NetworkMessagePacket() { Command = eProtocol.SetActivePlayer, MessageText = messageText } }; AddMessageToQueue(message); }
public void SetStartPlayer() { int player = 0; int startPlayer = m_randomiser.Next(GameSettings.Settings.PlayersJoined.Count + 1); foreach (string playerIP in m_activePlayer.Keys) { m_activePlayer[playerIP].Active = (player == startPlayer); if (player == startPlayer) { m_currentActivePlayer = m_activePlayer[playerIP]; } player++; } }
private void SetActivePlayer(PlayerDetails activePlayer) { // If the player is our IP Address AND is active then it is our turn. if (activePlayer.IpAddress == m_localNetwork.IpAddress && activePlayer.Active) { m_turnState = eTurnState.PlayersTurn; if (TurnIndicator != null) { TurnIndicator("Your Turn"); } } else { m_turnState = eTurnState.OpponentsTurn; if (TurnIndicator != null) { TurnIndicator("Waiting on " + activePlayer.Name); } } }
private void NextActivePlayer() { bool activateNext = false; string firstIP = string.Empty; string playerToDeactivate = string.Empty; string playerToActivate = string.Empty; foreach (string playerIP in m_activePlayer.Keys) { if(firstIP.Length == 0) { firstIP = playerIP; } if (activateNext) { activateNext = false; playerToActivate = playerIP; break; } else if (m_activePlayer[playerIP].Active) { playerToDeactivate = playerIP; activateNext = true; } } if(playerToDeactivate.Length > 0) { m_activePlayer[playerToDeactivate].Active = false; } if (playerToActivate.Length > 0) { m_activePlayer[playerToActivate].Active = true; m_currentActivePlayer = m_activePlayer[playerToActivate]; } else { m_activePlayer[firstIP].Active = true; m_currentActivePlayer = m_activePlayer[firstIP]; } if (m_currentActivePlayer != null) { SendActivePlayer(); } }
void LocalNetwork_OnSetActivePlayerReceived(PlayerDetails activePlayer) { SetActivePlayer(activePlayer); }
void NetworkCommunications_OnGameJoinedReceived(string playersIpAddress, PlayerDetails playersDetails) { GameSettings.Settings.PlayersJoined.Add(playersIpAddress, playersDetails); GameSettings.SaveSettings(); AvailableGamesListView.Items.Add(playersDetails.Name + " on " + playersDetails.Machine); StartGameButton.IsEnabled = true; }