void initAddPlayerWindow(PlayerCollection playerList) { this.Players = playerList; Players.Clear(); Player one = new Player("Frank", "Furters", "Necrons",false,0); Players.Add(one); Player two = new Player("Joe (AI:4)", "Shmoes", "Orks",true,4); Players.Add(two); InitializeComponent(); initIconSets(); lbxPlayerList.ItemsSource = Players; lbxPlayerList.UpdateLayout(); }
public PlayerCollection PlayersWithLowestGoodsCount( PlayerCollection PlayersToCheck ) { PlayerCollection toReturn = new PlayerCollection(); toReturn.Add( PlayersToCheck[0] ); for( int i = 1; /* skipping the first player in the list */ i < PlayersToCheck.Count; i++ ) { if( PlayersToCheck[i].GoodsCount < toReturn[0].GoodsCount ) { toReturn.Clear(); toReturn.Add( PlayersToCheck[i] ); } else if( PlayersToCheck[i].GoodsCount == toReturn[0].GoodsCount ) { toReturn.Add( PlayersToCheck[i] ); } else // do nothing { } } return toReturn; }
public PlayerCollection PlayersWithHighestStrength( PlayerCollection PlayersToCheck ) { PlayerCollection toReturn = new PlayerCollection(); toReturn.Add( PlayersToCheck[0] ); for( int i = 1; i < PlayersToCheck.Count; i++ ) { if( PlayersToCheck[i].TotalStrength > toReturn[0].TotalStrength ) { toReturn.Clear(); toReturn.Add( PlayersToCheck[i] ); } else if( PlayersToCheck[i].NumBuildings == toReturn[0].NumBuildings ) { toReturn.Add( PlayersToCheck[i] ); } else { } // do nothing } return toReturn; }
public PlayerCollection PlayersWithLowestBuildingCount( PlayerCollection PlayersToCheck ) { PlayerCollection toReturn = new PlayerCollection(); toReturn.Add( PlayersToCheck[0] ); for( int i = 1; /* skipping the first player in the list */ i < PlayersToCheck.Count; i++ ) { if( PlayersToCheck[i].NumBuildings < toReturn[0].NumBuildings ) { toReturn.Clear(); toReturn.Add( PlayersToCheck[i] ); } else if( PlayersToCheck[i].NumBuildings == toReturn[0].NumBuildings ) { toReturn.Add( PlayersToCheck[i] ); } else { } // do nothing } return toReturn; }
/// <summary> /// Invoked when the network peer has received a message /// </summary> /// <param name="state">The object that invoked this (NetPeer)</param> private void MessageReceived(object state) { // Get the incoming message NetIncomingMessage inMsg = ((NetPeer)state).ReadMessage(); // We don't want the server to crash on one bad packet try { // Determine the message type to correctly handle it switch (inMsg.MessageType) { // Handle when a client's status has changed case NetIncomingMessageType.StatusChanged: // Gets the status and reason NetConnectionStatus status = (NetConnectionStatus)inMsg.ReadByte(); string reason = inMsg.ReadString(); // Depending on the status, we handle players joining or leaving switch (status) { case NetConnectionStatus.Disconnected: // If the reason the is shutdown message, we're good if (reason.Equals(NetSettings.DEFAULT_SERVER_SHUTDOWN_MESSAGE)) { OnDisconnected?.Invoke(this, EventArgs.Empty); } // Otherwise if the reason is that \/ , then we timed out else if (reason.Equals("Failed to establish connection - no response from remote host", StringComparison.InvariantCultureIgnoreCase)) { OnConnectionTimedOut?.Invoke(this, EventArgs.Empty); OnDisconnected?.Invoke(this, EventArgs.Empty); } else if (reason.StartsWith("You have been kicked:")) { OnKicked?.Invoke(this, reason); OnDisconnected?.Invoke(this, EventArgs.Empty); } // Otherwise the connection failed for some other reason else { OnDisconnected?.Invoke(this, EventArgs.Empty); } if (isApproving) { OnConnectionFailed?.Invoke(this, reason); } isApproving = false; // Clear local state and forget connected server tag myLocalState.Clear(); myConnectedServer = null; isReady = false; isHost = false; myKnownPlayers.Clear(); myLocalState.Clear(); myHand.Clear(); break; case NetConnectionStatus.RespondedAwaitingApproval: isApproving = true; break; // We connected case NetConnectionStatus.Connected: isApproving = false; // invoked the onConnected event OnConnected?.Invoke(this, EventArgs.Empty); break; } break; // Handle when the server has received a discovery request case NetIncomingMessageType.DiscoveryResponse: // Read the server tag from the packet ServerTag serverTag = ServerTag.ReadFromPacket(inMsg); // Notify that we discovered a server OnServerDiscovered?.Invoke(this, serverTag); break; // Handles when the server has received data case NetIncomingMessageType.Data: HandleMessage(inMsg); break; } } // An exception has occured parsing the packet catch (Exception e) { //Log the exception Logger.Write(e); } }