mirror of
https://github.com/opelly27/Sokobot.git
synced 2026-05-20 05:17:39 +00:00
fixed player spawning in a block
added mr command to reset the map if map is impossible
This commit is contained in:
@@ -2,38 +2,42 @@ package me.polymarsdev.sokobot.entity;
|
||||
|
||||
import me.polymarsdev.sokobot.objects.Grid;
|
||||
|
||||
public class Player
|
||||
{
|
||||
public class Player {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
Grid currentGrid;
|
||||
public Player(int x, int y, Grid currentGrid)
|
||||
{
|
||||
|
||||
public Player(int x, int y, Grid currentGrid) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.currentGrid = currentGrid;
|
||||
}
|
||||
public int getX()
|
||||
{
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
public int getY()
|
||||
{
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
public void setPosition(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
public void resetPosition() {
|
||||
int setX = 2;
|
||||
int setY = 2;
|
||||
while (currentGrid.isBoxRaw(setX, setY)) {
|
||||
if (setX >= currentGrid.getWidth() - 1) {
|
||||
setY++;
|
||||
setX = 1;
|
||||
} else setX++;
|
||||
}
|
||||
this.x = setX;
|
||||
this.y = setY;
|
||||
}
|
||||
public boolean moveUp()
|
||||
{
|
||||
if (!currentGrid.isWall(x, y - 1))
|
||||
{
|
||||
if (currentGrid.isBox(x, y - 1))
|
||||
{
|
||||
if (currentGrid.getBox(x, y - 1).moveUp())
|
||||
{
|
||||
|
||||
public boolean moveUp() {
|
||||
if (!currentGrid.isWall(x, y - 1)) {
|
||||
if (currentGrid.isBox(x, y - 1)) {
|
||||
if (currentGrid.getBox(x, y - 1).moveUp()) {
|
||||
y -= 1;
|
||||
return true;
|
||||
}
|
||||
@@ -44,14 +48,11 @@ public class Player
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean moveDown()
|
||||
{
|
||||
if (!currentGrid.isWall(x, y + 1))
|
||||
{
|
||||
if (currentGrid.isBox(x, y + 1))
|
||||
{
|
||||
if (currentGrid.getBox(x, y + 1).moveDown())
|
||||
{
|
||||
|
||||
public boolean moveDown() {
|
||||
if (!currentGrid.isWall(x, y + 1)) {
|
||||
if (currentGrid.isBox(x, y + 1)) {
|
||||
if (currentGrid.getBox(x, y + 1).moveDown()) {
|
||||
y += 1;
|
||||
return true;
|
||||
}
|
||||
@@ -62,14 +63,11 @@ public class Player
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean moveLeft()
|
||||
{
|
||||
if (!currentGrid.isWall(x - 1, y))
|
||||
{
|
||||
if (currentGrid.isBox(x - 1, y))
|
||||
{
|
||||
if (currentGrid.getBox(x - 1, y).moveLeft())
|
||||
{
|
||||
|
||||
public boolean moveLeft() {
|
||||
if (!currentGrid.isWall(x - 1, y)) {
|
||||
if (currentGrid.isBox(x - 1, y)) {
|
||||
if (currentGrid.getBox(x - 1, y).moveLeft()) {
|
||||
x -= 1;
|
||||
return true;
|
||||
}
|
||||
@@ -80,14 +78,11 @@ public class Player
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean moveRight()
|
||||
{
|
||||
if (!currentGrid.isWall(x + 1, y))
|
||||
{
|
||||
if (currentGrid.isBox(x + 1, y))
|
||||
{
|
||||
if (currentGrid.getBox(x + 1, y).moveRight())
|
||||
{
|
||||
|
||||
public boolean moveRight() {
|
||||
if (!currentGrid.isWall(x + 1, y)) {
|
||||
if (currentGrid.isBox(x + 1, y)) {
|
||||
if (currentGrid.getBox(x + 1, y).moveRight()) {
|
||||
x += 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user