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

Front #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default connect(mapStateToProps)(function TimeLineCompnent({user , dispat
axios.get("http://localhost:63342/web-api/src/api/matchHistory.php" , {withCredentials:true})
.then(function (response) {
//handle success
console.log(response.data);
setdata(response.data)

})
Expand Down
47 changes: 47 additions & 0 deletions game/pocjet-tanks.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all-main:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-android-aarch64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-android-armv6:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-linux-amd64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-linux-armv6:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-linux-armv6hf:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-linux-i586:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-macosx-universal:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-solaris-amd64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-solaris-i586:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-windows-amd64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.jogl:jogl-all:natives-windows-i586:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt-main:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-android-aarch64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-android-armv6:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-linux-amd64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-linux-armv6:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-linux-armv6hf:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-linux-i586:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-macosx-universal:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-solaris-amd64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-solaris-i586:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-windows-amd64:2.3.2" level="project" />
<orderEntry type="library" name="Maven: org.jogamp.gluegen:gluegen-rt:natives-windows-i586:2.3.2" level="project" />
<orderEntry type="library" name="Maven: com.neovisionaries:nv-websocket-client:2.10" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:4.9.0" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:2.8.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.4.10" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20201115" level="project" />
</component>
</module>
9 changes: 9 additions & 0 deletions game/src/main/java/game/ControlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ControlPanel extends JPanel {
private JLabel angleLabel;
private JLabel numOfMovesLabel;
private JButton pauseButton;
private JLabel enamyName;

private ControlPanel() {
init();
Expand Down Expand Up @@ -50,9 +51,14 @@ public void actionPerformed(ActionEvent e) {
}
});

enamyName = new JLabel();
enamyName.setBackground(Color.ORANGE);
enamyName.setFont(new Font(Font.SERIF, Font.BOLD, 30));

add(powerLabel);
add(angleLabel);
add(numOfMovesLabel);
add(enamyName);
add(pauseButton);
}

Expand All @@ -70,6 +76,9 @@ public void setAngle(int angle) {
}
}

public void setEnEmyName(String name){
enamyName.setText("Enemy Name: " + name);
}
public void setNumOfMoves(int movesLeft) {
numOfMovesLabel.setText("Moves left: " + movesLeft);
}
Expand Down
29 changes: 27 additions & 2 deletions game/src/main/java/game/GameFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import game.menu.GameMode;
import game.menu.LoadingView;
import game.menu.Menu;
import game.networking.Socket;

