Commit f73fbc75 authored by nargessalehi98's avatar nargessalehi98

Add Color checking feature(test).

parent 66ea0959
/*** In The Name of Allah ***/
import org.w3c.dom.css.RGBColor;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
......@@ -21,15 +23,18 @@ public class GameState {
public int locX, locY, diam;
public boolean gameOver;
private boolean keyUP, keyDOWN, keyRIGHT, keyLEFT;
private boolean mousePress;
private int mouseX, mouseY;
private KeyHandler keyHandler;
private MouseHandler mouseHandler;
public double rotateAmount;
private boolean one = false;
private boolean two = false;
private boolean three = false;
public GameState() {
public GameState(int num) {
locX = 100;
locY = 100;
diam = 42;
......@@ -45,37 +50,62 @@ public class GameState {
mouseX = 0;
mouseY = 0;
//
if (num == 1) {
one = true;
}
if (num == 2) {
two = true;
}
if (num == 3) {
three = true;
}
keyHandler = new KeyHandler();
mouseHandler = new MouseHandler();
}
public Rectangle getBounds(int locX,int locY){
return new Rectangle( locX, locY, 25, 25);
}
/**
* The method which updates the game state.
*/
public void update() {
public void update() throws AWTException {
if (rotateAmount >= 360 || rotateAmount <= -360) rotateAmount = 0;
if (mousePress) {
locY = mouseY - diam / 2;
locX = mouseX - diam / 2;
}
if (keyUP) {
// boolean Permission=true;
// for (Wall wall : Controller.walls) {
// if(wall.intersects(getBounds(locX+5,locY+5))){
// System.out.println("4");
// Permission = false;
// break;
// }
// }
// if (Permission)
move(+5);
}
if (keyDOWN) {
boolean Permission=true;
move(-5);
}
if (keyLEFT)
rotateAmount -= 10;
rotateAmount -= 15;
if (keyRIGHT)
rotateAmount += 10;
rotateAmount += 15;
locX = Math.max(locX, 42 );
locX = Math.min(locX, GameFrame.GAME_WIDTH - diam -160);
locY = Math.max(locY, 50);
locY = Math.min(locY, GameFrame.GAME_HEIGHT - diam-160);
locX = Math.max(locX, 42);
locX = Math.min(locX, GameFrame.GAME_WIDTH - diam - 42);
locY = Math.max(locY, 70);
locY = Math.min(locY, ((Controller.row-1)/2)*50+60);
}
public void move(int px) {
......@@ -134,6 +164,16 @@ public class GameState {
}
public void checkWall() {
for (Wall wall : Controller.walls) {
if (wall.getX() == locX + 5 || wall.getY() == locY + 5) {
keyDOWN = false;
} else if (wall.getX() == locX - 5 || wall.getY() == locY - 5) {
keyUP = false;
}
}
}
public KeyListener getKeyListener() {
return keyHandler;
}
......@@ -154,6 +194,7 @@ public class GameState {
@Override
public void keyPressed(KeyEvent e) {
if (one) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
keyUP = true;
......@@ -172,9 +213,49 @@ public class GameState {
break;
}
}
if (two) {
switch (e.getKeyCode()) {
case KeyEvent.VK_W:
keyUP = true;
break;
case KeyEvent.VK_S:
keyDOWN = true;
break;
case KeyEvent.VK_A:
keyLEFT = true;
break;
case KeyEvent.VK_D:
keyRIGHT = true;
break;
case KeyEvent.VK_ESCAPE:
gameOver = true;
break;
}
}
if (three) {
switch (e.getKeyCode()) {
case KeyEvent.VK_I:
keyUP = true;
break;
case KeyEvent.VK_K:
keyDOWN = true;
break;
case KeyEvent.VK_J:
keyLEFT = true;
break;
case KeyEvent.VK_L:
keyRIGHT = true;
break;
case KeyEvent.VK_ESCAPE:
gameOver = true;
break;
}
}
}
@Override
public void keyReleased(KeyEvent e) {
if (one) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
keyUP = false;
......@@ -190,6 +271,39 @@ public class GameState {
break;
}
}
if (two) {
switch (e.getKeyCode()) {
case KeyEvent.VK_W:
keyUP = false;
break;
case KeyEvent.VK_S:
keyDOWN = false;
break;
case KeyEvent.VK_A:
keyLEFT = false;
break;
case KeyEvent.VK_D:
keyRIGHT = false;
break;
}
}
if (three) {
switch (e.getKeyCode()) {
case KeyEvent.VK_I:
keyUP = false;
break;
case KeyEvent.VK_K:
keyDOWN = false;
break;
case KeyEvent.VK_J:
keyLEFT = false;
break;
case KeyEvent.VK_L:
keyRIGHT = false;
break;
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment