Skip to content

Commit c5a04dc

Browse files
committed
restored commit
1 parent 84fd229 commit c5a04dc

8 files changed

Lines changed: 104 additions & 53 deletions

File tree

‎Worm/.idea/workspace.xml‎

Lines changed: 65 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
630 Bytes
Binary file not shown.
108 Bytes
Binary file not shown.

‎Worm/src/model/items/Block.java‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,46 @@ public void moveBody(List<Block> wormBody) {
6464
oldY = newY;
6565
}
6666
}
67-
6867
// Transfers head to opposite side when at it the end of game's border
6968
public void changeSide(Direction headDir) {
7069
double currentX = this.getX();
7170
double currentY = this.getY();
7271

7372
switch (headDir) {
74-
case LEFT: setBlockPosition(CANVAS_WIDTH - SIDE,currentY); break;
75-
case RIGHT: setBlockPosition(SIDE, currentY); break;
76-
case UP: setBlockPosition(currentX,CANVAS_HEIGHT - SIDE); break;
77-
case DOWN: setBlockPosition(currentX, SIDE); break;
73+
case LEFT: setBlockPosition(CANVAS_WIDTH - SIDE,currentY);
74+
nearVerticalBorder(currentX); break;
75+
case RIGHT: setBlockPosition(SIDE, currentY);
76+
nearVerticalBorder(currentX); break;
77+
case UP: setBlockPosition(currentX,CANVAS_HEIGHT - SIDE);
78+
nearHorizontalBorder(currentY); break;
79+
case DOWN: setBlockPosition(currentX, SIDE);
80+
nearHorizontalBorder(currentY); break;
81+
}
82+
}
83+
84+
public void nearVerticalBorder(double x) {
85+
//System.out.println("VERTICAL");
86+
//System.out.println(x);
87+
if (x == CANVAS_WIDTH - 2 * SIDE) {
88+
System.out.println("LEFT");
89+
setBlockPosition(250,125);
90+
}
91+
if (x == 2 * SIDE) {
92+
System.out.println("RIGHT");
93+
setBlockPosition(250,125);
94+
}
95+
}
96+
97+
public void nearHorizontalBorder(double y) {
98+
//System.out.println("HORIZONTAL");
99+
//System.out.println(y);
100+
if (y == CANVAS_HEIGHT - 2 * SIDE) {
101+
System.out.println("UP");
102+
setBlockPosition(250,125);
103+
}
104+
if (y == 2 * SIDE) {
105+
System.out.println("DOWN");
106+
setBlockPosition(250,125);
78107
}
79108
}
80109

‎Worm/src/model/items/Worm.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public boolean isDead() {
4141
public void setApple(Apple apple) {
4242
this.apple = apple;
4343
}
44+
public void setHeadDirection(Direction headDirection) {
45+
this.headDirection = headDirection;
46+
}
4447

4548
// Decides whether or not worm can move, travels whole worm by every tick
4649
public void move() {
@@ -67,8 +70,8 @@ private boolean canMove() {
6770
double xPosition = wormHead.getX();
6871
double yPosition = wormHead.getY();
6972

70-
boolean widthCheck = (xPosition >= sideSize) && (xPosition < CANVAS_WIDTH - sideSize);
71-
boolean heightCheck = (yPosition >= sideSize) && (yPosition < CANVAS_HEIGHT - sideSize);
73+
boolean widthCheck = (xPosition >= 2* sideSize) && (xPosition < CANVAS_WIDTH - sideSize);
74+
boolean heightCheck = (yPosition >= 2 * sideSize) && (yPosition < CANVAS_HEIGHT - sideSize);
7275

7376
return widthCheck && heightCheck;
7477
}

0 commit comments

Comments
 (0)