Example #1
0
        private Creature GetClosestEnemy(CreatureLocInfo info)
        {
            Creature foundEnemy = null;
            //enemy away distance is defined as: how many column away + how many row away

            int distance = 0, minDist = 50;

            // List<CreatureLocInfo> distance = new List<CreatureLocInfo>();
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (GameBoard[i, j] != null && ((GameBoard[i, j].Type) == (1 - info.type)))//Checks the creature distance and provides if the other creature can attack or not
                    {
                        distance = (Math.Abs(info.row - i) + (Math.Abs(info.col - j)));
                        if (minDist >= distance)
                        {
                            minDist    = distance;
                            foundEnemy = GameBoard[i, j];
                        }
                    }
                }
            }

            return(foundEnemy);
        }
        private Creature GetClosestEnemy(CreatureLocInfo info)
        {
            Creature foundEnemy = null;
            //enemy away distance is defined as: how many column away + how many row away       ***maybe use distance formula?***

            int distance = 0, minDist = 50;

            // List<CreatureLocInfo> distance = new List<CreatureLocInfo>();
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (GameBoard[i, j] != null && ((GameBoard[i, j].Type) == (1 - info.type)))
                    {
                        distance = (Math.Abs(info.row - i) + (Math.Abs(info.col - j)));
                        if (minDist >= distance)
                        {
                            minDist    = distance;
                            foundEnemy = GameBoard[i, j];
                        }
                    }
                }
            }

            return(foundEnemy);
        }
Example #3
0
        public int GetDistance(Creature creature1, Creature creature2)
        {
            //will return the distance between creature1 and creature2 and ensure that if they are in neighboring squares it will return 1
            CreatureLocInfo info1 = GetLocInfo(creature1);
            CreatureLocInfo info2 = GetLocInfo(creature2);

            return(Math.Abs(info1.row - info2.row) + (Math.Abs(info1.col - info2.col)));
        }
Example #4
0
        public void Move(Creature creature)
        {
            CreatureLocInfo currLoc    = GetLocInfo(creature);
            int             distToMove = GetDistanceFromLoc(SelectedGridCellI, SelectedGridCellJ, currLoc.row, currLoc.col);

            //verfy that the creature can move to the current location
            if ((GameBoard[SelectedGridCellI, SelectedGridCellJ] == null) && distToMove <= creature.Speed)
            {
                //move the creature to a new spot on the game board
                GameBoard[SelectedGridCellI, SelectedGridCellJ] = creature;
                GameBoard[currLoc.row, currLoc.col]             = null;
            }
        }
Example #5
0
        private CreatureLocInfo GetLocInfo(Creature creature)//Give the Location info
        {
            CreatureLocInfo info = new CreatureLocInfo();

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (GameBoard[i, j] != null)
                    {
                        if (GameBoard[i, j].Id == creature.Id)
                        {
                            info.ID   = creature.Id;
                            info.row  = i;
                            info.col  = j;
                            info.type = creature.Type;
                        }
                    }
                }
            }
            return(info);
        }
Example #6
0
        private void GameBoardRemove(Creature creature) //When any creature is dead it removes that creature from the Gameboard
        {
            CreatureLocInfo info = GetLocInfo(creature);

            GameBoard[info.row, info.col] = null;
        }
Example #7
0
        //this will return the closest enemy creature to the creature passed in
        private Creature GetClosestEnemy(Creature creature)
        {
            CreatureLocInfo info = GetLocInfo(creature);

            return(GetClosestEnemy(info));
        }
Example #8
0
        public void GetNewLoc(Creature creature, Creature target)//When the player wants the creature to move and attack this helps in moving the creature
        {
            //find the creature move it one place(or more) closer to the first monster/character found or the user's chosen target
            Creature enemy;

            if (auto)
            {
                enemy = GetClosestEnemy(creature);
            }
            else
            {
                enemy = target;
            }
            CreatureLocInfo creatureInfo = GetLocInfo(creature);
            CreatureLocInfo enemyInfo    = GetLocInfo(enemy);

            SelectedGridCellI = creatureInfo.row;
            SelectedGridCellJ = creatureInfo.col;
            int distToMove = creature.Speed;

            //get to the right row
            while (distToMove > 0)
            {
                if (GetDistanceFromLoc(SelectedGridCellI, SelectedGridCellJ, enemyInfo.row, enemyInfo.col) == 1)//creature is already there
                {
                    break;
                }
                if (SelectedGridCellI > enemyInfo.row)//creature needs to move down
                {
                    //check if there is a creature in the way
                    if (GameBoard[SelectedGridCellI - 1, SelectedGridCellJ] == null)
                    {
                        SelectedGridCellI--;
                        distToMove--;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (SelectedGridCellI < enemyInfo.row)//creature needs to move up
                {
                    //check if there is a creature in the way
                    if (GameBoard[SelectedGridCellI + 1, SelectedGridCellJ] == null)
                    {
                        SelectedGridCellI++;
                        distToMove--;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            //get to the right colum
            while (distToMove > 0)
            {
                if (GetDistanceFromLoc(SelectedGridCellI, SelectedGridCellJ, enemyInfo.row, enemyInfo.col) == 1)//creature is already there
                {
                    break;
                }
                if (SelectedGridCellJ > enemyInfo.col)//creature needs to move down
                {
                    //check if there is a creature in the way
                    if (GameBoard[SelectedGridCellI, SelectedGridCellJ - 1] == null)
                    {
                        SelectedGridCellJ--;
                        distToMove--;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (SelectedGridCellJ < enemyInfo.col)//creature needs to move up
                {
                    //check if there is a creature in the way
                    if (GameBoard[SelectedGridCellI, SelectedGridCellJ + 1] == null)
                    {
                        SelectedGridCellJ++;
                        distToMove--;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
        public void GameBoardRemove(Creature creature)
        {
            CreatureLocInfo info = GetLocInfo(creature);

            GameBoard[info.row, info.col] = null;
        }