Esempio n. 1
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            var msg = new Data();

            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);
            }
            msg.playerId = player.Id;
            Piece[] pickedUpPiece = new Piece[1];
            foreach (PieceInfo p in connection.GameState.Pieces)
            {
                if (player.Location.x == p.Location.x && player.Location.y == p.Location.y)
                {
                    p.Piece.playerId          = player.Id;
                    p.Piece.playerIdSpecified = true;
                    pickedUpPiece[0]          = new Piece()
                    {
                        type = PieceType.unknown, playerId = player.Id, playerIdSpecified = true, id = p.Piece.id
                    };
                    msg.Pieces = pickedUpPiece;
                    connection.GameState.CalculateManhattanDistance();
                }
            }
            msg.gameFinished = connection.GameState.GameFinished;
            var serializer = new Messages.XmlHandling.Serializer(msg);

            connection.DelayMessage(serializer, connection.GameState.ActionCosts.PickUpDelay);
        }
Esempio n. 2
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());
                }
            }
        }
Esempio n. 3
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            var     msg    = new Data();
            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);
            }
            msg.playerId = player.Id;
            Piece[] checkedPiece = new Piece[1];

            foreach (PieceInfo p in connection.GameState.Pieces)
            {
                if (player.Id == p.Piece.playerId)
                {
                    checkedPiece[0] = new Piece()
                    {
                        type = p.Piece.type, playerId = player.Id, playerIdSpecified = true, id = p.Piece.id
                    };
                    msg.Pieces = checkedPiece;
                }
            }
            msg.gameFinished = connection.GameState.GameFinished;

            var serializer = new Messages.XmlHandling.Serializer(msg);

            connection.DelayMessage(serializer, connection.GameState.ActionCosts.TestDelay);
        }
Esempio n. 4
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            var     msg    = new Data();
            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);
            }
            msg.TaskFields   = GetSurroundingFields(connection, player);
            msg.playerId     = player.Id;
            msg.gameFinished = connection.GameState.GameFinished;
            var serializer = new Messages.XmlHandling.Serializer(msg);

            connection.DelayMessage(serializer, connection.GameState.ActionCosts.DiscoverDelay);
        }
Esempio n. 5
0
        public void HandleOnGameMaster(Messages.GameMaster.IConnection connection)
        {
            var msg = new Data();

            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);
            }
            msg.playerId = player.Id;

            Piece[]     placedPiece = new Piece[1];
            GoalField[] goalFields  = new GoalField[1];
            //we pick piece which shares the location with player.
            PieceInfo myPiece = connection.GameState.Pieces.First(p => p.Location.x == player.Location.x &&
                                                                  p.Location.y == player.Location.y &&
                                                                  p.Piece.playerId == player.Id &&
                                                                  p.Piece.playerIdSpecified == true);

            if (myPiece.Piece.type != PieceType.sham)
            {
                //if piece is on place we are standing,
                foreach (PieceInfo p in connection.GameState.Pieces)
                {
                    if (player.Location.x == p.Location.x && player.Location.y == p.Location.y)
                    {
                        if (player.Id != p.Piece.playerId)
                        {
                            placedPiece[0] = new Piece()
                            {
                                type = myPiece.Piece.type, playerId = player.Id, playerIdSpecified = true, id = myPiece.Piece.id
                            };
                        }
                    }
                }
                // this is overriding the lines before, we need to think through this process.
                placedPiece[0] = new Piece()
                {
                    type = myPiece.Piece.type, id = myPiece.Piece.id
                };

                foreach (List <Xsd2.Field> flist in connection.GameState.BoardList)
                {
                    foreach (var f in flist)
                    {
                        if (f is GoalField)
                        {
                            if (f.x == player.Location.x && f.y == player.Location.y)
                            {
                                goalFields[0] = new GoalField()
                                {
                                    playerId = player.Id, type = ((GoalField)f).type, playerIdSpecified = true, x = f.x, y = f.y
                                };
                                Console.WriteLine(((GoalField)f).type);
                                Console.WriteLine("f.x: " + f.x + ", f.y: " + f.y);
                                Console.WriteLine(" x " + player.Location.x + " y " + player.Location.y);
                                //testing whether piece is not sham.
                                if (((GoalField)f).type == GoalFieldType.goal && myPiece.Piece.type == PieceType.normal)
                                {
                                    if (player.TeamColour == TeamColour.red)
                                    {
                                        connection.GameState.RedGoalsFinished++;
                                    }
                                    else
                                    {
                                        connection.GameState.BlueGoalsFinished++;
                                    }
                                }
                            }
                        }
                    }
                }
                // why do we send here piece?
                msg.Pieces     = placedPiece; // we are still or not holding it.
                msg.GoalFields = goalFields;
                if (connection.GameState.GameFinished != true)
                {
                    connection.GameState.GameFinished = CheckIfEnding(connection);
                }
                //edit
                msg.gameFinished = connection.GameState.GameFinished;
                var serializer = new Messages.XmlHandling.Serializer(msg);
                connection.DelayMessage(serializer, connection.GameState.ActionCosts.PlacingDelay);
            }
            else
            {
                connection.GameState.Pieces.First(p => p.Location.x == player.Location.x &&
                                                  p.Location.y == player.Location.y &&
                                                  p.Piece.playerId == player.Id &&
                                                  p.Piece.playerIdSpecified == true).Piece.playerIdSpecified = false;
                //we are sending the keep alive back
                var serializer = new Messages.XmlHandling.Serializer(char.ToString((char)23));
            }
        }