package controller;

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

/**
 * 
 * @author Nick Chaput
 *
 */

public class PlayerUpdateBoardCtrl {

	PlayerApplication app;
	PlayerModel model;
	
	public PlayerUpdateBoardCtrl(PlayerApplication app, PlayerModel model) {
		this.app = app;
		this.model = model;
	}
	
	 public void processBoard() {
		  for (int x = Board.width - 1; x >= 0; x--) {
			  try {
			       Thread.sleep(25);
					 app.getView().paintImmediately(0, 0, 500, 500);
			    } catch (InterruptedException ie) {
			    }
			  for (int y = Board.height - 1; y >= 0; y--) {
				  if (model.level.currentBoard.grid[y][x].type != CellType.INERT 
						  && model.level.currentBoard.grid[y][x].type != CellType.BUCKET
						  && model.level.currentBoard.grid[y][x].tile == null) {
					  model.level.currentBoard.grid[y][x].tile = model.level.currentBoard.takeTileAbove(new Point(x,y));
					    /*try {
						       Thread.sleep(30);
								 app.getView().paintImmediately(50, 50, 500, 500);
						    } catch (InterruptedException ie) {
						    }*/
				  }
				  if (model.level.currentBoard.grid[y][x].type == CellType.BUCKET
						  && model.level.currentBoard.getTileAbove(new Point(x,y)).number == 5
						  && model.level.currentBoard.grid[y][x].tile == null) {
					  model.level.currentBoard.grid[y][x].tile = model.level.currentBoard.takeTileAbove(new Point(x,y));
					    /*try {
						       Thread.sleep(30);
								 app.getView().paintImmediately(50, 50, 500, 500);
						    } catch (InterruptedException ie) {
						    }*/
				  }
			  }
			  try {
			       Thread.sleep(25);
					// app.getView().paintImmediately(0, 0, 500, 500);
			    } catch (InterruptedException ie) {
			    }
		  }
	 }
	
}

@@ -461,24 +461,26 @@
  x--) %7B%0A%09%09%09 
+/*
  try %7B%0A%09%09%09  
@@ -489,33 +489,33 @@
    Thread.sleep(
-2
+1
 5);%0A%09%09%09%09%09 app.ge
@@ -503,24 +503,26 @@
 p(15);%0A%09%09%09%09%09
+//
  app.getView
@@ -609,16 +609,49 @@
 %09%09%09    %7D
+*/%0A%09%09%09  boolean hasEmpty = false;
 %0A%09%09%09  fo
@@ -996,32 +996,56 @@
 ew Point(x,y));%0A
+%09%09%09%09%09  hasEmpty = true;%0A
 %09%09%09%09%09    /*try %7B
@@ -1515,24 +1515,48 @@
 oint(x,y));%0A
+%09%09%09%09%09  hasEmpty = true;%0A
 %09%09%09%09%09    /*t
@@ -1721,24 +1721,46 @@
 %09  %7D%0A%09%09%09  %7D%0A
+%09%09%09  if (hasEmpty) %7B%0A%09
 %09%09%09  try %7B%0A%09
@@ -1754,24 +1754,25 @@
 %09%09%09%09  try %7B%0A
+%09
 %09%09%09       Th
@@ -1786,18 +1786,18 @@
 eep(
-25
+60
 );%0A%09%09%09%09%09
 // a
@@ -1784,34 +1784,33 @@
 sleep(60);%0A%09%09%09%09%09
-//
+%09
  app.getView().p
@@ -1837,32 +1837,33 @@
 , 500, 500);%0A%09%09%09
+%09
     %7D catch (Int
@@ -1893,14 +1893,22 @@
 %0A%09%09%09
+%09
     %7D%0A
+%09%09%09  %7D%0A
 %09%09  

Fix delay when move is located in upper rows only