Commit 81e7c71b authored by 9731301's avatar 9731301

complete client networkPlaying

parent 90315b7f
...@@ -8,10 +8,29 @@ ...@@ -8,10 +8,29 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="0b3d586d-9f0f-4ca4-b09d-03a200e1e684" name="Default Changelist" comment=""> <list default="true" id="0b3d586d-9f0f-4ca4-b09d-03a200e1e684" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/NetWorkGame/Client1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/NetWorkGame/Client1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/RewardState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/RewardState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/TankState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$5.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$5.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/NetWorkGame/NWGLoop.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/NetWorkGame/NWGLoop.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Setting.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Setting.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Server_Client/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/Client.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Server_Client/NetWorkGame/Client1.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/NetWorkGame/Client1.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Server_Client/NetWorkGame/Client1.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/NetWorkGame/Client1.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Server_Client/Server.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/Server.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Server_Client/registeredName/registeredList" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/registeredName/registeredList" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/RewardState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/RewardState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/TankState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/TankState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/WallState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/WallState.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/GameState/WallState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/WallState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/NetWorkGame/NWGLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/NetWorkGame/NWGLoop.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/LogIn/NetWorkGame/NWGLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/NetWorkGame/NWGLoop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/NetWorkGame/NWGRendering.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/NetWorkGame/NWGRendering.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -151,7 +170,11 @@ ...@@ -151,7 +170,11 @@
<workItem from="1596589736833" duration="13294000" /> <workItem from="1596589736833" duration="13294000" />
<workItem from="1596613090214" duration="8123000" /> <workItem from="1596613090214" duration="8123000" />
<workItem from="1596634146159" duration="2212000" /> <workItem from="1596634146159" duration="2212000" />
<workItem from="1596700092093" duration="11265000" /> <workItem from="1596700092093" duration="11489000" />
<workItem from="1596736621086" duration="2472000" />
<workItem from="1596753755315" duration="9970000" />
<workItem from="1596805407066" duration="11801000" />
<workItem from="1596824371588" duration="683000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -163,10 +186,10 @@ ...@@ -163,10 +186,10 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1596402386433" /> <state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1596402386433" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596713317284"> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596755270557">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596713317284" /> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596755270557" />
<state x="499" y="197" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1596591250036"> <state x="499" y="197" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1596591250036">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -187,22 +210,22 @@ ...@@ -187,22 +210,22 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="549" y="153" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1596567968810" /> <state x="549" y="153" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1596567968810" />
<state width="1493" height="145" key="GridCell.Tab.0.bottom" timestamp="1596610909897"> <state width="1493" height="266" key="GridCell.Tab.0.bottom" timestamp="1596825061812">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="145" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596610909897" /> <state width="1493" height="266" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596825061812" />
<state width="1493" height="145" key="GridCell.Tab.0.center" timestamp="1596610909897"> <state width="1493" height="266" key="GridCell.Tab.0.center" timestamp="1596825061812">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="145" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596610909897" /> <state width="1493" height="266" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596825061812" />
<state width="1493" height="145" key="GridCell.Tab.0.left" timestamp="1596610909896"> <state width="1493" height="266" key="GridCell.Tab.0.left" timestamp="1596825061812">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="145" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596610909896" /> <state width="1493" height="266" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596825061812" />
<state width="1493" height="145" key="GridCell.Tab.0.right" timestamp="1596610909897"> <state width="1493" height="266" key="GridCell.Tab.0.right" timestamp="1596825061812">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="145" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596610909897" /> <state width="1493" height="266" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596825061812" />
<state x="589" y="114" key="RollbackChangesDialog" timestamp="1595702094731"> <state x="589" y="114" key="RollbackChangesDialog" timestamp="1595702094731">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -211,10 +234,10 @@ ...@@ -211,10 +234,10 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="249" y="0" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1596591266758" /> <state x="249" y="0" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1596591266758" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596559084807"> <state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596824371717">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596559084807" /> <state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596824371717" />
<state x="578" y="330" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1596406077996"> <state x="578" y="330" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1596406077996">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -227,10 +250,10 @@ ...@@ -227,10 +250,10 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="209" y="33" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1596559227093" /> <state x="209" y="33" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1596559227093" />
<state x="511" y="41" key="refactoring.ChangeSignatureDialog" timestamp="1596620038689"> <state x="511" y="41" key="refactoring.ChangeSignatureDialog" timestamp="1596773060087">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1596620038689" /> <state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1596773060087" />
<state x="426" y="187" key="run.anything.popup" timestamp="1596369494104"> <state x="426" y="187" key="run.anything.popup" timestamp="1596369494104">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
...@@ -16,7 +16,7 @@ public class Client { ...@@ -16,7 +16,7 @@ public class Client {
public void run(){ public void run(){
System.out.println("client connected"); System.out.println("client connected");
try (Socket client = new Socket(InetAddress.getLocalHost().getHostName(),5757)){ try (Socket client = new Socket(InetAddress.getLocalHost().getHostName(),5758)){
OutputStream out = client.getOutputStream(); OutputStream out = client.getOutputStream();
PrintWriter writer = new PrintWriter(out,true); PrintWriter writer = new PrintWriter(out,true);
writer.println(user_pass); writer.println(user_pass);
......
package Server_Client.NetWorkGame; package Server_Client.NetWorkGame;
import UI.GameState.*; import UI.GameState.*;
import UI.LogIn.Game.GameFrame;
import UI.Registration.InitialFrame;
import UI.Registration.InitialPanel;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -15,69 +18,85 @@ public class Client1 { ...@@ -15,69 +18,85 @@ public class Client1 {
private int port; private int port;
private int myX, myY, myRotate; private int myX, myY, myRotate;
private ArrayList<BulletState> myBullets; private ArrayList<BulletState> myBullets;
private WallState wallState;
private String serverAns; private String serverAns;
private String[] enemyComponents; private String[] enemyComponents;
private int numOfEnemies; private int numOfEnemies;
private String wallMap; private String wallMap;
private WallState wallState;
private OutputStream out;
private InputStream in;
public Client1(String address , int port) { public Client1(String address , int port) {
this.host = address; this.host = address;
this.port = port; this.port = port;
numOfEnemies = 0; numOfEnemies = 0;
wallState = new WallState(GameFrame.GAME_WIDTH , GameFrame.GAME_HEIGHT);
} }
public void run0() throws IOException {
public void run(TankState tankState) {
try{
socket = new Socket(host,port); socket = new Socket(host,port);
OutputStream out = socket.getOutputStream(); out = socket.getOutputStream();
InputStream in = socket.getInputStream(); in = socket.getInputStream();
}
out.write("Client1".getBytes()); public void run1wall() throws IOException {
String clientText = ""; out.write(InitialPanel.userName.getText().getBytes());
byte[] buffer = new byte[2048];
int read = in.read(buffer);
wallMap = new String(buffer,0,read);
}
public void runToUpdateTank(TankState tankState) throws IOException {
try {
boolean running = true; boolean running = true;
do { // do {
String clientText = "";
clientText = myTankComponents(); clientText = myTankComponents();
running = !clientText.equalsIgnoreCase("over"); running = !clientText.equalsIgnoreCase("over");
out.write(clientText.getBytes()); out.write(clientText.getBytes());
byte[] buffer = new byte[2048]; byte[] buffer1 = new byte[2048];
int read = in.read(buffer); int read1 = in.read(buffer1);
serverAns = new String(buffer,0,read); serverAns = new String(buffer1, 0, read1);
System.out.println("- From Server : "+serverAns); System.out.println("- From Server : " + serverAns);
}while(running); // }while(running);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void close() throws IOException {
out.write("over".getBytes());
System.out.println("Client disconnected."); System.out.println("Client disconnected.");
socket.close(); socket.close();
}catch (IOException e){
System.out.println("Error : "+e.getMessage());
e.printStackTrace();
}
} }
private int getNumOfEnemies(){ private int getNumOfEnemies(){
String[] s = serverAns.split(" "); String[] s = serverAns.split(" ");
numOfEnemies = s.length/6; System.out.println(serverAns);
System.out.println(s.length+"ength");
numOfEnemies = (s.length)/6;
System.out.println(numOfEnemies+"num of enemies");
return numOfEnemies; return numOfEnemies;
} }
public ArrayList<EnemyTank> createEnemyTanks(){ public ArrayList<EnemyTank> createEnemyTanks(){
ArrayList<EnemyTank> enemyTanks = new ArrayList<>(); ArrayList<EnemyTank> enemyTanks = new ArrayList<>();
for (int i = 0 ; i < getNumOfEnemies() ; i ++){ for (int i = 0 ; i < getNumOfEnemies() ; i ++){
EnemyTank enemyTank = new EnemyTank(wallState); EnemyTank enemyTank = new EnemyTank(getWallState());
enemyTanks.add(enemyTank); enemyTanks.add(enemyTank);
} }
if (enemyTanks == null)
enemyTanks = new ArrayList<>();
return enemyTanks; return enemyTanks;
} }
public void updateEnemyComponents(ArrayList<EnemyTank> enemyTanks){//ToDO separate tanks and each tank bullets public void updateEnemyComponents(ArrayList<EnemyTank> enemyTanks){
int j = 0; int j = 0;
enemyComponents = serverAns.split(" "); enemyComponents = serverAns.split(" ");
wallMap = enemyComponents[0]; for (int i = 0 ; i < getNumOfEnemies() ; i++){
for (int i = 1 ; i < getNumOfEnemies() ; i++){
enemyTanks.get(i).locX = Integer.parseInt(enemyComponents[j]);j++; enemyTanks.get(i).locX = Integer.parseInt(enemyComponents[j]);j++;
enemyTanks.get(i).locY = Integer.parseInt(enemyComponents[j]);j++; enemyTanks.get(i).locY = Integer.parseInt(enemyComponents[j]);j++;
enemyTanks.get(i).rotate = Integer.parseInt(enemyComponents[j]);j++; enemyTanks.get(i).rotate = Integer.parseInt(enemyComponents[j]);j++;
...@@ -99,6 +118,8 @@ public class Client1 { ...@@ -99,6 +118,8 @@ public class Client1 {
private String myTankComponents(){ private String myTankComponents(){
String tankComponent , bulletComponent = ""; String tankComponent , bulletComponent = "";
tankComponent = myX +" "+ myY +" " + myRotate ; tankComponent = myX +" "+ myY +" " + myRotate ;
if (myBullets == null)
return tankComponent;
for (BulletState bullet : myBullets){ for (BulletState bullet : myBullets){
bulletComponent +=" " + bullet.locX + " " + bullet.locY ; bulletComponent +=" " + bullet.locX + " " + bullet.locY ;
} }
......
...@@ -24,7 +24,7 @@ public class Server { ...@@ -24,7 +24,7 @@ public class Server {
public void runRegistration() { public void runRegistration() {
if (serverSocket!=null) return; if (serverSocket!=null) return;
try { try {
serverSocket = new ServerSocket(5757); serverSocket = new ServerSocket(5758);
System.out.println("server connected"); System.out.println("server connected");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -90,7 +90,7 @@ public class RewardState { ...@@ -90,7 +90,7 @@ public class RewardState {
} }
public void runReward(TankState tankState){ public void runReward(TankState tankState){
switch (1) { switch (numOfReward) {
case 0:shield(tankState);break; case 0:shield(tankState);break;
case 1:extraLife(tankState);break; case 1:extraLife(tankState);break;
case 2:extraBulletDamage(tankState);break; case 2:extraBulletDamage(tankState);break;
......
...@@ -27,7 +27,7 @@ public class TankState { ...@@ -27,7 +27,7 @@ public class TankState {
public int locX, locY, diam, rotate; public int locX, locY, diam, rotate;
public boolean gameOver; public boolean gameOver;
protected WallState walls; protected WallState walls;
protected ArrayList<BulletState> bullets = new ArrayList<>(); protected ArrayList<BulletState> bullets ;
private boolean hasShield; private boolean hasShield;
private boolean hasLaser; private boolean hasLaser;
private int tankLife ; private int tankLife ;
...@@ -39,6 +39,7 @@ public class TankState { ...@@ -39,6 +39,7 @@ public class TankState {
// Initialize the game state and all elements ... // Initialize the game state and all elements ...
// setFirstLocationOfTank(); // setFirstLocationOfTank();
setFirstLocationOfTank(); setFirstLocationOfTank();
bullets = new ArrayList<>();
rotate = 0; rotate = 0;
diam = 32; diam = 32;
keyUP = false; keyUP = false;
...@@ -67,7 +68,6 @@ public class TankState { ...@@ -67,7 +68,6 @@ public class TankState {
while (true) { while (true) {
locX = randomX.nextInt(GameFrame.GAME_WIDTH-20); locX = randomX.nextInt(GameFrame.GAME_WIDTH-20);
locY = randomY.nextInt(GameFrame.GAME_HEIGHT-40); locY = randomY.nextInt(GameFrame.GAME_HEIGHT-40);
System.out.println(locX +" "+locY);
if (!walls.isWallForTank(locX , locY) && locX > 10 && locY >10 && locX < GameFrame.GAME_WIDTH-10 && locY < GameFrame.GAME_HEIGHT -10) if (!walls.isWallForTank(locX , locY) && locX > 10 && locY >10 && locX < GameFrame.GAME_WIDTH-10 && locY < GameFrame.GAME_HEIGHT -10)
break; break;
} }
...@@ -80,6 +80,8 @@ public class TankState { ...@@ -80,6 +80,8 @@ public class TankState {
} }
public ArrayList<BulletState> getBullets() { public ArrayList<BulletState> getBullets() {
if (bullets == null)
bullets = new ArrayList<BulletState>();
return bullets; return bullets;
} }
......
...@@ -13,7 +13,7 @@ import java.util.ArrayList; ...@@ -13,7 +13,7 @@ import java.util.ArrayList;
public class WallState { public class WallState {
private int frameX, frameY; private int frameX, frameY;
private String source; private String source = "C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\maps\\map3.txt";
private String[] lines; private String[] lines;
public int numRows, numColumns, w, h; public int numRows, numColumns, w, h;
private ArrayList<WallData> walls = new ArrayList<>(); private ArrayList<WallData> walls = new ArrayList<>();
...@@ -27,7 +27,7 @@ public class WallState { ...@@ -27,7 +27,7 @@ public class WallState {
frameY = GAME_HEIGHT; frameY = GAME_HEIGHT;
try { try {
source = new String(Files.readAllBytes(Paths.get("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\maps\\map3.txt")), StandardCharsets.UTF_8); source = new String(Files.readAllBytes(Paths.get(source)), StandardCharsets.UTF_8);
wall1 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\wall1.png")); wall1 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\wall1.png"));
wall2 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\wall2.png")); wall2 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\wall2.png"));
blank = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\blank.png")); blank = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\blank.png"));
......
...@@ -59,7 +59,7 @@ public class MainPanel extends JPanel { ...@@ -59,7 +59,7 @@ public class MainPanel extends JPanel {
super.mouseClicked(e); super.mouseClicked(e);
Client1 client1 = null; Client1 client1 = null;
try { try {
client1 = new Client1(InetAddress.getLocalHost().getHostName(),5000); client1 = new Client1(InetAddress.getLocalHost().getHostName(),5001);
run2(client1); run2(client1);
} catch (UnknownHostException ex) { } catch (UnknownHostException ex) {
ex.printStackTrace(); ex.printStackTrace();
...@@ -116,6 +116,11 @@ public class MainPanel extends JPanel { ...@@ -116,6 +116,11 @@ public class MainPanel extends JPanel {
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
try {
client1.run0();
} catch (IOException e) {
e.printStackTrace();
}
NWGFrame frame = new NWGFrame("Trouble Tank"); NWGFrame frame = new NWGFrame("Trouble Tank");
frame.setLocationRelativeTo(null); // put frame at center of screen frame.setLocationRelativeTo(null); // put frame at center of screen
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
...@@ -123,8 +128,14 @@ public class MainPanel extends JPanel { ...@@ -123,8 +128,14 @@ public class MainPanel extends JPanel {
frame.initBufferStrategy(); frame.initBufferStrategy();
// Create and execute the game-loop // Create and execute the game-loop
NWGLoop game = new NWGLoop(frame , client1); NWGLoop game = new NWGLoop(frame , client1);
try {
game.init(); game.init();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("222222 after init");
ThreadPool.execute(game); ThreadPool.execute(game);
System.out.println("after thearsd");
// and the game starts ... // and the game starts ...
} }
}); });
......
...@@ -45,10 +45,11 @@ import java.util.ArrayList; ...@@ -45,10 +45,11 @@ import java.util.ArrayList;
/** /**
* This must be called before the game loop starts. * This must be called before the game loop starts.
*/ */
public void init() { public void init() throws IOException {
// Perform all initializations ... // Perform all initializations ...
myTank = new MyTank(canvas.wallState); myTank = new MyTank(client1.getWallState());
client1.run(myTank); client1.run1wall();
client1.runToUpdateTank(myTank);
enemyTanks = client1.createEnemyTanks(); enemyTanks = client1.createEnemyTanks();
canvas.addKeyListener(myTank.getMyListener()); canvas.addKeyListener(myTank.getMyListener());
canvas.addMouseListener(myTank.getMouseListener()); canvas.addMouseListener(myTank.getMouseListener());
...@@ -63,6 +64,7 @@ import java.util.ArrayList; ...@@ -63,6 +64,7 @@ import java.util.ArrayList;
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
myTank.update(); myTank.update();
client1.runToUpdateTank(myTank);
client1.updateEnemyComponents(enemyTanks); client1.updateEnemyComponents(enemyTanks);
client1.updateMyTank(myTank); client1.updateMyTank(myTank);
canvas.render(myTank , enemyTanks , client1.getWallState()); canvas.render(myTank , enemyTanks , client1.getWallState());
...@@ -72,6 +74,11 @@ import java.util.ArrayList; ...@@ -72,6 +74,11 @@ import java.util.ArrayList;
} catch (InterruptedException | IOException ex) { } catch (InterruptedException | IOException ex) {
} }
} }
try {
client1.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
package UI.LogIn; package UI.LogIn;
import UI.Registration.InitialPanel;
import javax.swing.*; import javax.swing.*;
import java.util.ArrayList; import java.util.ArrayList;
public class Setting { public class Setting {
private float playedTime = 0; private float playedTime = 0;
private String userName ; private String userName = InitialPanel.userName.getText() ;
private int numOfWinsSingle = 0; private int numOfWinsSingle = 0;
private int numOfLoosesSingle = 0; private int numOfLoosesSingle = 0;
private int numOfWinsMulti = 0; private int numOfWinsMulti = 0;
...@@ -29,9 +31,6 @@ public class Setting { ...@@ -29,9 +31,6 @@ public class Setting {
else numOfLoosesMulti++; else numOfLoosesMulti++;
} }
public void setUserName(String userName) {
this.userName = userName;
}
public int getNumOfWinsMulti() { public int getNumOfWinsMulti() {
return numOfWinsMulti; return numOfWinsMulti;
......
...@@ -11,7 +11,7 @@ import java.awt.event.MouseEvent; ...@@ -11,7 +11,7 @@ import java.awt.event.MouseEvent;
import java.io.IOException; import java.io.IOException;
public class InitialPanel extends JPanel { public class InitialPanel extends JPanel {
public static boolean clickOnPlay; public static boolean clickOnPlay;
private JTextField userName = new JTextField(); public static JTextField userName = new JTextField();
private JTextField pass = new JTextField(); private JTextField pass = new JTextField();
public InitialPanel(){ public InitialPanel(){
......
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