public void draw() { switch (gameState) { case START: background(0); break; case PLAY: background(100); sun.display(); sun.update(); garden.display(); garden.update(); milk.update(); milk.display(); textSize(20); text("Sun : " + sunGrade, 10, 20); // Sun collision test if (isHit(sun.x, sun.y, sun.w, sun.h, mouseX, mouseY, 0, 0)) { sun.getEaten(); sunGrade += 50; } // Bullet collision test break; case WIN: break; case LOSE: break; } }
@Override public void run() { for (int i = 0; i < 100; i++) { testGarden.removeVegetable(testGarden.chooseRandomOne(testGarden.vegetables.size())); try { Thread.sleep(870); } catch (InterruptedException e) { e.printStackTrace(); } } }
@Override public void run() { while (true) { testGarden.printList(testGarden.fruits); testGarden.printList(testGarden.vegetables); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } }
public static boolean isComplete(GardenModel mod) { for (Garden g : mod.gardens) { if (g.getTreeCount() != mod.trees) return false; } for (Iterator<Line> it = mod.grid.iterateColumns(); it.hasNext(); ) { Line col = it.next(); if (col.getTreeCount() != mod.trees) return false; } for (Iterator<Line> it = mod.grid.iterateRows(); it.hasNext(); ) { Line row = it.next(); if (row.getTreeCount() != mod.trees) return false; } return Analysis.isValid(mod); }
public void mouseReleased() { if (fruitOption == Banana && sunGrade >= BananCost) { sunGrade -= BananCost; } else if (fruitOption == Melon) { sunGrade -= BananCost; } else return; garden.addPlant(fruitOption, mouseX, mouseY); }
@Override public void run() { for (int i = 0; i < 100; i++) { testGarden.addVegetable(0, "Veg " + i); try { Thread.sleep(750); } catch (InterruptedException e) { e.printStackTrace(); } } }
@Override public void run() { for (int i = 0; i < 100; i++) { testGarden.addFruit(0, "Fruit " + i); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } }
public static boolean isValid(GardenModel mod) { for (Garden g : mod.gardens) { if (g.getTreeCount() > mod.trees) return false; if (g.getUnknownCount() + g.getTreeCount() < mod.trees) return false; } for (Iterator<Line> it = mod.grid.iterateColumns(); it.hasNext(); ) { Line col = it.next(); if (col.getTreeCount() > mod.trees) return false; if (col.getUnknownCount() + col.getTreeCount() < mod.trees) return false; } for (Iterator<Line> it = mod.grid.iterateRows(); it.hasNext(); ) { Line row = it.next(); if (row.getTreeCount() > mod.trees) return false; if (row.getUnknownCount() + row.getTreeCount() < mod.trees) return false; } for (Cell c : mod.grid) { if (c.getState() == State.Tree) { for (Iterator<Cell> it = mod.grid.iterateAdjacent(c); it.hasNext(); ) { if (it.next().getState() == State.Tree) return false; } } } for (Garden g : mod.gardens) { if (!g.areThereEnoughFreeNonAdjacentCells()) return false; } for (Line l : mod.grid.getColumnsAndRows()) { if (!l.areThereEnoughFreeNonAdjacentCells(mod.trees)) return false; } return checkBalance(mod); }
boolean containsCell(Cell c) { for (Garden g : this) { if (g.contains(c)) return true; } return false; }
private static void test1() { for (int i = 0; i < 5; i++) { testGarden.addFruit(i, "Fruit " + i); } testGarden.printList(testGarden.fruits); for (int i = 0; i < 5; i++) { testGarden.addVegetable(i, "Vegetable " + i); } testGarden.printList(testGarden.vegetables); testGarden.addFruit(7, "New Fruit 0"); testGarden.printList(testGarden.fruits); testGarden.addVegetable(3, "New Vegetable 0"); testGarden.addVegetable(5, "New Vegetable 1"); testGarden.printList(testGarden.vegetables); testGarden.removeFruit(10); testGarden.printList(testGarden.fruits); testGarden.removeVegetable(3); testGarden.printList(testGarden.vegetables); testGarden.removeVegetable(6); testGarden.printList(testGarden.vegetables); }