예제 #1
0
파일: BlueArmy.cs 프로젝트: sunruslan/RPG
 public void Act(GameBoard.GameBoard gameBoard)
 {
     foreach (var unit in _units)
     {
         unit.Act(gameBoard);
     }
 }
예제 #2
0
        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;
            }
        }
예제 #3
0
파일: Unit.cs 프로젝트: sunruslan/RPG
 public void Act(GameBoard.GameBoard gameBoard, IAction action)
 {
     if (!IsAlive)
     {
         return;
     }
     action.Act(this, gameBoard);
 }
예제 #4
0
파일: BlueArmy.cs 프로젝트: sunruslan/RPG
 public void ActWithout(GameBoard.GameBoard gameBoard, Unit unit)
 {
     foreach (var u in _units)
     {
         if (u == unit)
         {
             continue;
         }
         u.Act(gameBoard);
     }
 }
예제 #5
0
파일: Unit.cs 프로젝트: sunruslan/RPG
        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);
            }
        }
예제 #6
0
 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();
 }
예제 #7
0
 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;
     }
 }
예제 #8
0
 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));
     }
 }
예제 #9
0
        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);
        }
예제 #10
0
파일: Attack.cs 프로젝트: sunruslan/RPG
        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);
        }