static void Main(string[] args)
    {
        //calling and setting the class
        UserMath math = new UserMath();

        //taking user input
        Console.WriteLine("Please enter a number to do some math on: ");
        int userNum = Convert.ToInt32(Console.ReadLine());

        //calling the method in the class
        int equal = math.Addition(userNum);

        Console.WriteLine(userNum + " + 5 = " + equal);

        //calling the method in the class
        int equal2 = math.Subtraction(userNum);

        Console.WriteLine(userNum + " - 5 = " + equal2);

        //calling the method in the class
        int equal3 = math.Multi(userNum);

        Console.WriteLine(userNum + " * 5 = " + equal3);


        Console.ReadLine();
    }
    public static bool attackable(Unit unit1, Unit unit2)
    {
        if (battle[unit1.GetType()][unit2.GetType()] == 0)
        {
            return(false);
        }
        else if (unit1.GetType() == typeof(Infantry) ||
                 unit1.GetType() == typeof(Mech) || unit1.GetType() == typeof(Bike) ||
                 unit1.GetType() == typeof(Recon) || unit1.GetType() == typeof(Flare) ||
                 unit1.GetType() == typeof(Tank) || unit1.GetType() == typeof(MediumTank) ||
                 unit1.GetType() == typeof(WarTank) || unit1.GetType() == typeof(Carrier))
        {
            return(true);
        }
        else if (unit1.getAmmo() == 0)
        {
            return(false);
        }
        else
        {
            return(true);
        }
        int level = 0;

        if (unit1.getLevel() == 1)
        {
            level = 5;
        }
        else if (unit1.getLevel() == 2)
        {
            level = 10;
        }
        else if (unit1.getLevel() == 3)
        {
            level = 20;
        }
        int co = 0;

        if (UserMath.inRange(team[turn].getUnits.getCommander(), unit1, team[turn].getCo().getCoZone()))
        {
            co = 10;
        }
        int attackStat = 100 + level +
                         battle[unit1.GetType()][unit2.GetType()] * (unit1.getHealth() / 10) * attackStat / defenseStat;
    }
    public static bool inRange(Unit u1, Unit u2, int r)
    {
        int x1 = UserMath.Dround(u1.gameObject.transform.position.x + .5);
        int y1 = UserMath.Dround(u1.gameObject.transform.position.y + .5);
        int x2 = UserMath.Dround(u2.gameObject.transform.position.x + .5);
        int y2 = UserMath.Dround(u2.gameObject.transform.position.y + .5);

        for (int i = -1 * r; i <= r; i++)
        {
            for (int j = -1 * (r - Math.Abs(i)); j <= (r - Math.Abs(i)); j++)
            {
                if (x1 + i == x2 && y1 + j == y2)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Exemple #4
0
    public static void updatePath(Tile t, Map m)
    {
        if (moveList.Contains(t))
        {
            bool inside = false;
            for (int i = 0; i < currentPath.length(); ++i)
            {
                if (t == currentPath.at(i).getValue())
                {
                    currentPath = currentPath.getUpTo(i);
                    inside      = true;
                }
            }
            if (!inside)
            {
                if (UserMath.About(m.distance(t, currentPath.at(currentPath.length() - 1).getValue()), 1) && currentPath.getCost() + movementCosts[t.getType()] <= currentUnit.getMoves())
                {
                    currentPath.insertTail(t, movementCosts[t.getType()]);
                }
                else
                {
                    /*
                     *      try generating shortest path using a variation of Dijkstra's algorithm
                     *      if such a path doesn't exist, try it for the 2nd most recent
                     *              (base will work since t is in movelist)
                     *              Notes: break as soon as the node is found (1 pair),
                     *              we can't really afford the full runtime (I think)
                     */
                    Path shortPath;
                    Path tempPath;
                    for (int i = currentPath.length() - 1; i >= 0; --i)
                    {
                        //Note that since t is in moveList, that currentPath will be set at some point
                        //If runtime is too slow, we can just run it on the starting node
                        tempPath = shortestPath(currentPath.at(i).getValue(), t, m);
                        if (tempPath != null)
                        {
                            shortPath = currentPath.getUpTo(i).merge(tempPath);
                            shortPath.removeCycles();
                            // shortest path doesn't contain at(i)
                            if (shortPath.getCost() <= currentUnit.getMoves())
                            {
                                currentPath = shortPath;
                                i           = -1;                                     //equivalent to break;
                            }
                        }
                        else
                        {
                            UI.print("Shortest Path Error! Please let Kenneth know if you see this");
                        }
                    }
                }
            }

            List <int> toHighlight = new List <int>();
            foreach (Tile x in currentPath.getTiles())
            {
                toHighlight.Add(moveList.IndexOf(x));
            }
            UI.highlightPath(toHighlight);
        }
    }