Пример #1
0
        /// <summary>
        /// Get the closest item to the specified Player
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public int[] GetClosestItem(PlayerInfoModel player)
        {
            int[] PlayerLocation = GameBoardModel.GetPlayerLocation(player);
            int[] location       = { Int32.MaxValue, Int32.MaxValue };

            // Get closest Character
            int closestDistance = Int32.MaxValue;

            for (int x = 0; x < GameBoardModel.Size; ++x)
            {
                for (int y = 0; y < GameBoardModel.Size; ++y)
                {
                    if (GameBoardModel.ItemLocations[x, y] != null)
                    {
                        int distance = GameBoardHelper.Distance(x, y, PlayerLocation[0], PlayerLocation[1]);
                        if (distance < closestDistance)
                        {
                            location[0] = x;
                            location[1] = y;
                        }
                    }
                }
            }

            return(location);
        }
Пример #2
0
        /// <summary>
        /// Attack as a Turn
        ///
        /// Pick who to go after
        ///
        /// Determine the Attack score
        /// Determine the Defense score
        ///
        /// Do the Attack
        ///
        /// </summary>
        /// <param name="Attacker"></param>
        /// <returns></returns>
        public bool Attack(PlayerInfoModel Attacker)
        {
            // For Attack, Choose Who
            var TargetLocation = AttackChoice(Attacker);

            if (TargetLocation[0] == Int32.MaxValue)
            {
                return(false);
            }

            int[] attackerLocation = GameBoardModel.GetPlayerLocation(Attacker);
            int   Distance         = GameBoardHelper.Distance(attackerLocation[0], attackerLocation[1], TargetLocation[0], TargetLocation[1]);

            int AttackRange = 1;

            if (Attacker.Head != null)
            {
                AttackRange = ItemIndexViewModel.Instance.GetItem(Attacker.Head).Range;
            }

            if (Distance > AttackRange || Attacker.CurrentStamina < 3)
            {
                return(false);
            }

            // Do Attack
            PlayerInfoModel TargetModel = GameBoardModel.GetPlayer(TargetLocation[0], TargetLocation[1]);

            TurnAsAttack(Attacker, TargetModel);

            CurrentAttacker = new PlayerInfoModel(Attacker);
            CurrentDefender = new PlayerInfoModel(TargetModel);

            return(true);
        }
Пример #3
0
        // Attack or Move
        // Roll To Hit
        // Decide Hit or Miss
        // Decide Damage
        // Death
        // Drop Items
        // Turn Over
        #endregion Algrorithm

        /// <summary>
        /// Perform a turn and attack the target
        /// </summary>
        /// <param name="Attacker"></param>
        /// <returns></returns>
        public bool TakeTurn(PlayerInfoModel Attacker)
        {
            // Replenish Stamina
            Attacker.CurrentStamina = Attacker.BaseStamina;

            // Choose Action.  Such as Move, Attack etc.

            // while an action is possible
            // If Nearest enemy in range and have an item, then Attack
            // If in range of an item, then move onto Item

            // if we don't have an item
            if (Attacker.Head == null)
            {
                // move to item
                int[] closestItem = GetClosestItem(Attacker);
                if (closestItem[0] != Int32.MaxValue && closestItem[1] != Int32.MaxValue)
                {
                    // Move towards the Item, conserving 3 stamina for the attack
                    Attacker.CurrentStamina = MoveTowards(Attacker, closestItem, 3, GameBoardModel.GetItem(closestItem[0], closestItem[1]).Name);
                }

                int[] PlayerLocation = GameBoardModel.GetPlayerLocation(Attacker);

                int[] newestClosest = GetClosestItem(Attacker);
                if (newestClosest[0] != Int32.MaxValue && newestClosest[1] != Int32.MaxValue &&
                    GameBoardHelper.Distance(newestClosest[0], newestClosest[1], PlayerLocation[0], PlayerLocation[1]) <= 1)
                {
                    ItemModel temp = GameBoardModel.ItemLocations[newestClosest[0], newestClosest[1]];
                    Attacker.Head = temp.Id;
                    Debug.WriteLine(Attacker.Name + " picked up " + temp.Name);
                    GameBoardModel.ItemLocations[newestClosest[0], newestClosest[1]] = null;
                }
            }

            // then try an attack
            var attacks = Attack(Attacker);

            if (!attacks)
            {
                // move toward enemy
                int[] TargetLocation = AttackChoice(Attacker);

                if (TargetLocation[0] == Int32.MaxValue)
                {
                    return(attacks);
                }
            }

            BattleScore.TurnCount++;

            return(attacks);
        }
