From 44eeb5a16359467cd1a6b1e46de3f2295fe59e84 Mon Sep 17 00:00:00 2001 From: Oscar Bauer <oscar.bauer@etu.univ-amu.fr> Date: Thu, 12 Dec 2024 15:36:25 +0100 Subject: [PATCH] version4 (==version3) --- CCI_Java/CCI_Java/src/version3/SnakeGame.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CCI_Java/CCI_Java/src/version3/SnakeGame.java b/CCI_Java/CCI_Java/src/version3/SnakeGame.java index 68091ff..3c1dae6 100644 --- a/CCI_Java/CCI_Java/src/version3/SnakeGame.java +++ b/CCI_Java/CCI_Java/src/version3/SnakeGame.java @@ -17,15 +17,15 @@ public class SnakeGame { } public void initialize() { - direction = Direction.NORTH; + direction = Direction.EAST; int startL = GRID_LINES / 2; int startC = GRID_COLUMNS / 2; gameOver = false; setApple(); segments = new ArrayList<Position>(); segments.add(new Position(startL, startC)); - segments.add(new Position(startL + 1, startC)); - segments.add(new Position(startL + 2, startC)); + segments.add(new Position(startL, startC - 1)); + segments.add(new Position(startL, startC - 2)); } @@ -51,18 +51,17 @@ public class SnakeGame { return false; } - public boolean isAppleAt(Position position) { return position.isSamePosition(apple); } - + public void print() { - for (int L =0; L < GRID_LINES; L++) { - for (int c =0; c<GRID_COLUMNS;c++) { + for (int L = 0; L < GRID_LINES; L++) { + for (int c = 0; c < GRID_COLUMNS; c++) { Position tmp = new Position(L, c); - if(isAppleAt(tmp)) + if (isAppleAt(tmp)) System.out.print(" A "); - else if(isSnakeAt(tmp)) + else if (isSnakeAt(tmp)) System.out.print(" S "); else System.out.print(" _ "); @@ -70,7 +69,7 @@ public class SnakeGame { System.out.println(); } } - + // public void printLine() { // String line = ""; // for (int c =0; c<GRID_COLUMNS;c++) { -- GitLab