/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package boardgame;

/**
 *
 * @author csstudent
 */
public class TurnPhases {
    
    private static Game g;
    
    public static void setConnectedGame(Game game) {
        g = game;
    }
    
    public TurnPhases() {
    }
    
    public static void reinforce(Player p) {
        g.setCurrentPhase("reinforce");
        int numArmies = p.getArmiesPerTurn();
        //g.outText("Place armies on your territories. Left: " + numArmies);
        Territory t = new Territory(0, "", null);
        for (int i = 0; i < numArmies; i++) {
            t = new Territory(0, "", null);
            while (!(t.getOccupied().equals(p))) {
                //wait for player to click country and save it to 't'
            }
            t.changeUnits(t.getUnits()+ 1);
        }
    }
    
    public static void attack(Player p) {
        g.setCurrentPhase("attack");
        //g.outText("To attack, first select the territory you would like to attack from");
        Territory t = new Territory(0, "", null); 
        while (!(t.getOccupied().equals(p) && t.getUnits()>=2)) {
            //wait for player to click country and save it to 't'
        }
        
    }
    
    public static void move(Player p) {
        g.setCurrentPhase("move");
    }
    
    public static void takeTurn(Player p) {
        reinforce(p);
        attack(p);
        move(p);
        g.setCurrentTurn((g.getCurrentTurn()+1) % g.getNumPlayers());
    }
    
    public static int diceRoll() {
        return (int)Math.random()*6 + 1;
    }
}

@@ -198,16 +198,71 @@
 dgame;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.TreeSet;%0A%0A
 /**%0A *%0A 
@@ -1196,33 +1196,36 @@
       Territory 
-t
+from
  = new Territory
@@ -1249,33 +1249,36 @@
        while (!(
-t
+from
 .getOccupied().e
@@ -1289,17 +1289,20 @@
 s(p) && 
-t
+from
 .getUnit
@@ -1386,26 +1386,936 @@
         
-%7D%0A        
+    //If ENDPHASE button is pressed, return%0A        %7D%0A        Territory to = new Territory(0, %22%22, null);%0A        while (to.getOccupied().equals(p) %7C%7C !(from.isAdjacent(to))) %7B%0A            //wait for player to click country and save it to 't'%0A        %7D%0A        while (to.getUnits() %3E 0 && from.getUnits() %3E 0) %7B%0A            ArrayList%3CInteger%3E attackingDice = rollNumDice(Math.min(from.getUnits() - 1, 3));%0A            ArrayList%3CInteger%3E defendingDice = rollNumDice(Math.min(to.getUnits() - 1, 2));%0A            for (int i = 0; i %3C Math.min(attackingDice.size(), defendingDice.size()); i++) %7B%0A                if (attackingDice.get(i) %3E defendingDice.get(i)) %7B%0A                    to.changeUnits(to.getUnits()-1);%0A                %7D else %7B%0A                    from.changeUnits(from.getUnits()-1);%0A                %7D%0A                //wait for player to continue attack or press ENDPHASE(retreat) button%0A            %7D%0A        %7D
 %0A    %7D%0A 
@@ -2669,10 +2669,364 @@
 ;%0A    %7D%0A
+    public static ArrayList%3CInteger%3E rollNumDice(int num) %7B%0A        TreeSet%3CInteger%3E sorted = new TreeSet%3CInteger%3E();%0A        for (int i = 0; i %3C num; i++) %7B%0A            sorted.add(diceRoll());%0A        %7D%0A        ArrayList%3CInteger%3E out = new ArrayList%3CInteger%3E();%0A        for (int i : sorted) %7B%0A            out.add(i);%0A        %7D%0A        return out;%0A    %7D%0A
 %7D%0A

Add rollNumDice method, finish most of attack phase