Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Game2048.java #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions src/com/bulenkov/game2048/Game2048.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ public Game2048() {
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
resetGame();
}
if (!canMove()) {

if (!canMove())
myLose = true;
}


if (!myWin && !myLose) {
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
Expand Down Expand Up @@ -154,42 +153,46 @@ private boolean isFull() {
boolean canMove() {
if (!isFull()) {
return true;
}
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
Tile t = tileAt(x, y);
if ((x < 3 && t.value == tileAt(x + 1, y).value)
|| ((y < 3) && t.value == tileAt(x, y + 1).value)) {
return true;
}

for (int y = 0, x = 0; y < 4; y++) {
Tile t = tileAt(x, y);
if ((x < 3 && t.value == tileAt(x + 1, y).value)
|| ((y < 3) && t.value == tileAt(x, y + 1).value)) {
return true;
}
if((y == 3) && (x < 3)){
x++;
y=0;
}
}
}

return false;

}

private boolean compare(Tile[] line1, Tile[] line2) {
if (line1 == line2) {
if (line1 == line2)
return true;
} else if (line1.length != line2.length) {
else if (line1.length != line2.length)
return false;
}


for (int i = 0; i < line1.length; i++) {
if (line1[i].value != line2[i].value) {
if (line1[i].value != line2[i].value)
return false;
}
}
return true;
}

private Tile[] rotate(int angle) {
Tile[] newTiles = new Tile[4 * 4];
int offsetX = 3, offsetY = 3;
if (angle == 90) {
if (angle == 90)
offsetY = 0;
} else if (angle == 270) {
else if (angle == 270)
offsetX = 0;
}


double rad = Math.toRadians(angle);
int cos = (int) Math.cos(rad);
Expand Down