Beispiel #1
0
 public Position GetBehind(Position position)
 {
     if (position.Orientation == Orientation.North) return GetSouthPosition(Position);
     else if (position.Orientation == Orientation.South) return GetNorthPosition(Position);
     else if (position.Orientation == Orientation.East) return GetWestPosition(Position);
     else if (position.Orientation == Orientation.West) return GetEastPosition(Position);
     else throw new Exception("Invalid orientation");
 }
Beispiel #2
0
        public Grid(Grid copy)
        {
            this.Position = copy.Position;
            this.Health = copy.Health - 1;
            this.Energy = copy.Energy;
            this.EnemyHit = copy.EnemyHit;
            this.BatteryFound = copy.BatteryFound;

            Array.Copy(copy.Cells, 0, Cells, 0, Cells.Length);
        }
Beispiel #3
0
 public char GetItem(Position position)
 {
     return Cells[position.X, position.Y];
 }
Beispiel #4
0
        private static Position GetSouthPosition(Position position)
        {
            int x, y;
            x = position.X;
            if (position.Y == (Height - 1))
            {
                y = 0;
            }
            else
            {
                y = position.Y + 1;
            }

            return new Position(x, y, Orientation.South);
        }
Beispiel #5
0
        private static Position GetWestPosition(Position position)
        {
            int x, y;
            y = position.Y;
            if (position.X == 0)
            {
                x = Width - 1;
            }
            else
            {
                x = position.X - 1;
            }

            return new Position(x, y, Orientation.West);
        }
Beispiel #6
0
        private static Position GetNorthPosition(Position position)
        {
            int x, y;
            x = position.X;
            if (position.Y == 0)
            {
                y = Height - 1;
            }
            else
            {
                y = position.Y - 1;
            }

            return new Position(x, y, Orientation.North);
        }
Beispiel #7
0
        private static Position GetEastPosition(Position position)
        {
            int x, y;
            y = position.Y;
            if (position.X == (Width - 1))
            {
                x = 0;
            }
            else
            {
                x = position.X + 1;
            }

            return new Position(x, y, Orientation.East);
        }
Beispiel #8
0
        public void Update(dynamic serialization)
        {
            EnemyHit = false;
            BatteryFound = false;

            Orientation orientation;
            Enum.TryParse(serialization.orientation, true, out orientation);

            Health = serialization.health;
            Energy = serialization.energy;

            string gridSerialization = serialization.grid;

            // Infer the health, battery and laser energy of our opponent based on how the board changes.
            int gridY = 0;
            foreach (string gridLine in gridSerialization.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                int gridX = 0;
                foreach (char gridChar in gridLine)
                {
                    Cells[gridX, gridY] = gridChar;

                    if (gridChar == 'X')
                    {
                        Position = new Position(gridX, gridY, orientation);
                    }

                    gridX++;
                }
                gridY++;
            }
        }
Beispiel #9
0
 public void SetItem(Position position, char item)
 {
     Cells[position.X, position.Y] = item;
 }
Beispiel #10
0
        public void MovePosition(Position newPosition)
        {
            Cells[Position.X, Position.Y] = '_';
            Cells[newPosition.X, newPosition.Y] = 'X';

            Position = newPosition;
        }