Beispiel #1
0
        public void Handle(CatanClient catanClient, CatanClientStateChangeMessage catanClientStateChangeMessage)
        {
            this.catanClient = catanClient;
            if (catanClientStateChangeMessage.NewSpielFiguren != null)
            {
                foreach (var newSpielFiguren in catanClientStateChangeMessage.NewSpielFiguren.Where(spielFigur => spielFigur is Siedlung).ToList())
                {
                    addNewSiedlung(newSpielFiguren as Siedlung);
                }

                foreach (var newSpielFiguren in catanClientStateChangeMessage.NewSpielFiguren.Where(spielFigur => spielFigur is Strasse).ToList())
                {
                    addNewStrasse(newSpielFiguren as Strasse);
                }

                foreach (var newSpielFiguren in catanClientStateChangeMessage.NewSpielFiguren.Where(spielFigur => spielFigur is Stadt).ToList())
                {
                    addNewStadt(newSpielFiguren as Stadt);
                }
            }

            if (catanClientStateChangeMessage.NewEntwicklungskarten != null)
            {
                foreach (var newEntwicklungskarte in catanClientStateChangeMessage.NewEntwicklungskarten)
                {
                    addNewEntwicklungskarte(newEntwicklungskarte);
                }
            }
        }
Beispiel #2
0
 private void modifyCatanClientStateMessageIfNecessary(CatanClientStateChangeMessage catanClientStateChangeMessage)
 {
     if (catanClientStateChangeMessage.NewSpielFiguren?.Count > 0)
     {
         foreach (var strasse in (catanClientStateChangeMessage.NewSpielFiguren.Where(spielFigur => spielFigur is Strasse).ToList()))
         {
             Strasse foundStrasse = strasse as Strasse;
             foundStrasse.HexagonEdge = HexagonGrid.Instance.Hexagones[strasse.HexagonPosition.RowIndex][strasse.HexagonPosition.ColumnIndex].Edges[foundStrasse.HexagonEdge.Index];
         }
     }
 }
Beispiel #3
0
        /*
         * public void ClientGameStateChangeMessageReceived(CatanClientStateChangeMessage catanClientStateChangeMessage)
         * {
         *  CatanClient receivedMessageCatanClient = catanClients.Find(client => client.ID == catanClientStateChangeMessage.ClientID);
         *  if (receivedMessageCatanClient == null)
         *      new NullReferenceException("ClientGameStateChangeMessageReceived");
         *
         *  if (this.currentClient == receivedMessageCatanClient)
         *  {
         *      //modifyCatanClientStateMessageIfNecessary(catanClientStateChangeMessage);
         *      this.messageHandler.Handle(receivedMessageCatanClient, catanClientStateChangeMessage);
         *
         #region Gewinner gefunden?
         *
         *      CatanClient winner = null;
         *      if (receivedMessageCatanClient.Siegpunkte >= MAX_SIEGPUNKTE_WINN)
         *      {
         *          winner = receivedMessageCatanClient;
         *      }
         *      else
         *      {
         *          currentClient = getNextClient();
         *          clearAllowedSpielFigurenByClients();
         *          setAllowedSpielFigurenByClient(currentClient);
         *      }
         *
         #endregion
         *
         *      iNetworkLayer.SendBroadcastMessage(new GameStateMessage(this.catanClients, currentClient, winner, null));
         *  }
         * }*/

        public void ClientGameStateChangeMessageReceived(CatanClientStateChangeMessage catanClientStateChangeMessage)
        {
            CatanClient receivedMessageCatanClient = catanClients.Find(client => client.ID == catanClientStateChangeMessage.ClientID);

            if (receivedMessageCatanClient == null)
            {
                new NullReferenceException("ClientGameStateChangeMessageReceived");
            }

            if (this.currentClient == receivedMessageCatanClient)
            {
                modifyCatanClientStateMessageIfNecessary(catanClientStateChangeMessage);
                this.messageHandler.Handle(receivedMessageCatanClient, catanClientStateChangeMessage);
                CatanClient winner = null;


                // Neue Karten verdient?
                int newStrassen = catanClientStateChangeMessage.NewSpielFiguren != null?catanClientStateChangeMessage.NewSpielFiguren.Where(sf => sf is Strasse).ToList().Count : 0;

                int newSiedlung = catanClientStateChangeMessage.NewSpielFiguren != null?catanClientStateChangeMessage.NewSpielFiguren.Where(sf => sf is Siedlung).ToList().Count : 0;


                if (catanClientStateChangeMessage.IsTurnDone)
                {
                    #region Gewinner gefunden?

                    if (receivedMessageCatanClient.Siegpunkte >= MAX_SIEGPUNKTE_WINN)
                    {
                        winner = receivedMessageCatanClient;
                    }

                    #endregion

                    currentClient    = getNextClient();
                    previousTurnDone = true;
                }

                clearAllowedSpielFigurenByClients();
                setAllowedSpielFigurenByClient(currentClient);

                iNetworkLayer.SendBroadcastMessage(new GameStateMessage(this.catanClients, currentClient, winner, null));

                //catanClients.ForEach(cclient => addNewKartenByNewStrassenNewSiedlungen(cclient,0, newSiedlung));

                if (catanClientStateChangeMessage.IsTurnDone && previousTurnDone)
                {
                    // Neue Karten verdient?
                    catanClients.ForEach(cclient => addNewKartenByClient(cclient));
                    previousTurnDone = false;
                }
            }
        }