import javax.swing.*;
import java.awt.*;
Expand All @@ -17,6 +18,16 @@ public class GameFrame extends JFrame {
private ControlPanel controlPanel;
private JPanel gamePanel;
private GameMode gameMode;
private String userName;
private String enemyName;

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

private GameFrame() {
SwingUtilities.invokeLater(
Expand All @@ -32,6 +43,13 @@ public static GameFrame getInstance() {
return instance;
}

public static GameFrame getInstance(String username){
if (instance == null) {
instance = new GameFrame();
instance.setUserName(username);
}
return instance;
}
private void init() {
setTitle("Pocket Tanks");

Expand Down Expand Up @@ -96,7 +114,6 @@ public void changeDisplayToMenu() {

public void showLoadingSpinner() {
getContentPane().removeAll();

getContentPane().add(LoadingView.getInstance());
revalidate();
}
Expand Down Expand Up @@ -135,7 +152,6 @@ public void updateControlPanel() {

public void showResultView(String result) {
getContentPane().removeAll();

getContentPane().add(new ResultView(result));
revalidate();
}
Expand Down Expand Up @@ -168,5 +184,14 @@ public GameMode getGameMode() {
public void setGameMode(GameMode gameMode) {
this.gameMode = gameMode;
}

public void setEnemayname(String name){
controlPanel.setEnEmyName(name);
this.enemyName = name;
}

public String getEnemyName(){
return this.enemyName;
}
}

2 changes: 1 addition & 1 deletion game/src/main/java/game/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package game;

import game.game_objects.Ground;
import game.menu.LoginMenu;

import java.util.Timer;
import java.util.TimerTask;
Expand All @@ -12,7 +13,6 @@ public static void main(String[] args) {
}

public static void initializeGuestGame() {

Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
Expand Down
40 changes: 38 additions & 2 deletions game/src/main/java/game/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import game.game_objects.Tank;
import game.menu.GameMode;
import game.menu.LoadingView;
import game.networking.Site;
import game.networking.Socket;

import java.util.Timer;
Expand All @@ -35,10 +36,17 @@ public class World {
private final ImageResource arrowImageResource;

private World() {
try {
Socket.getInstance().sendMessage("USERNAME:" + Site.getUserName());
}
catch (Exception ex){

}
ground = Ground.getInstance();
int tX = 15;
int tY = 10;
leftTank = new Tank(tX, tY, "m1.png", -45);

rightTank = new Tank(tX + 65, tY, "m1.png", -135);
arrow = new GameObject();
arrowImageResource = new ImageResource("/arrow.png");
Expand Down Expand Up @@ -81,8 +89,30 @@ public void checkEndOFGame() {
new java.util.TimerTask() {
@Override
public void run() {
GameFrame.getInstance().showResultView(leftTank.getScore() > rightTank.getScore() ?
"Left tank won" : "Right tank won");
String msg ="";
boolean winner = false;
if(leftTank.getScore() > rightTank.getScore()) {
msg = leftTank.getName() + " won";
if(leftTank.getScore() == myTank.getScore())
winner = true;
}
else if(leftTank.getScore() < rightTank.getScore()) {
msg = rightTank.getName() + " won";
if(rightTank.getScore() == myTank.getScore())
winner = true;
}
else
msg = "TIE";
String result = "{\"user1\":";
result += "\"" + rightTank.getName() + "\",";
result += "\"user2\":" + "\""+leftTank.getName()+ "\",";
result += "\"score1\":" + "\""+rightTank.getScore() + "\",";
result += "\"score2\":" + "\""+leftTank.getScore() + "\"}";
System.out.println(result);
Socket.getInstance().sendMessage(msg);
if(winner)
Socket.getInstance().sendMessage(result);
GameFrame.getInstance().showResultView(msg);
}
},
5000
Expand Down Expand Up @@ -146,12 +176,18 @@ public void update() {
public void setMeLeft() {
myTank = leftTank;
enemyTank = rightTank;
rightTank.setName(GameFrame.getInstance().getEnemyName());
myTank.setName(Site.getUserName());
leftTank.setName(Site.getUserName());
isMyTurn = true;
}

public void setMeRight() {
myTank = rightTank;
myTank.setName(Site.getUserName());
rightTank.setName(Site.getUserName());
enemyTank = leftTank;
leftTank.setName(GameFrame.getInstance().getEnemyName());
isMyTurn = false;
}

Expand Down
9 changes: 9 additions & 0 deletions game/src/main/java/game/game_objects/Tank.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public class Tank extends GameObject implements BulletDestructor {
private int rightMoves;
private int power = 40;
private int score;
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Tank(float x, float y, String canonImage, float angle) {
this.canon = new GameObject(x + .5f, y - .1f, 5, 5,
Expand Down
64 changes: 64 additions & 0 deletions game/src/main/java/game/menu/LoginMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package game.menu;

import game.GameFrame;
import game.networking.Site;

import java.awt.*;
import java.awt.event.*;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.swing.*;
public class LoginMenu extends JFrame implements ActionListener {
JPanel panel;
JLabel user_label, password_label, message;
JTextField userName_text;
JPasswordField password_text;
JButton submit, cancel;
public LoginMenu() {
// Username Label
user_label = new JLabel();
user_label.setText("User Name :");
userName_text = new JTextField();
// Password Label
password_label = new JLabel();
password_label.setText("Password :");
password_text = new JPasswordField();
// Submit
submit = new JButton("SUBMIT");
panel = new JPanel(new GridLayout(3, 1));
panel.add(user_label);
panel.add(userName_text);
panel.add(password_label);
panel.add(password_text);
message = new JLabel();
panel.add(message);
panel.add(submit);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Adding the listeners to components..
submit.addActionListener(this);
add(panel, BorderLayout.CENTER);
setTitle("Please Login Here !");
setSize(450,350);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
String userName = userName_text.getText();
String password = password_text.getText();
var result = Site.login(userName, password);
try {
message.setText(result.getString("Msg"));
Site.setLoggedIn(false);
Site.setUserName("");
}
catch(Exception ex){
userName = result.getString("userName");
Site.setLoggedIn(true);
Site.setUserName(userName);
this.dispose();
}
}


}
12 changes: 9 additions & 3 deletions game/src/main/java/game/menu/MenuCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import game.GameFrame;
import game.Main;
import game.networking.Site;
import game.networking.Socket;


Expand All @@ -15,9 +16,14 @@ public static MenuCallback getInstance() {
}

public void startOnlineGame() {
GameFrame.getInstance().setGameMode(GameMode.ONLINE);
Socket.getInstance().connect();
GameFrame.getInstance().showLoadingSpinner();
if(Site.getLoggedIn()) {
GameFrame.getInstance().setGameMode(GameMode.ONLINE);
Socket.getInstance().connect();
GameFrame.getInstance().showLoadingSpinner();
}
else{
new LoginMenu();
}
}

public void startLocalGame() {
Expand Down
Loading