Exemple #1
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            IPlayer player = connection.GameState.BluePlayers.FirstOrDefault(p => p.Guid.ToString() == this.playerGuid);

            if (player == null)
            {
                player = connection.GameState.RedPlayers.FirstOrDefault(p => p.Guid.ToString() == this.playerGuid);
            }
            //TO DO:location of piece carried by player should also change
            var location = Validate(connection, player);
            var piece    = connection.GameState.Pieces.FirstOrDefault(p => p.Piece.playerId == player.Id && p.Piece.playerIdSpecified == true);

            if (piece != null)
            {
                piece.Location = location;
            }
            var msg = new Data();

            msg.PlayerLocation = player.Location = location;
            msg.playerId       = player.Id;
            msg.gameFinished   = connection.GameState.GameFinished;
            var  serializer = new Messages.XmlHandling.Serializer(msg);
            Task delay      = new Task(() => {
                System.Threading.Thread.Sleep((int)connection.GameState.ActionCosts.MoveDelay);
                connection.SendMessage(serializer.Serialize());
                Console.WriteLine("I have waited for: " + (int)connection.GameState.ActionCosts.MoveDelay);
            });

            delay.Start();
        }
        public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver)
        {
            IReceiver rec        = server.Receivers.Find(p => p.Id == this.playerId);
            var       serializer = new Messages.XmlHandling.Serializer(this);

            rec.SendMessage(serializer.Serialize());
        }
Exemple #3
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            var sender = connection.GameState.GetPlayerByGuid(this.playerGuid);

            if (connection.GameState.GetPlayerById(this.withPlayerId) == null)
            {
                RejectKnowledgeExchange msg = new RejectKnowledgeExchange(this.withPlayerId, sender.Id, true);
                var serializer = new Messages.XmlHandling.Serializer(msg);
                connection.SendMessage(serializer.Serialize());
            }
            else
            {
                Tuple <ulong, ulong> pair = new Tuple <ulong, ulong>(sender.Id, this.withPlayerIdField);

                if (connection.GameState.PlayerPairs.FirstOrDefault(x => x.Item1 == sender.Id && x.Item2 == this.withPlayerId) == null)
                {
                    //no pair yet
                    KnowledgeExchangeRequest msg = new KnowledgeExchangeRequest(this.withPlayerId, sender.Id);
                    var serializer = new Messages.XmlHandling.Serializer(msg);
                    connection.GameState.PlayerPairs.Add(pair);
                    connection.DelayMessage(serializer, connection.GameState.ActionCosts.KnowledgeExchangeDelay);
                }
                else
                {
                    // pair exists
                    connection.GameState.PlayerPairs.RemoveAll(x => x.Item1 == sender.Id && x.Item2 == this.withPlayerId);
                    AcceptExchangeRequest msg = new AcceptExchangeRequest(this.withPlayerId, sender.Id);
                    var serializer            = new Messages.XmlHandling.Serializer(msg);
                    connection.SendMessage(serializer.Serialize());
                }
            }
        }
        public void HandleOnCommunicationServer(Messages.CommunicationServer.IConnection server, IReceiver receiver)
        {
            var serializer = new Messages.XmlHandling.Serializer(this);
            var gameId     = receiver.GameId;
            var game       = server.Games[gameId];

            game.GameMaster.SendMessage(serializer.Serialize());
        }
Exemple #5
0
        public void DelayMessage(Connection connection, Messages.XmlHandling.Serializer serializer, uint timeToWait)
        {
            Task delay = new Task(() => {
                System.Threading.Thread.Sleep((int)timeToWait);
                connection.SendMessage(serializer.Serialize());
                // TO BE DELETED
                Console.WriteLine("I have waited for: " + (int)connection.GameState.ActionCosts.MoveDelay);
            });

            delay.Start();
        }
        public void HandleOnPlayer(Messages.PlayerInterfaces.IConnection connection)
        {
            Data msg = new Data();

            msg.gameFinished = connection.GameFinished;
            msg.GoalFields   = connection.Logic.GetGoalFields.ToArray();
            msg.TaskFields   = connection.Logic.GetTaskFields.ToArray();
            msg.Pieces       = new Piece[1] {
                connection.Logic.GetPiece
            };
            var serializer = new Messages.XmlHandling.Serializer(msg);

            connection.SendMessage(serializer.Serialize());
        }
 public void HandleOnPlayer(Messages.PlayerInterfaces.IConnection connection)
 {
     if (connection.Logic.TeamMembers.FirstOrDefault(x => x.id == this.senderPlayerId) != null)
     {
         Data msg = new Data();
         msg.gameFinished = connection.GameFinished;
         msg.GoalFields   = connection.Logic.GetGoalFields.ToArray();
         msg.TaskFields   = connection.Logic.GetTaskFields.ToArray();
         msg.Pieces       = new Piece[1] {
             connection.Logic.GetPiece
         };
         var serializer = new Messages.XmlHandling.Serializer(msg);
         connection.SendMessage(serializer.Serialize());
         AuthorizeKnowledgeExchange message = new AuthorizeKnowledgeExchange(connection.Guid.ToString(), connection.GameId, this.senderPlayerId);
         var serializer2 = new Messages.XmlHandling.Serializer(message);
         connection.SendMessage(serializer2.Serialize());
     }
 }