-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
305f6d2
commit 8f09adb
Showing
11 changed files
with
191 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package sample; | ||
|
||
import javafx.scene.image.Image; | ||
|
||
public enum AnimalTile implements Tile{ | ||
ANIMAL1("images/animal-1.png"), | ||
ANIMAL2("images/animal-2.png"), | ||
ANIMAL3("images/animal-3.png"), | ||
ANIMAL4("images/animal-4.png"), | ||
ANIMAL5("images/animal-5.png"), | ||
ANIMAL6("images/animal-6.png"), | ||
ANIMAL7("images/animal-7.png"), | ||
ANIMAL8("images/animal-8.png"), | ||
ANIMAL9("images/animal-9.png"), | ||
ANIMAL10("images/animal-10.png"); | ||
|
||
private final String imagePath; | ||
|
||
AnimalTile(String imagePath){ | ||
this.imagePath = imagePath; | ||
} | ||
|
||
public Image getImage(){ | ||
return new Image(this.imagePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sample; | ||
|
||
import simulation.Simulation; | ||
|
||
public class AnimalTileFactory{ | ||
private Simulation simulation; | ||
AnimalTileFactory(Simulation simulation){ | ||
this.simulation = simulation; | ||
} | ||
public TerrainTile getTile(int x, int y){ | ||
if (simulation.plantBoard.isPlanted(x,y)){ | ||
if (simulation.jungle.contains(x,y)) | ||
return TerrainTile.JUNGLEPLANTED; | ||
else return TerrainTile.SAVANNAHPLANTED; | ||
} | ||
else{ | ||
if(simulation.jungle.contains(x,y)) | ||
return TerrainTile.JUNGLE; | ||
else return TerrainTile.SAVANNAH; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package sample; | ||
|
||
import javafx.scene.canvas.Canvas; | ||
import simulation.Simulation; | ||
|
||
public class SimulationCanvas extends Canvas { | ||
private final Simulation simulation; | ||
private final TerrainTileFactory terrainTileFactory; | ||
private final AnimalTileFactory animalTileFactory; | ||
private final int tileSize = 5; | ||
SimulationCanvas(Simulation simulation){ | ||
super(simulation.getWidth()*10,simulation.getHeight()*10); | ||
this.simulation = simulation; | ||
this.terrainTileFactory = new TerrainTileFactory(simulation); | ||
this.animalTileFactory = new AnimalTileFactory(simulation); | ||
} | ||
public void update(){ | ||
for (int i = 0; i<simulation.getWidth(); i++){ | ||
for (int j = 0; j<simulation.getHeight(); j++){ | ||
drawTile(i,j, terrainTileFactory.getTile(i,j)); | ||
drawTile(i,j,animalTileFactory.getTile(i,j)); | ||
} | ||
} | ||
} | ||
private void drawTile(int x, int y, Tile tile){ | ||
int drawX = x*tileSize; | ||
int drawY = y*tileSize; | ||
this.getGraphicsContext2D().drawImage(tile.getImage(),drawX,drawY); | ||
System.out.println("Drawing "+tile.toString()+" at "+drawX+" "+drawY); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package sample; | ||
|
||
public class SimulationWindowController { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sample; | ||
|
||
import javafx.scene.image.Image; | ||
|
||
public enum TerrainTile implements Tile{ | ||
JUNGLE("images/jungle-tile.png"), | ||
JUNGLEPLANTED("images/jungle-tile-planted.png"), | ||
SAVANNAH("images/savannah-tile.png"), | ||
SAVANNAHPLANTED("images/savannah-tile-planted.png"); | ||
private final String imagePath; | ||
|
||
TerrainTile(String imagePath){ | ||
this.imagePath = imagePath; | ||
} | ||
|
||
public Image getImage(){ | ||
return new Image(this.imagePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sample; | ||
|
||
import simulation.Simulation; | ||
|
||
public class TerrainTileFactory { | ||
private Simulation simulation; | ||
TerrainTileFactory(Simulation simulation){ | ||
this.simulation = simulation; | ||
} | ||
public TerrainTile getTile(int x, int y){ | ||
if (simulation.plantBoard.isPlanted(x,y)){ | ||
if (simulation.jungle.contains(x,y)) | ||
return TerrainTile.JUNGLEPLANTED; | ||
else return TerrainTile.SAVANNAHPLANTED; | ||
} | ||
else{ | ||
if(simulation.jungle.contains(x,y)) | ||
return TerrainTile.JUNGLE; | ||
else return TerrainTile.SAVANNAH; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sample; | ||
|
||
import javafx.scene.image.Image; | ||
|
||
public interface Tile { | ||
public Image getImage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package simulation; | ||
|
||
public class InvalidStartingParametersException extends Exception { | ||
InvalidStartingParametersException(String errorMessage){ | ||
super(errorMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters