Пример #1
0
        // ends the current turn
        private void EndTurn(TurnEndReason reason)
        {
            ConsoleManager.Instance.WriteLine($"Turn {TurnNumber} has ended, reason {reason}", MsgType.ServerInfo);

            controllers.ProcessTurn();
            TurnNumber++;
            TurnTimer.Restart();

            ConsoleManager.Instance.WriteLine($"Turn {TurnNumber} has begun", MsgType.ServerInfo);
            foreach (Player player in controllers.Player.GetAllPlayers())
            {
                Packet p = new Packet((int)PacketHeader.TurnData,
                                      TurnNumber,
                                      TurnTimeLimit,
                                      reason,
                                      player,
                                      controllers.City.GetAllCities(),
                                      controllers.Unit.GetAllUnits()
                                      );

                server.SendData(p, player.Connection);
            }

            //// TODO this is where we check for game over
            //Tuple<bool, Player, VictoryType> res = IsGameOver();
            //if (res.Item1)
            //    SendGameOver(res.Item2, res.Item3);
        }
Пример #2
0
        // parses a packet with the header TurnData
        private void ParseTurnData(Packet p)
        {
            int i = 0;

            TurnNumber    = (int)p.Items[i++];
            TurnTimeLimit = (int)p.Items[i++];
            TurnEndReason reason = (TurnEndReason)p.Items[i++];

            Player   = (Player)p.Items[i++];
            Cities   = (List <City>)p.Items[i++];
            AllUnits = (List <UnitInstance>)p.Items[i++];
            UpdateCache();
            ConsoleManager.Instance.WriteLine($"Recieved data for turn {TurnNumber}");
            TurnState = TurnState.Begin;
            TurnTimer.Restart();
        }
Пример #3
0
 // loop thread: runs processes that can't be event driven
 private void UpdateLoop()
 {
     TurnTimer.Start();
     while (Running)
     {
         if (TurnTimer.ElapsedMilliseconds > TurnTimeLimit)
         {
             foreach (Player player in controllers.Player.GetAllPlayers())
             {
                 player.EndedTurn = true;
             }
             EndTurn(TurnEndReason.TimeOut);
             TurnTimer.Restart();
         }
     }
 }