Exemplo n.º 1
0
 public void AddPlayers(GameObject obj)
 {
     if (obj is PlayerOne)
     {
         this.playerOne = obj as PlayerOne;
     }
     if (obj is PlayerTwo)
     {
         this.playerTwo = obj as PlayerTwo;
     }
     this.allObjects.Add(obj);
 }
Exemplo n.º 2
0
        public static void CollisionCheck(List<GameObject> staticObjects, PlayerOne playerOne, PlayerTwo playerTwo)
        {
            foreach (var obj in staticObjects)
            {
                if (obj is Apple)
                {
                    if ((obj.Position.Row >= playerOne.Position.Row && obj.Position.Row <= playerOne.Position.Row) && (obj.Position.Col >= playerOne.Position.Col &&
                                        obj.Position.Col <= playerOne.Position.Col))
                    {
                        obj.Collide(playerOne);
                        playerOne.Collide(obj);
                        Engine.powerPlayerOne++;
                        totalPowerPlayerOne++;
                    }
                    if ((obj.Position.Row >= playerTwo.Position.Row && obj.Position.Row <= playerTwo.Position.Row) && (obj.Position.Col >= playerTwo.Position.Col &&
                                        obj.Position.Col <= playerTwo.Position.Col))
                    {
                        obj.Collide(playerTwo);
                        playerTwo.Collide(obj);
                        Engine.powerPlayerTwo++;
                        totalPowerPlayerTwo++;
                    }
                }
                else if (obj is Pear)
                {
                    if ((obj.Position.Row >= playerOne.Position.Row && obj.Position.Row <= playerOne.Position.Row) && (obj.Position.Col >= playerOne.Position.Col &&
                                        obj.Position.Col <= playerOne.Position.Col))
                    {
                        obj.Collide(playerOne);
                        playerOne.Collide(obj);
                        curentMovePlayerOne++;               
                    }
                    if ((obj.Position.Row >= playerTwo.Position.Row && obj.Position.Row <= playerTwo.Position.Row) && (obj.Position.Col >= playerTwo.Position.Col &&
                                        obj.Position.Col <= playerTwo.Position.Col))
                    {
                        obj.Collide(playerTwo);
                        playerTwo.Collide(obj);
                        curentMovePlayerTwo++;                     
                    }
                }
                totalMovePlayerOne = curentMovePlayerOne + Engine.movePlayerOne;
                totalMovePlayerTwo = curentMovePlayerTwo + Engine.movePlayerTwo;
            }

            if (playerOne is PlayerOne)
            {
                if ((playerTwo.Position.Row >= playerOne.Position.Row && playerTwo.Position.Row <= playerOne.Position.Row) && (playerTwo.Position.Col >= playerOne.Position.Col &&
                                    playerTwo.Position.Col <= playerOne.Position.Col))
                {
                    playerTwo.Collide(playerOne);
                    playerOne.Collide(playerTwo);
                }
            }
            if (playerTwo is PlayerTwo)
            {
                if ((playerOne.Position.Row >= playerTwo.Position.Row && playerOne.Position.Row <= playerTwo.Position.Row) && (playerOne.Position.Col >= playerTwo.Position.Col &&
                                    playerOne.Position.Col <= playerTwo.Position.Col))
                {
                    playerOne.Collide(playerTwo);
                    playerTwo.Collide(playerOne);
                }
            }
        }
Exemplo n.º 3
0
        public void GeneratePlayersOnField()
        {
            Random randomGen = new Random();
            var map = new bool[,] 
                {
                    {true, true, true, true, true, true, true, true},
                    {true, true, true, true, true, true, true, true},
                    {true, true, true, true, true, true, true, true},
                    {true, true, true, true, true, true, true, true},
                    {true, true, true, true, true, true, true, true},
                    {true, true, true, true, true, true, true, true},
                    {true, true, true, true, true, true, true, true},
                    {true, true, true, true, true, true, true, true}
                };

            Warrior playerOne = new PlayerOne(new Position(
                randomGen.Next(startRow, endRow),
                randomGen.Next(startCol, endCol)));

            this.AddPlayers(playerOne);
            map[playerOne.Position.Col - 3, playerOne.Position.Row - 3] = false;

            var position = new Position(
                                    randomGen.Next(0, 8),
                                    randomGen.Next(0, 8));

            while (!IsPositionAvailable(position, map, 3))
            {
                position = new Position(
                                        randomGen.Next(0, 8),
                                        randomGen.Next(0, 8));

            }

            Warrior playerTwo = new PlayerTwo(new Position(
                    position.Row + 3,
                    position.Col + 3));

            this.AddPlayers(playerTwo);
        }