Пример #1
0
        private Hero MakeFakeMove(UserChoise userChoise)
        {
            LastPosX = Hero.PositionX;
            LastPosY = Hero.PositionY;
            var hero = new Hero()
            {
                PositionX = Hero.PositionX, PositionY = Hero.PositionY
            };

            hero.OnMove(this, userChoise);
            return(hero);
        }
Пример #2
0
        public void OnMove(object sender, UserChoise e)
        {
            switch (e)
            {
            case UserChoise.Down:
                PositionY -= 1;
                break;

            case UserChoise.Up:
                PositionY += 1;
                break;

            case UserChoise.Left:
                PositionX -= 1;
                break;

            case UserChoise.Right:
                PositionX += 1;
                break;
            }
            Moved?.Invoke(this, this);
        }
Пример #3
0
        private void OnUserInput(object sender, UserChoise e)
        {
            if (e == UserChoise.Restart)
            {
                _boardHandler.DrawAll();
                IsBombExploided = false;
                return;
            }

            if (IsBombExploided)
            {
                _messenger.ShowError("HIT");
                return;
            }

            if (!_boardHandler.IsValidMove(e))
            {
                return;
            }

            Move?.Invoke(this, e);
            _boardHandler.DrawAll();
        }
Пример #4
0
        public bool IsValidMove(UserChoise userChoise)
        {
            var hero = MakeFakeMove(userChoise);

            if (hero.PositionX == Board.SizeX)
            {
                return(false);
            }
            if (hero.PositionY == Board.SizeY)
            {
                return(false);
            }
            if (hero.PositionX == 0)
            {
                return(false);
            }
            if (hero.PositionY == 0)
            {
                return(false);
            }

            return(true);
        }
Пример #5
0
 public void AddListener(UserChoise listener)
 {
     ChoiseEvent += listener;
 }