package controller;

import java.awt.EventQueue;

import boundary.PlayerApplication;
import model.PlayerModel;
import model.Point;

/**
 * Controller for the Elimination variation.
 *
 * @author Bailey Sheridan, Nick Chaput
 */
public class PlayerEliminationCtrl implements PlayerVariationCtrl {
  PlayerApplication app;
  PlayerModel model;

  /**
   * Creates a new PlayerEliminationCtrl.
   * @param app
   * @param model
   */
  public PlayerEliminationCtrl(PlayerApplication app, PlayerModel model) {
    this.app = app;
    this.model = model;
  }

  public boolean specialMove() {
	  model.counter--;
    return false;
  }

  public boolean finishMove() {
    if (model.counter <= 0) {
      return false;
    }

    model.counter--;

    if(model.counter==0) {
    	EventQueue.invokeLater(new Runnable() {
    		@Override
    		public void run() {
                PlayerEndLevelCtrl end = new PlayerEndLevelCtrl(app, model);
    			end.endLevel();
    		}
    	});
    }
    
    if(model.move.isValid()) {
	    // set the cells to marked
	    for (Point point : model.move.points) {
	      model.level.currentBoard.grid[point.x][point.y].marked = true;
	    }
	    
	    for(int i = 0; i<9; i++) {
	    	for(int j = 0; j<9; j++) {
	    		if(!model.level.currentBoard.grid[i][j].marked)
	    			return true;
	    	}
	    }
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
	            PlayerEndLevelCtrl end = new PlayerEndLevelCtrl(app, model);
				end.endLevel();
			}
		});
	    return true;
    }
    else
    	return false;
  }

  @Override
  public boolean remove() {
	  // TODO Auto-generated method stub
	  specialMove();
	  return false;
  }

  @Override
  public boolean scramble() {
	  // TODO Auto-generated method stub
	  specialMove();
	  return false;
  }

  @Override
  public boolean swap() {
	  // TODO Auto-generated method stub
	  specialMove();
	  return false;
  }
}

@@ -544,24 +544,209 @@
 model;%0A  %7D%0A%0A
+  protected Runnable endLevelCtrl() %7B%0A    return new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A        (new PlayerEndLevelCtrl(app, model)).endLevel();%0A      %7D%0A    %7D;%0A  %7D%0A%0A
   public boo
@@ -766,17 +766,18 @@
 ove() %7B%0A
-%09
+  
   model.
@@ -923,24 +923,25 @@
 r--;%0A%0A    if
+ 
 (model.count
@@ -946,10 +946,12 @@
 nter
+ 
 ==
+ 
 0) %7B
@@ -955,17 +955,18 @@
 ) %7B%0A    
-%09
+  
 EventQue
@@ -984,201 +984,39 @@
 ter(
-new Runnable() %7B%0A    %09%09@Override%0A    %09%09public void run() %7B%0A                PlayerEndLevelCtrl end = new PlayerEndLevelCtrl(app, model);%0A    %09%09%09end.endLevel();%0A    %09%09%7D%0A    %09%7D);%0A    %7D%0A    
+endLevelCtrl());%0A    %7D%0A
 %0A    if
+ 
 (mod
@@ -1032,25 +1032,26 @@
 sValid()) %7B%0A
-%09
+  
     // set t
@@ -1069,21 +1069,22 @@
  marked%0A
-%09
     
+  
 for (Poi
@@ -1111,25 +1111,26 @@
 e.points) %7B%0A
-%09
+  
       model.
@@ -1190,29 +1190,27 @@
 ue;%0A
-%09
+  
     %7D%0A
-%09    %0A%09
+%0A  
     for
+ 
 (int
@@ -1218,17 +1218,19 @@
 i = 0; i
-%3C
+ %3C 
 9; i++) 
@@ -1235,17 +1235,20 @@
 ) %7B%0A
-%09
+   
     
-%09
+ 
 for
+ 
 (int
@@ -1256,17 +1256,19 @@
 j = 0; j
-%3C
+ %3C 
 9; j++) 
@@ -1273,17 +1273,21 @@
 ) %7B%0A
-%09
+  
     
-%09%09
+    
 if
+ 
 (!mo
@@ -1331,17 +1331,23 @@
 ked)
-%0A%09
+ %7B%0A        
     
-%09%09%09
 retu
@@ -1359,207 +1359,86 @@
 ue;%0A
-%09
     
-%09%7D%0A%09    %7D%0A%09%09EventQueue.invokeLater(new Runnable() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09
+      %7D%0A        %7D%0A
       
+%7D%0A
       
-PlayerEndLevelCtrl end = new PlayerEndLevelCtrl(app, model);%0A%09%09%09%09end.endLevel();%0A%09%09%09%7D%0A%09%09%7D);%0A%09
+EventQueue.invokeLater(endLevelCtrl());%0A  
     
@@ -1460,22 +1460,13 @@
   %7D%0A
-    else
 %0A    
-%09
 retu
@@ -1524,47 +1524,33 @@
 ) %7B%0A
-%09
+ 
   
+ 
 // TODO
- Auto-generated method stub%0A%09
+: implement%0A  
   sp
@@ -1554,33 +1554,34 @@
  specialMove();%0A
-%09
+  
   return false;%0A
@@ -1623,25 +1623,26 @@
 cramble() %7B%0A
-%09
+  
   // TODO Au
@@ -1642,37 +1642,22 @@
 TODO
- Auto-generated method stub%0A%09
+: implement%0A  
   sp
@@ -1661,33 +1661,34 @@
  specialMove();%0A
-%09
+  
   return false;%0A
@@ -1730,17 +1730,18 @@
 wap() %7B%0A
-%09
+  
   // TOD
@@ -1745,37 +1745,22 @@
 TODO
- Auto-generated method stub%0A%09
+: implement%0A  
   sp
@@ -1776,9 +1776,10 @@
 ();%0A
-%09
+  
   re

Improve PlayerEliminationCtrl