Beispiel #1
0
        /// <summary>
        /// Determinate changes on playground base on player's movements
        /// </summary>
        /// <param name="movement">Array of moves by players</param>
        /// <param name="connection">Connection coresponding to player who want to make a move</param>
        internal static void Process(Movement movement, Connection connection)
        {
            Playground playground = Program.playground;

            if (playground.board[connection.position.X][connection.position.Y] == Square.Fire)
            {
                return;
            }
            switch (movement)
            {
            case Movement.Up:
                if ((playground.board[connection.position.X - 1][connection.position.Y] == Square.Empty) ||
                    (playground.board[connection.position.X - 1][connection.position.Y] == Square.Fire))
                {
                    Move(new Point(connection.position.X, connection.position.Y), new Point(connection.position.X - 1, connection.position.Y));
                    connection.position = new Point(connection.position.X - 1, connection.position.Y);
                }
                return;

            case Movement.Left:
                if ((playground.board[connection.position.X][connection.position.Y - 1] == Square.Empty) ||
                    (playground.board[connection.position.X][connection.position.Y - 1] == Square.Fire))
                {
                    Move(new Point(connection.position.X, connection.position.Y), new Point(connection.position.X, connection.position.Y - 1));
                    connection.position = new Point(connection.position.X, connection.position.Y - 1);
                }
                return;

            case Movement.Down:
                if ((playground.board[connection.position.X + 1][connection.position.Y] == Square.Empty) ||
                    (playground.board[connection.position.X + 1][connection.position.Y] == Square.Fire))
                {
                    Move(new Point(connection.position.X, connection.position.Y), new Point(connection.position.X + 1, connection.position.Y));
                    connection.position = new Point(connection.position.X + 1, connection.position.Y);
                }
                return;

            case Movement.Right:
                if ((playground.board[connection.position.X][connection.position.Y + 1] == Square.Empty) ||
                    (playground.board[connection.position.X][connection.position.Y + 1] == Square.Fire))
                {
                    Move(new Point(connection.position.X, connection.position.Y), new Point(connection.position.X, connection.position.Y + 1));
                    connection.position = new Point(connection.position.X, connection.position.Y + 1);
                }
                return;

            case Movement.Plant_bomb:
                playground.AddBomb(new Point(connection.position.X, connection.position.Y));
                return;

            default:
                return;
            }
        }
Beispiel #2
0
        private static void Move(Point oldLocation, Point newLocation)
        {
            Playground playground = Program.playground;
            Square     oldSquare  = playground.board[oldLocation.X][oldLocation.Y];

            if ((oldSquare >= Square.Bomb_1_1 && oldSquare <= Square.Bomb_1_4) ||
                (oldSquare >= Square.Bomb_2_1 && oldSquare <= Square.Bomb_2_4) ||
                (oldSquare >= Square.Bomb_3_1 && oldSquare <= Square.Bomb_3_4))
            {
                playground.board[newLocation.X][newLocation.Y] = GetPlayerSquare(oldSquare);
                changes.Add(new Change(new Point(newLocation.X, newLocation.Y), playground.board[newLocation.X][newLocation.Y]));
                playground.board[oldLocation.X][oldLocation.Y] = GetBombSquare(playground.board[oldLocation.X][oldLocation.Y]);
                changes.Add(new Change(new Point(oldLocation.X, oldLocation.Y), playground.board[oldLocation.X][oldLocation.Y]));
            }
            else
            {
                playground.board[newLocation.X][newLocation.Y] = playground.board[oldLocation.X][oldLocation.Y];
                changes.Add(new Change(new Point(newLocation.X, newLocation.Y), playground.board[newLocation.X][newLocation.Y]));
                playground.board[oldLocation.X][oldLocation.Y] = Square.Empty;
                changes.Add(new Change(new Point(oldLocation.X, oldLocation.Y), Square.Empty));
            }
        }