Skip to content
Snippets Groups Projects
Commit acdde5e0 authored by Jerusalem Laila's avatar Jerusalem Laila
Browse files

logger

parent 2fcaab40
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,16 @@ package org.example.SnakeGame;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.example.game.Direction;
import java.util.ArrayList;
import java.util.List;
public class Snake extends Circle {
private final static Logger log = LogManager.getLogger(Snake.class);
private List<Circle> tails;
private int length = 0;
private Direction currentDirection;
......@@ -31,15 +35,19 @@ public class Snake extends Circle {
}
if (currentDirection == Direction.UP){
log.info("Snake moves UP");
setCenterY(getCenterY()- step);
}
else if (currentDirection == Direction.DOWN){
log.info("Snake moves DOWN");
setCenterY(getCenterY() + step);
}
else if (currentDirection == Direction.LEFT) {
log.info("Snake moves LEFT");
setCenterX(getCenterX() - step);
}
else if (currentDirection == Direction.RIGHT) {
log.info("Snake moves RIGHT");
setCenterX(getCenterX() + step);
}
}
......
......@@ -18,7 +18,7 @@ import java.util.ResourceBundle;
public class SnakeGameController implements Initializable {
private final static Logger logger = LogManager.getLogger(SnakeGameController.class);
private final static Logger log = LogManager.getLogger(SnakeGameController.class);
private static final int radius = 14;
private static final int width = 600;
......@@ -39,12 +39,18 @@ public class SnakeGameController implements Initializable {
* and display it randomly
*/
private void newFood(){
log.info("Food was created");
food = new Circle(random.nextInt(400),random.nextInt(500), radius);
food.setFill(Color.RED);
anchorPane.getChildren().add(food);
}
/**
* methode will create the food
* and display it randomly
*/
private void newSnake(){
log.info("Snake was created");
snake = new Snake(300,250, radius +2);
anchorPane.getChildren().add(snake);
for (int i = 0; i < 25; i++){
......@@ -63,11 +69,14 @@ public class SnakeGameController implements Initializable {
snake.step();
adjustLocation();
if (hit() ){
log.info("Collected food");
snake.eat(food);
score.setText(" "+ snake.getLength());
newFood();
log.info("Spawned new food");
}
else if (gameOver()){
log.info("Game Over");
anchorPane.getChildren().clear();
anchorPane.getChildren().add(score);
score.setText("Game Over "+ snake.getLength());
......@@ -110,7 +119,7 @@ public class SnakeGameController implements Initializable {
move();
Thread.sleep(100/((snake.getLength() / 10)));
}
} catch(InterruptedException ie){}};
}catch(InterruptedException ignored){}};
anchorPane.sceneProperty().addListener((observable, oldScene, newScene) -> {
......
......@@ -3,10 +3,7 @@ package org.example.StartScreen;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -22,25 +19,6 @@ public class StartScreen extends Application {
private final static double HEIGHT = 500;
public static void main(String[] args) {
log.info("Startscene is activated");
launch(args);
}
// @Override
// public void start(Stage startstage) throws Exception{
// Parent root = FXMLLoader.load(getClass().getResource("/fxml/start.fxml"));
// Parent optionsPage = FXMLLoader.load(getClass().getResource("/fxml/OptionsScreen.fxml"));
// Scene scene = new Scene(root);
// startstage.setTitle("Snake Game");
// startstage.setResizable(false);
// startstage.setScene(scene);
// startstage.show();
// }
public static void changeScene (String fxml, String css) {
try {
FXMLLoader loader = new FXMLLoader();
......@@ -54,7 +32,6 @@ public class StartScreen extends Application {
exception.printStackTrace();
}
}
@Override
public void start(Stage stage) throws Exception {
stages=stage;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment