Commit 1383acb0 authored by 9731301's avatar 9731301

add intrance frame for game

parent 598bed0a
......@@ -2,12 +2,34 @@
<project version="4">
<component name="ChangeListManager">
<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$/out/production/JTankTrouble/UI/MainFrame.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MainFrame.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maps/map3.txt" beforeDir="false" afterPath="$PROJECT_DIR$/maps/map3.txt" 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$/out/production/JTankTrouble/UI/GameState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/InitialFrame.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Main$1.class" beforeDir="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/MainFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/MainFrame.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>
<option name="SHOW_DIALOG" value="false" />
......@@ -42,7 +64,20 @@
<recent name="UI" />
</key>
</component>
<component name="RunManager">
<component name="RunManager" selected="Application.Main (1)">
<configuration name="Main (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="UI.LogIn.Main" />
<module name="JTankTrouble" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="UI.LogIn.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="UI.Main" />
<module name="JTankTrouble" />
......@@ -58,6 +93,7 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Main (1)" />
<item itemvalue="Application.Main" />
</list>
</recent_temporary>
......@@ -88,7 +124,9 @@
<workItem from="1595631601242" duration="7682000" />
<workItem from="1595671067716" duration="13031000" />
<workItem from="1595695509035" duration="23884000" />
<workItem from="1595724202134" duration="6601000" />
<workItem from="1595724202134" duration="7814000" />
<workItem from="1595766182905" duration="14490000" />
<workItem from="1595787964241" duration="8776000" />
</task>
<servers />
</component>
......@@ -100,54 +138,54 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<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="1595424907485">
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1595785649965">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1595424907485" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1593430104059">
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1595785649965" />
<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" />
</state>
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes/0.0.1536.824@0.0.1536.824" timestamp="1593430104059" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes/0.0.1536.824@0.0.1536.824" timestamp="1595774990960" />
<state x="593" y="0" key="CommitChangelistDialog2" timestamp="1595639194593">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="593" y="0" key="CommitChangelistDialog2/0.0.1536.824@0.0.1536.824" timestamp="1595639194593" />
<state width="1493" height="118" key="GridCell.Tab.0.bottom" timestamp="1595730990190">
<state width="1045" height="101" key="GridCell.Tab.0.bottom" timestamp="1595797412239">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="118" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1595730990190" />
<state width="1493" height="118" key="GridCell.Tab.0.center" timestamp="1595730990190">
<state width="1045" height="101" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" />
<state width="1045" height="101" key="GridCell.Tab.0.center" timestamp="1595797412239">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="118" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1595730990190" />
<state width="1493" height="118" key="GridCell.Tab.0.left" timestamp="1595730990190">
<state width="1045" height="101" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" />
<state width="1045" height="101" key="GridCell.Tab.0.left" timestamp="1595797412239">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="118" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1595730990190" />
<state width="1493" height="118" key="GridCell.Tab.0.right" timestamp="1595730990190">
<state width="1045" height="101" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" />
<state width="1045" height="101" key="GridCell.Tab.0.right" timestamp="1595797412239">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="118" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1595730990190" />
<state width="1045" height="101" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1595797412239" />
<state x="589" y="114" key="RollbackChangesDialog" timestamp="1595702094731">
<screen x="0" y="0" width="1536" height="824" />
</state>
<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="1595724201885">
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1595788034036">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1595724201885" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1595788034036" />
<state x="209" y="33" key="new project wizard" timestamp="1593723788909">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="209" y="33" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1593723788909" />
<state x="511" y="41" key="refactoring.ChangeSignatureDialog" timestamp="1595279815795">
<state x="511" y="41" key="refactoring.ChangeSignatureDialog" timestamp="1595774253325">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1595279815795" />
<state x="426" y="187" key="run.anything.popup" timestamp="1595636897284">
<state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1595774253325" />
<state x="426" y="187" key="run.anything.popup" timestamp="1595788998130">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="426" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1595636897284" />
<state x="426" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1595788998130" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1595684580506">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
1111111
1001001
1001011
1001001
1010001
1001011
1001001
1111111
\ No newline at end of file
111111111
100100001
100100011
101100001
101000001
101101111
100100001
111111111
\ No newline at end of file
......@@ -11,7 +11,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class MainFrame extends JFrame {
public class GameFrame extends JFrame {
private long lastRender;
private BufferStrategy bufferStrategy;
......@@ -22,7 +22,7 @@ public class MainFrame extends JFrame {
public static final int GAME_WIDTH = 16 * GAME_HEIGHT / 9; // wide aspect ratio
public WallState wallState = new WallState(GAME_WIDTH ,GAME_HEIGHT);
public MainFrame(String gameName) {
public GameFrame(String gameName) {
lastRender = -1;
setTitle(gameName);
pack();
......@@ -85,18 +85,12 @@ public class MainFrame extends JFrame {
// to the game 'state' using 'g2d' ...
private void doRendering(Graphics2D g2d, GameState state) {
// Draw background
// g2d.setColor(Color.GREEN);
// g2d.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
wallState.paintComponent(g2d);
// Draw tank;
try {
image1 = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\tank_blue.png"));
// 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) {
System.out.println(e);
}
......@@ -111,7 +105,7 @@ public class MainFrame extends JFrame {
// Drawing the rotated image at the required drawing locations
g2d.drawImage(op.filter( image11, null),state.locX , state.locY , null);
// g2d.drawImage(image2 , state.locX+30 , state.locY+30 , null);
// g2d.drawImage(image2 , state.locX+30 , state.locY+30 , null);
// Print FPS info
......
......@@ -24,10 +24,10 @@ public class GameLoop implements Runnable {
*/
public static final int FPS = 30;
private MainFrame canvas;
private GameFrame canvas;
private GameState state;
public GameLoop(MainFrame frame) {
public GameLoop(GameFrame frame) {
canvas = frame;
}
......
......@@ -112,9 +112,9 @@ public class GameState {
}
locX = Math.max(locX, 0);
locX = Math.min(locX, MainFrame.GAME_WIDTH - diam);
locX = Math.min(locX, GameFrame.GAME_WIDTH - diam);
locY = Math.max(locY, 0);
locY = Math.min(locY, MainFrame.GAME_HEIGHT - diam);
locY = Math.min(locY, GameFrame.GAME_HEIGHT - diam);
}
......
package UI.LogIn;
/*** In The Name of Allah ***/
import java.io.IOException;
/**
* Program start.
*
* @author Seyed Mohammad Ghaffarian
*/
public class Main {
public static void main(String[] args) throws IOException {
// Show the game menu ...
// InitialFrame initialFrame = new InitialFrame("Trouble Tank");
// if (initialFrame.isClickOnPlay()) {
// After the player clicks 'PLAY' ...
Mainframe mainframe = new Mainframe("Trouble Tank");
// }
}
}
package UI.LogIn;
import javax.swing.*;
import java.io.IOException;
class Mainframe extends JFrame {
public Mainframe(String gameName) throws IOException {
setTitle(gameName);
MainPanel mainPanel = new MainPanel();
add(mainPanel);
pack();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(720, 720);
setVisible(true);
setResizable(true);
setLocation(200,100);
}
}
\ No newline at end of file
package UI.LogIn;
import UI.GameFrame;
import UI.GameLoop;
import UI.ThreadPool;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
public class MainPanel extends JPanel {
private Image image;
public MainPanel() throws IOException {
image = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\index.png"));
initComponents();
}
private void initComponents(){
setLayout(new BorderLayout());
ImageIcon imageIcon = new ImageIcon(image);
JButton label = new JButton();
label.setIcon(imageIcon);
add(label , BorderLayout.CENTER);
JButton multiPlaysBtn = new JButton("MultiPlayers");
multiPlaysBtn.setPreferredSize(new Dimension(200 ,250));
JButton settingBtn = new JButton("Setting");
JButton singlePlayBtn = new JButton("SinglePlayer");
JButton leaveAccountBtn = new JButton("Leave current account");
JPanel jPanel = new JPanel(new GridLayout(1 ,4));
jPanel.add(singlePlayBtn);
jPanel.add(multiPlaysBtn);
jPanel.add(settingBtn);
jPanel.add(leaveAccountBtn);
add(jPanel , BorderLayout.SOUTH);
singlePlayBtn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
run();
}
});
settingBtn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
removeAll();
add(setSettingPanel());
}
});
}
private JPanel setSettingPanel(){
SettingPanel settingPanel = new SettingPanel();
return settingPanel;
}
private void run() {
// Initialize the global thread-pool
ThreadPool.init();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
GameFrame frame = new GameFrame("Trouble Tank");
frame.setLocationRelativeTo(null); // put frame at center of screen
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
frame.initBufferStrategy();
// Create and execute the game-loop
GameLoop game = new GameLoop(frame);
game.init();
ThreadPool.execute(game);
// and the game starts ...
}
});
}
}
package UI.LogIn;
import javax.swing.*;
import java.util.ArrayList;
public class Setting {
private int playedTime;
private String userName;
private int numOfWins;
private int numOfLooses;
private ImageIcon tankShape;
private int tankArmor;
private int bulletDamage;
private int wallWealth;
private ArrayList<String> urls = new ArrayList<>();
private ArrayList<ImageIcon> allTankColors = new ArrayList<>();
public Setting(){
}
}
package UI.LogIn;
import javax.swing.*;
public class SettingPanel extends JPanel {
}
package UI;
/*** In The Name of Allah ***/
import java.awt.EventQueue;
import javax.swing.JFrame;
/**
* Program start.
*
* @author Seyed Mohammad Ghaffarian
*/
public class Main {
public static void main(String[] args) {
// Initialize the global thread-pool
ThreadPool.init();
// Show the game menu ...
// InitialFrame initialFrame = new InitialFrame("Trouble Tank");
System.out.println("yes");
// if (initialFrame.isClickOnPlay()) {
// After the player clicks 'PLAY' ...
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainFrame frame = new MainFrame("Trouble Tank");
frame.setLocationRelativeTo(null); // put frame at center of screen
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
frame.initBufferStrategy();
// Create and execute the game-loop
GameLoop game = new GameLoop(frame);
game.init();
ThreadPool.execute(game);
// and the game starts ...
}
});
// }
}
}
package UI;
package UI.Registration;
import javax.swing.*;
public class InitialFrame extends JFrame {
private MainInitialPanel mainInitialPanel;
private InitialPanel mainInitialPanel;
private boolean isClickOnPlay = false;
public InitialFrame(String title) {
super(title);
setVisible(true);
mainInitialPanel = new MainInitialPanel();
mainInitialPanel = new InitialPanel();
add(mainInitialPanel);
isClickOnPlay = mainInitialPanel.isClickOnPlay();
}
......
package UI;
package UI.Registration;
import Server_Client.Client;
import Server_Client.Server;
......@@ -9,12 +9,21 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
public class MainInitialPanel extends JPanel{
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 {
private boolean clickOnPlay;
private JTextField userName = new JTextField();
private JTextField pass = new JTextField();
public MainInitialPanel(){
public InitialPanel(){
clickOnPlay = false;
initComponents();
}
......
......@@ -23,7 +23,7 @@ public class WallState {
frameY = GAME_HEIGHT;
try {
source = new String(Files.readAllBytes(Paths.get("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\maps\\map1.txt")), StandardCharsets.UTF_8);
source = new String(Files.readAllBytes(Paths.get("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\maps\\map3.txt")), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
......@@ -36,12 +36,6 @@ public class WallState {
w = (frameX-10) / (numColumns); //sideX
}
public boolean isWall(int x,int y){
for(WallData d : walls){
if (d.isWall(x,y)) return true;
}
return false;
}
public void paintComponent(Graphics g) {
// Draw background
......@@ -112,11 +106,20 @@ public class WallState {
g.fillRect(0,frameY-start,frameX,start);
}
public boolean isWall(int x,int y){
for(WallData d : walls){
if (d.isWall(x,y)) return true;
}
return false;
}
private void draw(Graphics g,int x,int y,int w,int h){
walls.add(new WallData(x,y,w,h));
g.fillRect(x,y,w,h);
}
public class WallData {
int x,y,w,h;
......@@ -129,7 +132,7 @@ public class WallState {
public boolean isWall (int x,int y){
//BUG
return (x>=this.x && x<=this.x+w && y>=this.y && y<this.y+h);
return (x>this.x && x<this.x+w && y>this.y && y<this.y+h);
}
}
}
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