Skip to content
2 changes: 2 additions & 0 deletions .feature-model
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Snake_Game
Tile
Food
Spawn
Poison
MildPoison
Blank
Snake
Update
Expand Down
1 change: 1 addition & 0 deletions src/graphics/.feature-to-folder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update Controls
2 changes: 2 additions & 0 deletions src/logic/DataOfSquare.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public DataOfSquare(int color) {
//Lets add the color to the arrayList
C.add(Color.darkGray);// &line[Tile::Snake]
C.add(Color.BLUE); // &line[Food]
C.add(Color.RED); // &line[Poison]
C.add(Color.YELLOW); // &line[MildPoison]
C.add(Color.white); // &line[Playing_Area]
square = new SquarePanel(C.get(color));
}
Expand Down
2 changes: 2 additions & 0 deletions src/logic/SquareToLightUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public enum SquareToLightUp {
SNAKE, // &line[Tile::Snake]
FOOD, // &line[Food]
POISON, // &line[Poison]
MILD_POISON, // &line[MildPoison]
BACK_GROUND // &line[Blank]
}
53 changes: 51 additions & 2 deletions src/logic/ThreadsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
public class ThreadsController extends Thread {
private final ArrayList<ArrayList<DataOfSquare>> Squares;
private final Tuple headSnakePos;
private int sizeSnake = 3;
private int sizeSnake = 4;
private final long delay = 75;
public static Direction directionSnake;

private final ArrayList<Tuple> positions = new ArrayList<>();
private Tuple foodPosition; // &line[Food]
private Tuple poisonPosition; // &line[Poison]
private Tuple mildPoisonPosition; // &line[MildPoison]

//Constructor of ControllerThread
public ThreadsController(Tuple positionDepart) {
Expand All @@ -34,6 +35,22 @@ public ThreadsController(Tuple positionDepart) {
foodPosition = new Tuple(Window.getWindowHeight() - 1, Window.getWindowWidth() - 1);
spawnFood(foodPosition);//&line[Spawn]
// &end[Food]

// &begin[Poison]
poisonPosition = new Tuple(Window.getWindowHeight() - 3, Window.getWindowWidth() - 3);
spawnFood(poisonPosition); // &line[Spawn]
// &end[Poison]

// &begin[MildPoison]
poisonPosition = new Tuple(Window.getWindowHeight() - 5, Window.getWindowWidth() - 5);
spawnFood(poisonPosition); // &line[Spawn]
// &end[MildPoison]

// &begin[MildPoison]
// test functionality
//code
// &end[MildPoison]

}

//Important part :
Expand Down Expand Up @@ -69,6 +86,7 @@ private void checkCollision() {
}
}
// &end[Collision]

// &begin[Food]
boolean eatingFood = posCritique.getX() == foodPosition.y && posCritique.getY() == foodPosition.x;
if (eatingFood) {
Expand All @@ -79,6 +97,28 @@ private void checkCollision() {
spawnFood(foodPosition); // &line[Spawn]
}
// &end[Food]


// &begin[Poison]
boolean eatingPoison = posCritique.getX() == poisonPosition.y && posCritique.getY() == poisonPosition.x;
if (eatingPoison) {
System.out.println("Ouch");
sizeSnake = sizeSnake - 3;
poisonPosition = getTileNotInSnake();

spawnPoison(poisonPosition); // &line[Spawn]
}
// &end[Poison]

// &begin[MildPoison]
boolean eatingMildPoison = posCritique.getX() == mildPoisonPosition.y && posCritique.getY() == mildPoisonPosition.x;
if (eatingMildPoison) {
System.out.println("Mild Poison eaten");
sizeSnake = sizeSnake - 1;
mildPoisonPosition = getTileNotInSnake();
spawnMildPoison(mildPoisonPosition); // &line[Spawn]
}
// &end[MildPoison]
}

//Stops The Game
Expand All @@ -91,13 +131,21 @@ private void stopTheGame(String s) {
}
// &end[Collision]


//Put food in a position and displays it
// &begin[Spawn]
private void spawnFood(Tuple foodPositionIn) {
Squares.get(foodPositionIn.x).get(foodPositionIn.y).lightMeUp(SquareToLightUp.FOOD);
}
private void spawnPoison(Tuple poisonPositionIn) {
Squares.get(poisonPositionIn.x).get(poisonPositionIn.y).lightMeUp(SquareToLightUp.POISON);
}
private void spawnMildPoison(Tuple mildPoisonPositionIn) {
Squares.get(mildPoisonPositionIn.x).get(mildPoisonPositionIn.y).lightMeUp(SquareToLightUp.MILD_POISON);
}
// &end[Spawn]


// &begin[Blank]
//return a position not occupied by the snake
private Tuple getTileNotInSnake() {
Expand Down Expand Up @@ -194,3 +242,4 @@ private void deleteTail() {
// &end[Tail]

}