Пример #4
0
        /// <summary>
        /// Move towards the specified location as much as possible
        /// </summary>
        /// <param name="player"></param>
        /// <param name="location"></param>
        /// <param name="StaminaToConserve"></param>
        /// <returns></returns>
        public int MoveTowards(PlayerInfoModel player, int[] location, int StaminaToConserve, string label)
        {
            int[] PlayerLocation = GameBoardModel.GetPlayerLocation(player);
            int   Distance       = GameBoardHelper.Distance(location[0], location[1], PlayerLocation[0], PlayerLocation[1]);

            Debug.WriteLine("Distance " + Distance);

            // How far the Player can move when conserving the amount of stamina that they want to
            int CanMove = player.CurrentStamina - StaminaToConserve;

            if (CanMove < Distance)
            {
                Distance = CanMove;
            }

            // Determine how far to move in each direction
            int BlocksToMove = (int)(Math.Floor(Math.Sqrt(Math.Pow(Distance, 2) / 2)));
            int xMovement    = (location[0] - PlayerLocation[0] > 0 ? BlocksToMove : -BlocksToMove);
            int yMovement    = (location[1] - PlayerLocation[1] > 0 ? BlocksToMove : -BlocksToMove);

            // Debug.WriteLine("Move " + (PlayerLocation[0] + xMovement) + ", " + (PlayerLocation[1] + yMovement));

            int newX = PlayerLocation[0] + xMovement;

            if (PlayerLocation[0] + xMovement > 5 || PlayerLocation[0] + xMovement < 0)
            {
                newX = PlayerLocation[0];
            }

            int newY = PlayerLocation[1] + yMovement;

            if (PlayerLocation[1] + yMovement > 5 || PlayerLocation[1] + yMovement < 0)
            {
                newY = PlayerLocation[0];
            }

            // Perform the GameBoard updates
            GameBoardModel.PlayerLocations[PlayerLocation[0], PlayerLocation[1]] = null;
            GameBoardModel.PlayerLocations[newX, newY] = player;

            Debug.WriteLine(player.Name + " moved towards \"" + label + "\" (" + location[0] + ", " + location[1] + ")");

            // Update the Player stamina
            player.CurrentStamina -= BlocksToMove;
            return(player.CurrentStamina);
        }
Пример #5
0
        /// <summary>
        /// Pick the Monster to Attack
        /// </summary>
        /// <returns></returns>
        public int[] SelectMonsterToAttack(PlayerInfoModel currentPlayer)
        {
            int[] characterLocation = GameBoardModel.GetPlayerLocation(currentPlayer);
            int[] closestLocation   = { Int32.MaxValue, Int32.MaxValue };

            if (MonsterList == null)
            {
                return(null);
            }

            if (MonsterList.Count < 1)
            {
                return(null);
            }

            // Get closest Character
            int closestDistance = Int32.MaxValue;

            for (int x = 0; x < GameBoardModel.Size; ++x)
            {
                for (int y = 0; y < GameBoardModel.Size; ++y)
                {
                    if (GameBoardModel.PlayerLocations[x, y] != null &&
                        GameBoardModel.PlayerLocations[x, y].PersonType == PersonTypeEnum.Monster)
                    {
                        int distance = GameBoardHelper.Distance(x, y, characterLocation[0], characterLocation[1]);
                        if (distance < closestDistance)
                        {
                            closestLocation[0] = x;
                            closestLocation[1] = y;
                        }
                    }
                }
            }

            return(closestLocation);
        }