Beispiel #1
0
 /// <summary>
 /// Method checks if attacking unit can attack it's target and finds where the attacking unit is to move to,
 /// assuming movement is necessary. Then calls upon the graphicalBattlefield to do the required action.
 /// </summary>
 /// <param name="cx">X coordinate of unit to be attacked</param>
 /// <param name="cy">Y coordinate of unit to be attacked</param>
 private void checkPos(int cx, int cy)
 {
     if (unitsOnField[cx, cy].GetComponent <UnitGameObject>().Attackable)//Checks if unit can be attacked
     {
         //Finds where it should move to attack incase of meele unit.
         GroundGameObject[] neighbours = findNeighboursHex(cx, cy);
         Point tmpGoal = neighbours[0].LogicalPos;
         if (!neighbours[0].Reachable)
         {
             for (int i = 1; i < neighbours.Length; i++)
             {
                 if (neighbours[i] == null)
                 {
                     break;
                 }
                 if (neighbours[i].Reachable)
                 {
                     tmpGoal = neighbours[i].LogicalPos;
                     break;
                 }
             }
         }
         graphicalBattlefield.attackUnit(unitsOnField[cx, cy].GetComponent <UnitGameObject>(), tmpGoal);
     }
     else
     {
         //Finds closest position to target that it can reach.
         while (!field[cx, cy].GetComponent <GroundGameObject>().Reachable)
         {
             if (cx < x)
             {
                 cx++;
             }
             else if (cx > x)
             {
                 cx--;
             }
             if (cy < y)
             {
                 cy++;
             }
             else if (cy > y)
             {
                 cy--;
             }
         }
         graphicalBattlefield.moveUnit(new Point(cx, cy));
     }
 }
Beispiel #2
0
 /// <summary>
 /// Decides what happens when you click on unit
 /// </summary>
 /// <param name="direction">What direction your approaching from</param>
 public void MouseDown(int direction)
 {
     if (ItsTurn)
     {
         //todo defend
     }
     else if (Attackable)
     {
         Point destination;
         if (logicalPos.y % 2 == 0)
         {
             destination = logicalPos.addition(HEXDIRSEVEN[direction]);
         }
         else
         {
             destination = logicalPos.addition(HEXDIRSODD[direction]);
         }
         graphicalBattlefield.attackUnit(this, destination);
     }
 }