Commit a8b5f416 authored by 9731301's avatar 9731301

complete some settings and make tank changable color

parent 1383acb0
...@@ -2,35 +2,12 @@ ...@@ -2,35 +2,12 @@
<project version="4"> <project version="4">
<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 afterPath="$PROJECT_DIR$/src/UI/GameFrame.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/Main.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/MainFrame.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/SettingPanel.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/Registration/InitialFrame.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" afterDir="false" />
<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$/maps/map3.txt" beforeDir="false" afterPath="$PROJECT_DIR$/maps/map3.txt" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/GameFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameFrame.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameLoop.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameLoop.class" 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$/out/production/JTankTrouble/UI/GameState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState.class" 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$/out/production/JTankTrouble/UI/InitialFrame.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/LogIn/SettingPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/SettingPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Main$1.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Main.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainFrame.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$2.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel$3.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainInitialPanel.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/WallState$WallData.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/WallState$WallData.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/WallState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/WallState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameLoop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/InitialFrame.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/Main.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/MainFrame.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/MainInitialPanel.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/WallState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/WallState.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" />
...@@ -127,6 +104,7 @@ ...@@ -127,6 +104,7 @@
<workItem from="1595724202134" duration="7814000" /> <workItem from="1595724202134" duration="7814000" />
<workItem from="1595766182905" duration="14490000" /> <workItem from="1595766182905" duration="14490000" />
<workItem from="1595787964241" duration="8776000" /> <workItem from="1595787964241" duration="8776000" />
<workItem from="1595807570766" duration="19718000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -138,10 +116,10 @@ ...@@ -138,10 +116,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="1595580808418" /> <state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1595580808418" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1595785649965"> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1595827412140">
<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="1595785649965" /> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1595827412140" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1595774990960"> <state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1595774990960">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -150,30 +128,30 @@ ...@@ -150,30 +128,30 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="593" y="0" key="CommitChangelistDialog2/0.0.1536.824@0.0.1536.824" timestamp="1595639194593" /> <state x="593" y="0" key="CommitChangelistDialog2/0.0.1536.824@0.0.1536.824" timestamp="1595639194593" />
<state width="1045" height="101" key="GridCell.Tab.0.bottom" timestamp="1595797412239"> <state width="1493" height="168" key="GridCell.Tab.0.bottom" timestamp="1595828869703">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1045" height="101" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" /> <state width="1493" height="168" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<state width="1045" height="101" key="GridCell.Tab.0.center" timestamp="1595797412239"> <state width="1493" height="168" key="GridCell.Tab.0.center" timestamp="1595828869703">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1045" height="101" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" /> <state width="1493" height="168" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<state width="1045" height="101" key="GridCell.Tab.0.left" timestamp="1595797412239"> <state width="1493" height="168" key="GridCell.Tab.0.left" timestamp="1595828869703">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1045" height="101" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" /> <state width="1493" height="168" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<state width="1045" height="101" key="GridCell.Tab.0.right" timestamp="1595797412239"> <state width="1493" height="168" key="GridCell.Tab.0.right" timestamp="1595828869703">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1045" height="101" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" /> <state width="1493" height="168" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1595828869703" />
<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>
<state x="589" y="114" key="RollbackChangesDialog/0.0.1536.824@0.0.1536.824" timestamp="1595702094731" /> <state x="589" y="114" key="RollbackChangesDialog/0.0.1536.824@0.0.1536.824" timestamp="1595702094731" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1595788034036"> <state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1595807634287">
<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="1595788034036" /> <state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1595807634287" />
<state x="209" y="33" key="new project wizard" timestamp="1593723788909"> <state x="209" y="33" key="new project wizard" timestamp="1593723788909">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
package UI; package UI;
import UI.LogIn.Setting;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
...@@ -21,6 +23,7 @@ public class GameFrame extends JFrame { ...@@ -21,6 +23,7 @@ public class GameFrame extends JFrame {
public static final int GAME_HEIGHT = 720; // 720p game resolution public static final int GAME_HEIGHT = 720; // 720p game resolution
public static final int GAME_WIDTH = 16 * GAME_HEIGHT / 9; // wide aspect ratio public static final int GAME_WIDTH = 16 * GAME_HEIGHT / 9; // wide aspect ratio
public WallState wallState = new WallState(GAME_WIDTH ,GAME_HEIGHT); public WallState wallState = new WallState(GAME_WIDTH ,GAME_HEIGHT);
private Setting setting = new Setting();
public GameFrame(String gameName) { public GameFrame(String gameName) {
lastRender = -1; lastRender = -1;
...@@ -89,7 +92,8 @@ public class GameFrame extends JFrame { ...@@ -89,7 +92,8 @@ public class GameFrame extends JFrame {
// Draw tank; // Draw tank;
try { try {
image1 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_blue.png")); System.out.println("3"+setting.getTankShapePath());
image1 = ImageIO.read(new File(setting.getTankShapePath()));
// image2 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_sand.png")); // image2 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_sand.png"));
} catch (IOException e) { } catch (IOException e) {
System.out.println(e); System.out.println(e);
......
...@@ -52,12 +52,16 @@ public class MainPanel extends JPanel { ...@@ -52,12 +52,16 @@ public class MainPanel extends JPanel {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
super.mouseClicked(e); super.mouseClicked(e);
removeAll(); removeAll();
try {
add(setSettingPanel()); add(setSettingPanel());
} catch (IOException ex) {
ex.printStackTrace();
}
} }
}); });
} }
private JPanel setSettingPanel(){ private JPanel setSettingPanel() throws IOException {
SettingPanel settingPanel = new SettingPanel(); SettingPanel settingPanel = new SettingPanel();
return settingPanel; return settingPanel;
} }
......
...@@ -4,19 +4,67 @@ import javax.swing.*; ...@@ -4,19 +4,67 @@ import javax.swing.*;
import java.util.ArrayList; import java.util.ArrayList;
public class Setting { public class Setting {
private int playedTime; private float playedTime = 0;
private String userName; private String userName ;
private int numOfWins; private int numOfWinsSingle = 0;
private int numOfLooses; private int numOfLoosesSingle = 0;
private ImageIcon tankShape; private int numOfWinsMulti = 0;
private int tankArmor; private int numOfLoosesMulti = 0;
private int bulletDamage; private static String tankShapePath = "C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_blue.png";
private int wallWealth; private int tankArmor = 100;
private int bulletDamage ;
private int wallWealth = 100;
private ArrayList<String> urls = new ArrayList<>(); private ArrayList<String> urls = new ArrayList<>();
private ArrayList<ImageIcon> allTankColors = new ArrayList<>();
public Setting(){
public void updateSettingAfterASingleGame(float startTime , float endTime , boolean isWin ){
playedTime += endTime - startTime ;
if (isWin)numOfWinsSingle++;
else numOfLoosesSingle++;
}
public void updateSettingAfterAMultiGame(float startTime , float endTime , boolean isWin ){
playedTime += endTime - startTime ;
if (isWin)numOfWinsMulti++;
else numOfLoosesMulti++;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getNumOfWinsMulti() {
return numOfWinsMulti;
}
public int getNumOfLoosesMulti() {
return numOfLoosesMulti;
}
public float getPlayedTime() {
return playedTime;
}
public String getUserName() {
return userName;
}
public int getNumOfWinsSingle() {
return numOfWinsSingle;
} }
public int getNumOfLoosesSingle() {
return numOfLoosesSingle;
}
public String getTankShapePath() {
System.out.println(2+tankShapePath);
return tankShapePath;
}
public void setTankShapePath(String tankShapePath) {
this.tankShapePath = tankShapePath;
System.out.println(1+getTankShapePath());
}
} }
package UI.LogIn; package UI.LogIn;
import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
public class SettingPanel extends JPanel { public class SettingPanel extends JPanel {
private Setting setting = new Setting();
private String chosenTankPath ="C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_blue.png";
private Image image;
public SettingPanel() throws IOException {
setLayout(new GridLayout(1 , 2));
add(informationPanel());
add(changeableComponents());
}
private JPanel informationPanel(){
JPanel informationPanel = new JPanel(new GridLayout(6, 1));
JPanel informationPanel1 = new JPanel();
JPanel informationPanel2 = new JPanel();
JPanel informationPanel3 = new JPanel();
JPanel informationPanel4 = new JPanel();
JPanel informationPanel5 = new JPanel();
JPanel informationPanel6 = new JPanel();
JLabel username= new JLabel("username ");
JLabel userName = new JLabel(setting.getUserName());
JLabel playedTime = new JLabel("played time ");
JLabel playedTimeNum = new JLabel(setting.getPlayedTime()+"");
JLabel winNumSingle1 = new JLabel("Wins(singlePlay) ");
JLabel winNumSingle2 = new JLabel(setting.getNumOfWinsSingle()+"");
JLabel looseNumSingle1 = new JLabel("looses(singlePlay) ");
JLabel looseNumSingle2 = new JLabel(setting.getNumOfLoosesSingle()+"");
JLabel winNumMulti1 = new JLabel("Wins(multiPlay) ");
JLabel winNumMulti2 = new JLabel(setting.getNumOfWinsMulti()+"");
JLabel looseNumMulti1 = new JLabel("Looses(multiPlay ");
JLabel looseNumMulti2 = new JLabel(setting.getNumOfLoosesMulti()+"");
informationPanel1.add(username);
informationPanel1.add(userName);
informationPanel2.add(playedTime);
informationPanel2.add(playedTimeNum);
informationPanel3.add(winNumSingle1);
informationPanel3.add(winNumSingle2);
informationPanel4.add(looseNumSingle1);
informationPanel4.add(looseNumSingle2);
informationPanel5.add(winNumMulti1);
informationPanel5.add(winNumMulti2);
informationPanel6.add(looseNumMulti1);
informationPanel6.add(looseNumMulti2);
informationPanel.add(informationPanel1);
informationPanel.add(informationPanel2);
informationPanel.add(informationPanel3);
informationPanel.add(informationPanel4);
informationPanel.add(informationPanel5);
informationPanel.add(informationPanel6);
return informationPanel;
}
private JPanel changeableComponents() throws IOException {
JPanel changeableComponents = new JPanel(new GridLayout(5 , 1));
JPanel changeableComponents1 = new JPanel();
JPanel changeableComponents2 = new JPanel();
JPanel changeableComponents3 = new JPanel();
JPanel changeableComponents4 = new JPanel();
JLabel playWith= new JLabel("play with");
String[] options ={"mouth" , "keyboard"};
JComboBox comboBox = new JComboBox(options);
JLabel urls = new JLabel("URL");
String[] options2 ={""};
JComboBox comboBox2 = new JComboBox(options2);
JLabel tankColor = new JLabel("tank's color");
String[] options3 ={"blue" , "green" , "black" , "white"};
JComboBox comboBox3 = new JComboBox(options3);
image = ImageIO.read(new File(chosenTankPath));
ImageIcon imageIcon = new ImageIcon(image);
JLabel tankShape = new JLabel(imageIcon);
changeableComponents.removeAll();
changeableComponents4.add(tankShape);
comboBox3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String s = (String) comboBox3.getSelectedItem();
switch (s){
case "blue" : {chosenTankPath = "C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_blue.png";break;}
case "black" : {chosenTankPath = "C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_dark.png";break;}
case "green" : {chosenTankPath = "C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_green.png";break;}
case "white" : chosenTankPath = "C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_sand.png";
}
try {
image = ImageIO.read(new File(chosenTankPath));
} catch (IOException ex) {
ex.printStackTrace();
}
setting.setTankShapePath(chosenTankPath);
changeableComponents4.removeAll();
ImageIcon imageIcon = new ImageIcon(image);
JLabel tankShape = new JLabel(imageIcon);
changeableComponents4.add(tankShape);
}
});
JButton back = new JButton("back");
back.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
removeAll();
try {
MainPanel mainPanel = new MainPanel();
add(mainPanel);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
changeableComponents1.add(playWith);
changeableComponents1.add(comboBox);
changeableComponents2.add(urls);
changeableComponents2.add(comboBox2);
changeableComponents3.add(tankColor);
changeableComponents3.add(comboBox3);
changeableComponents.add(changeableComponents1);
changeableComponents.add(changeableComponents2);
changeableComponents.add(changeableComponents3);
changeableComponents.add(changeableComponents4);
changeableComponents.add(back);
return changeableComponents;
}
} }
...@@ -8,16 +8,6 @@ import java.awt.*; ...@@ -8,16 +8,6 @@ import java.awt.*;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.IOException; import java.io.IOException;
import Server_Client.Client;
import Server_Client.Server;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
public class InitialPanel extends JPanel { public class InitialPanel extends JPanel {
private boolean clickOnPlay; private boolean clickOnPlay;
private JTextField userName = new JTextField(); private JTextField userName = new JTextField();
......
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