Exemple #1
0
        public bool CanMove(int x, int y)
        {
            IPlayer currentPlayer = GetCurrentPlayer();
            Coord   nextStep      = currentPlayer.CalculateNextStep(x, y);
            bool    isInGameField = DrawingEngine.IsInGameField(nextStep);

            if (isInGameField)
            {
                bool isFieldFree = IsFieldFree(nextStep);
                if (isFieldFree)
                {
                    return(true);
                }
                else
                {
                    DrawingEngine.ShowMessage("You can't move there! Try again!");
                }
            }
            else
            {
                DrawingEngine.ShowMessage("You can't move outside the field! Try again!");
            }

            return(false);
        }
Exemple #2
0
        private bool IsFieldFree(Coord nextStep)
        {
            IGameObject gameObject = GetObjectOnNextStep(nextStep);

            if (gameObject != null)
            {
                DrawingEngine.ShowMessage("You have just met an object!");

                if (gameObject is Obstacle)
                {
                    (gameObject as IEnemy).ApplyEffects(GetCurrentPlayer());
                    return(false);
                }
                else if (gameObject is IEnemy)
                {
                    (gameObject as IEnemy).ApplyEffects(GetCurrentPlayer());
                    return(true);
                }
                else if (gameObject is IFriend)
                {
                    (gameObject as IFriend).ApplyEffects(GetCurrentPlayer());
                    return(true);
                }
                else if (gameObject is ITarget)
                {
                    DrawingEngine.ShowMessage(GetCurrentPlayer().Name + " wins the game! Start a new game!");
                }

                return(false);
            }

            foreach (IPlayer obj in players)
            {
                if (obj.IsVisible && obj.Location.X == nextStep.X && obj.Location.Y == nextStep.Y)
                {
                    return(false);
                }
            }

            return(true);
        }