Commit 0f8b4477 authored by nargessalehi98's avatar nargessalehi98

Merge remote-tracking branch 'origin/master'

parents 77f5bab3 2b3e1890
......@@ -8,6 +8,7 @@ import java.io.File;
import java.io.FileWriter;
public class CreateNewGameFrame extends JFrame {
private JPanel settingPanel;
private JPanel gameDetailsPanel;
private JPanel optionPanel;
......@@ -49,7 +50,7 @@ public class CreateNewGameFrame extends JFrame {
destructibleWallSlider = new JSlider(10, 100, 20);
sliderAndIcon(tankHealthSlider, "pictures/tankHealth.png");
sliderAndIcon(shotDamageSlider, "pictures/shotDamage.png");
sliderAndIcon(destructibleWallSlider, "pictures/DestructibleWall.png");
sliderAndIcon(destructibleWallSlider,"pictures/DestructibleWall.png");
add(settingPanel);
settingPanel.add(gameDetailsPanel, BorderLayout.CENTER);
......@@ -136,6 +137,4 @@ public class CreateNewGameFrame extends JFrame {
ex.printStackTrace();
}
}
}
......@@ -71,7 +71,8 @@ public class GameLoop implements Runnable {
long delay = (1000 / FPS) - (System.currentTimeMillis() - start);
if (delay > 0)
Thread.sleep(delay);
} catch (InterruptedException | IOException | AWTException ex) {
} catch (Exception ee) {
ee.printStackTrace();
}
}
try {
......
......@@ -32,10 +32,6 @@ public class GameState {
private boolean one = false;
private boolean two = false;
private boolean three = false;
private int step = 0;
boolean PermissionUp = true;
boolean PermissionDown = true;
boolean check = true;
public GameState(int num) {
......@@ -84,64 +80,11 @@ public class GameState {
if (keyUP) {
PermissionUp = true;
for (Wall wall : Controller.walls) {
if (wall.getWidth() == 5 && wall.getHeight() == 50) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50)))) {
//&&
// ((rotateAmount == 0 && locX < wall.getX()) || ((rotateAmount == 180 || rotateAmount == -180) && locX > wall.getX()))
PermissionUp = false;
break;
}
}
if (wall.getWidth() == 50 && wall.getHeight() == 5) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5)))) {
// &&
// (((rotateAmount == +90 || rotateAmount == -270) && locY < wall.getY()) || (((rotateAmount == -90 || rotateAmount == -270) && locY > wall.getY())))
PermissionUp = false;
break;
}
}
}
if (PermissionUp)
move(+5);
for (Wall wall : Controller.walls)
if (!PermissionDown && (!(getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5))) ||
!(getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50))))) {
move(+5);
break;
}
move(+5);
}
if (keyDOWN) {
PermissionDown = true;
for (Wall wall : Controller.walls) {
if (wall.getWidth() == 5 && wall.getHeight() == 50) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50)))) {
//&&
// ((((rotateAmount == 0) || locX >= wall.getX())) || (((rotateAmount == -180 || rotateAmount == 180) && locX <= wall.getX())))
PermissionDown = false;
break;
}
}
if (wall.getWidth() == 50 && wall.getHeight() == 5) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5)))) {
// &&
// (((rotateAmount == -90 || rotateAmount == 270) && locY<wall.getY()))|| (((rotateAmount==90||rotateAmount==-270)&& locY>wall.getY()))
PermissionDown = false;
break;
}
}
}
if (PermissionDown)
move(-5);
for (Wall wall : Controller.walls)
if (!PermissionUp && (!(getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5))) ||
!(getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50))))) {
move(-5);
break;
}
// }
move(-5);
}
......@@ -158,9 +101,93 @@ public class GameState {
locY = Math.min(locY, 50 + ((Controller.row - 1) / 2) * 50 + (((Controller.row - 1) / 2) + 1) * 5 - 25);
}
public Wall verticalWallCollision() {
for (Wall wall : Controller.walls) {
if (wall.getWidth() == 5 && wall.getHeight() == 50) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50)))) {
return wall;
}
}
}
return null;
}
public Wall horizontalWallCollision() {
for (Wall wall : Controller.walls) {
if (wall.getWidth() == 50 && wall.getHeight() == 5) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5)))) {
return wall;
}
}
}
return null;
}
public boolean isMoveAllowed(int px) {
if (verticalWallCollision() != null) {
if (verticalWallCollision().getX() > locX && px > 0) {
if ((rotateAmount <= 90 && rotateAmount >= -90) || (rotateAmount <= -270 && rotateAmount > -360) || (rotateAmount >= 270 && rotateAmount < 360)) {
return false;
} else return true;
}
if (verticalWallCollision().getX() < locX && px < 0) {
if ((rotateAmount <= 90 && rotateAmount >= -90) || (rotateAmount <= -270 && rotateAmount > -360) || (rotateAmount >= 270 && rotateAmount < 360)) {
return false;
} else return true;
}
if (verticalWallCollision().getX() > locX && px < 0) {
if ((rotateAmount >= 90 && rotateAmount <= 270) || (rotateAmount <= -90 && rotateAmount >= -270)) {
return false;
} else return true;
}
if (verticalWallCollision().getX() < locX && px > 0) {
if ((rotateAmount >= 90 || rotateAmount <= 270) || (rotateAmount <= -90 && rotateAmount >= -270)) {
return false;
} else return true;
}
}
if (horizontalWallCollision() != null) {
if (horizontalWallCollision().getY() > locY && px > 0) {
if ((rotateAmount <= 180 && rotateAmount >= 0) || (rotateAmount <= -180 && rotateAmount > -360)) {
System.out.println("1");
return false;
} else return true;
}
if (horizontalWallCollision().getY() < locY && px < 0) {
if ((rotateAmount <= 180 && rotateAmount >= 0) || (rotateAmount <= -180 && rotateAmount > -360)) {
System.out.println("2");
return false;
} else return true;
}
if (horizontalWallCollision().getY() < locY && px > 0) {
if ((rotateAmount >= -180 && rotateAmount <= 0) || (rotateAmount >= 180 && rotateAmount < 360)) {
System.out.println("3");
return false;
} else return true;
}
if (horizontalWallCollision().getY() > locY && px < 0) {
if ((rotateAmount >= -180 && rotateAmount <= 0) || (rotateAmount >= 180 && rotateAmount < 360)) {
System.out.println("4");
return false;
} else return true;
}
}
return true;
}
public void move(int px) {
double d;
if (!isMoveAllowed(px)) px = 0;
if (rotateAmount == 0) locX += px;
if (rotateAmount == 90 || rotateAmount == -270) locY += px;
if (rotateAmount == -90 || rotateAmount == 270) locY -= px;
......@@ -214,15 +241,6 @@ 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;
......
......@@ -35,20 +35,6 @@ public class LoginFrame extends JFrame {
}
public void initInformationPanel() {
informationPanel = new JPanel();
informationPanel.setOpaque(true);
informationPanel.setBorder(new LineBorder(Color.DARK_GRAY));
informationPanel.setLayout(new GridLayout(3, 1));
informationPanel.add(userName);
informationPanel.add(passwordField);
informationPanel.add(remindMe);
add(informationPanel, BorderLayout.CENTER);
}
public void initLoginFrame() {
tankPhoto = new ImageIcon("gifFiles/gif.gif");
......@@ -81,6 +67,20 @@ public class LoginFrame extends JFrame {
}
public void initInformationPanel() {
informationPanel = new JPanel();
informationPanel.setOpaque(true);
informationPanel.setBorder(new LineBorder(Color.DARK_GRAY));
informationPanel.setLayout(new GridLayout(3, 1));
informationPanel.add(userName);
informationPanel.add(passwordField);
informationPanel.add(remindMe);
add(informationPanel, BorderLayout.CENTER);
}
public void initRemindMe() {
File accounts = new File("Accounts.txt");
try (Scanner scanner = new Scanner(new FileReader(accounts))) {
......@@ -99,6 +99,28 @@ public class LoginFrame extends JFrame {
}
}
class SignUpAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
File accounts = new File("Accounts.txt");
try (Scanner scanner = new Scanner(new FileReader(accounts))) {
String account = "";
while (scanner.hasNextLine()) {
account = scanner.nextLine() + "\n";
}
if (account.contains(userName.getText())) {
JFrame userFound = new JFrame();
JOptionPane.showMessageDialog(userFound, "This User already exists ! ", "", JOptionPane.ERROR_MESSAGE);
} else {
signUpUser(accounts);
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
public void signUpUser(File accounts) {
try (FileWriter fileWriter = new FileWriter(accounts, true)) {
fileWriter.write(userName.getText() + " " + passwordField.getText() + " " + remindMe.isSelected() + " 0 0 0 0 0 " + "\n");
......@@ -146,27 +168,4 @@ public class LoginFrame extends JFrame {
}
}
class SignUpAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
File accounts = new File("Accounts.txt");
try (Scanner scanner = new Scanner(new FileReader(accounts))) {
String account = "";
while (scanner.hasNextLine()) {
account = scanner.nextLine() + "\n";
}
if (account.contains(userName.getText())) {
JFrame userFound = new JFrame();
JOptionPane.showMessageDialog(userFound, "This User already exists ! ", "", JOptionPane.ERROR_MESSAGE);
} else {
signUpUser(accounts);
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
}
......@@ -106,8 +106,7 @@ public class MainFrame extends JFrame {
}
}
class OfflineModeAction implements ActionListener {
class OfflineModeAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
......@@ -115,7 +114,7 @@ public class MainFrame extends JFrame {
JFrame dialogFrame = new JFrame("Change settings ");
dialogFrame.setResizable(false);
dialogFrame.setLayout(new FlowLayout());
dialogFrame.setBounds(700, 450, 300, 85);
dialogFrame.setBounds(700,450,300,85);
JLabel settingLabel = new JLabel("Do you want to play with current setting ?");
dialogFrame.add(settingLabel);
......@@ -143,10 +142,8 @@ public class MainFrame extends JFrame {
dialogFrame.setVisible(true);
}
}
class OnlineModeAction implements ActionListener {
class OnlineModeAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
......@@ -155,4 +152,4 @@ public class MainFrame extends JFrame {
}
}
\ No newline at end of file
}
......@@ -8,6 +8,7 @@ import java.io.FileReader;
import java.util.Scanner;
public class OnlineModeFrame extends JFrame {
private JComboBox serverBox;
private JPanel serverChoosePanel;
private JPanel gamesPanel;
......@@ -98,6 +99,4 @@ public class OnlineModeFrame extends JFrame {
new CreateNewGameFrame("Make A New Game");
}
}
}
......@@ -29,6 +29,7 @@ public class SettingFrame extends JFrame {
setVisible(true);
}
public void initUserInformationPanel() {
userInformationPanel = new JPanel();
......@@ -68,7 +69,9 @@ public class SettingFrame extends JFrame {
add(userInformationPanel);
}
public void textAndLabel(String pngFile, String textField) {
ImageIcon icon = new ImageIcon(pngFile);
......@@ -84,6 +87,7 @@ public class SettingFrame extends JFrame {
userInformationPanel.add(text);
}
public void initSettingPanel() {
settingPanel = new JPanel();
......@@ -104,6 +108,7 @@ public class SettingFrame extends JFrame {
settingPanel.add(gameDetailsPanel, BorderLayout.NORTH);
settingPanel.add(serverPanel, BorderLayout.CENTER);
}
public void initServerPanel() {
JComboBox serverBox = new JComboBox();
serverBox.addItem("Server 1");
......@@ -138,8 +143,4 @@ public class SettingFrame extends JFrame {
gameDetailsPanel.add(slider);
}
}
public class temp {
// if(Math.abs((locX+5-wall.getX()))<18 && Math.abs((locY-wall.getY()))<18){
// System.out.println("4");
// Permission = false;
// break;
// }
//if (locX + 5 < wall.getX() && locY + 5 < wall.getY() && locX - 5 < wall.getX() && locY - 5 < wall.getY())
// {
// System.out.println("1111");
// if (Math.abs(locY - wall.getY()) <= 25 && Math.abs(wall.getX() - locX) <= 25 && (rotateAmount == 90 || rotateAmount == -270)) {
// System.out.println("1");
// Permission = false;
// break;
// }
// if (Math.abs((locX - wall.getX())) <= 25 && Math.abs((locY-wall.getY()))<=25 && rotateAmount == 0) {
// System.out.println("2");
// Permission = false;
// break;
// }
// if ( Math.abs(locX - wall.getX()) <=30 && Math.abs(locY-wall.getY())<=75 && (rotateAmount == -180 || rotateAmount == 180)) {
// System.out.println("3");
// Permission = false;
// break;
// }
// if((rotateAmount==-270||rotateAmount==90)&& Math.abs((locX-wall.getX()))<=25 && Math.abs(locY-wall.getY())<=25){
// System.out.println("4");
// Permission = false;
// break;
// }
// }
// if (!robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY)) ||
// robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY))) {
// //System.out.println((locX + 5, locY + 5));
// // System.out.println(robot.getPixelColor(locX , locY ));
// System.out.println("4");
// Permission = false;
// break;
// }
// System.out.println("na");
// if(Controller.g2d.hit( wall, (Shape) Controller.taken,false)){
// System.out.println("4");
// Permission = false;
// break;
// }
// boolean Permission = true;
// for (Wall wall : Controller.walls) {
// if ((wall.getX() == locX + 5 || wall.getX() == locX + 5 + 5)) {
// Permission = false;
// break;
// }
// }
// Robot robot = new Robot();
// if (!robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY)) ||
// robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY))) {
// System.out.println("4");
// Permission = 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