Commit 1383acb0 authored by 9731301's avatar 9731301

add intrance frame for game

parent 598bed0a
This diff is collapsed.
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