public void Act(GameBoard.GameBoard gameBoard) { foreach (var unit in _units) { unit.Act(gameBoard); } }
public override void Initialize() { base.Initialize(); // Setup the game board _playerBoard = new GameBoard.GameBoard(); _playerBoard.Position = new Vector2(15, 120); _playerBoard.Size = new Vector2(380, 380); _playerBoard.Ships = this.PlayerShips; _playerBoard.MouseHoverEnabled = false; _playerBoard.Initialize(); _opponentBoard = new GameBoard.GameBoard(); _opponentBoard.Position = new Vector2(30 + 380, 120); _opponentBoard.Size = new Vector2(380, 380); _opponentBoard.Initialize(); _opponentBoard.MouseHoverEnabled = false; ConnectionTimer = new FixedTimer(1000); if (BattleshipsGame.PlayerNumber == 1) { _myTurn = true; } }
public void Act(GameBoard.GameBoard gameBoard, IAction action) { if (!IsAlive) { return; } action.Act(this, gameBoard); }
public void ActWithout(GameBoard.GameBoard gameBoard, Unit unit) { foreach (var u in _units) { if (u == unit) { continue; } u.Act(gameBoard); } }
public void Act(GameBoard.GameBoard gameBoard) { if (!IsAlive) { return; } IAction action = new Attack(); if (!action.Act(this, gameBoard)) { ChangeDirection(); action = new Move(Direction); action.Act(this, gameBoard); } }
private void Start() { if (Level == Level.UNKHOWN || Player == UnitType.UNKNOWN) { return; } Game = new Game.Game(Level, Player); Game.Start(); GameBoard = Game.GameBoard; IsStarted = true; _timer = new DispatcherTimer(); _timer.Tick += new EventHandler(GameStep); _timer.Interval = new TimeSpan(0, 0, 1); _timer.Start(); }
public void PickUp(Unit unit, IItem temp, GameBoard.GameBoard gameBoard) { if (temp is Box) { unit.Weapons += 1; temp = new Ground { X = temp.X, Y = temp.Y }; gameBoard.GameBoardItems[temp.Y][temp.X] = temp; } if (temp is Life) { unit.Health += 10; temp = new Ground { X = temp.X, Y = temp.Y }; gameBoard.GameBoardItems[temp.Y][temp.X] = temp; } }
public void GameStep(object sender, EventArgs e) { GameBoard = null; GameBoard = Game.GameBoard; Weapons = Game.Weapons; X = Game.X; Y = Game.Y; Health = Game.Health; if (Health <= 0) { _timer.Stop(); _viewLauncher.ShowWinner(false); } if (Game.IsFinished) { _timer.Stop(); _viewLauncher.ShowWinner(Game.Winner.GetType() == typeof(RedArmy)); } }
public bool Act(Unit unit, GameBoard.GameBoard gameBoard) { var x = unit.X; var y = unit.Y; IItem temp; switch (_direction) { case Direction.LEFT: if (x - 1 < 0 || gameBoard.GameBoardItems[y][x - 1] is Wall || gameBoard.GameBoardItems[y][x - 1] is Unit) { break; } temp = gameBoard.GameBoardItems[y][x - 1]; PickUp(unit, temp, gameBoard); if (!(temp is Unit)) { temp = new Ground() { X = temp.X, Y = temp.Y } } ; gameBoard.GameBoardItems[y][x - 1] = unit; gameBoard.GameBoardItems[y][x] = temp; unit.X -= 1; temp.X += 1; break; case Direction.UP: if (y - 1 < 0 || gameBoard.GameBoardItems[y - 1][x] is Wall || gameBoard.GameBoardItems[y - 1][x] is Unit) { break; } temp = gameBoard.GameBoardItems[y - 1][x]; PickUp(unit, temp, gameBoard); if (!(temp is Unit)) { temp = new Ground() { X = temp.X, Y = temp.Y } } ; gameBoard.GameBoardItems[y - 1][x] = unit; gameBoard.GameBoardItems[y][x] = temp; unit.Y -= 1; temp.Y += 1; break; case Direction.RIGHT: if (x + 1 >= gameBoard.Width || gameBoard.GameBoardItems[y][x + 1] is Wall || gameBoard.GameBoardItems[y][x + 1] is Unit) { break; } temp = gameBoard.GameBoardItems[y][x + 1]; PickUp(unit, temp, gameBoard); if (!(temp is Unit)) { temp = new Ground() { X = temp.X, Y = temp.Y } } ; gameBoard.GameBoardItems[y][x + 1] = unit; gameBoard.GameBoardItems[y][x] = temp; unit.X += 1; temp.X -= 1; break; case Direction.DOWN: if (y + 1 >= gameBoard.Height || gameBoard.GameBoardItems[y + 1][x] is Wall || gameBoard.GameBoardItems[y + 1][x] is Unit) { break; } temp = gameBoard.GameBoardItems[y + 1][x]; PickUp(unit, temp, gameBoard); if (!(temp is Unit)) { temp = new Ground() { X = temp.X, Y = temp.Y } } ; gameBoard.GameBoardItems[y + 1][x] = unit; gameBoard.GameBoardItems[y][x] = temp; unit.Y += 1; temp.Y -= 1; break; default: throw new ArgumentOutOfRangeException(); } return(true); }
public bool Act(Unit unit, GameBoard.GameBoard gameBoard) { if (unit.Weapons == 0) { return(false); } var x = unit.X; var y = unit.Y; var res = false; if (x - 1 >= 0 && gameBoard.GameBoardItems[y][x - 1] is Unit && ((Unit)gameBoard.GameBoardItems[y][x - 1]).Army != unit.Army) { ((Unit)gameBoard.GameBoardItems[y][x - 1]).Health -= unit.Hit; if (((Unit)gameBoard.GameBoardItems[y][x - 1]).Health <= 0) { gameBoard.GameBoardItems[y][x - 1] = new Ground { X = x - 1, Y = y }; } unit.Weapons -= 1; res = true; } if (y - 1 >= 0 && gameBoard.GameBoardItems[y - 1][x] is Unit && ((Unit)gameBoard.GameBoardItems[y - 1][x]).Army != unit.Army) { ((Unit)gameBoard.GameBoardItems[y - 1][x]).Health -= unit.Hit; if (((Unit)gameBoard.GameBoardItems[y - 1][x]).Health <= 0) { gameBoard.GameBoardItems[y - 1][x] = new Ground { X = x, Y = y - 1 }; } unit.Weapons -= 1; res = true; } if (x + 1 < gameBoard.Width && gameBoard.GameBoardItems[y][x + 1] is Unit && ((Unit)gameBoard.GameBoardItems[y][x + 1]).Army != unit.Army) { ((Unit)gameBoard.GameBoardItems[y][x + 1]).Health -= unit.Hit; if (((Unit)gameBoard.GameBoardItems[y][x + 1]).Health <= 0) { gameBoard.GameBoardItems[y][x + 1] = new Ground { X = x + 1, Y = y }; } unit.Weapons -= 1; res = true; } if (y + 1 < gameBoard.Height && gameBoard.GameBoardItems[y + 1][x] is Unit && ((Unit)gameBoard.GameBoardItems[y + 1][x]).Army != unit.Army) { ((Unit)gameBoard.GameBoardItems[y + 1][x]).Health -= unit.Hit; if (((Unit)gameBoard.GameBoardItems[y + 1][x]).Health <= 0) { gameBoard.GameBoardItems[y + 1][x] = new Ground { X = x, Y = y + 1 }; } unit.Weapons -= 1; res = true; } return(res); }