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"); }
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); }
public char GetItem(Position position) { return Cells[position.X, position.Y]; }
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); }
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); }
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); }
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); }
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++; } }
public void SetItem(Position position, char item) { Cells[position.X, position.Y] = item; }
public void MovePosition(Position newPosition) { Cells[Position.X, Position.Y] = '_'; Cells[newPosition.X, newPosition.Y] = 'X'; Position = newPosition; }