Commit 14bde8a2 authored by 9731301's avatar 9731301

add some changes to login and add shield reward method

parent 2620ec94
......@@ -3,16 +3,19 @@
<component name="ChangeListManager">
<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$/out/production/JTankTrouble/Server_Client/Client.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Client.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Server.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Server.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/registeredName/registeredList" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/registeredName/registeredList" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Main.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$3.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$3.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/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/BulletState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/BulletState.java" 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/LogIn/Game/Rendering.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/Rendering.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/MainFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/MainFrame.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/Registration/InitialFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/Registration/InitialFrame.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>
<option name="SHOW_DIALOG" value="false" />
......@@ -140,6 +143,7 @@
<workItem from="1596360744874" duration="14702000" />
<workItem from="1596382833689" duration="23785000" />
<workItem from="1596407579858" duration="9000" />
<workItem from="1596421183096" duration="8850000" />
</task>
<servers />
</component>
......@@ -151,10 +155,10 @@
<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="1596402386433" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596406076120">
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596425202424">
<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="1596406076120" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596425202424" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1596368712645">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -167,30 +171,30 @@
<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="201" key="GridCell.Tab.0.bottom" timestamp="1596407509883">
<state width="1493" height="156" key="GridCell.Tab.0.bottom" timestamp="1596430140296">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state width="1493" height="201" key="GridCell.Tab.0.center" timestamp="1596407509883">
<state width="1493" height="156" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596430140296" />
<state width="1493" height="156" key="GridCell.Tab.0.center" timestamp="1596430140296">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state width="1493" height="201" key="GridCell.Tab.0.left" timestamp="1596407509883">
<state width="1493" height="156" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596430140296" />
<state width="1493" height="156" key="GridCell.Tab.0.left" timestamp="1596430140296">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state width="1493" height="201" key="GridCell.Tab.0.right" timestamp="1596407509883">
<state width="1493" height="156" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596430140296" />
<state width="1493" height="156" key="GridCell.Tab.0.right" timestamp="1596430140296">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state width="1493" height="156" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596430140296" />
<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="1596407580390">
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596421188732">
<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="1596407580390" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596421188732" />
<state x="578" y="330" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1596406077996">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
......@@ -30,7 +30,7 @@ public class BulletState {
if (walls.getWallForBullet(locX, locY).isHorizontal()) {
angle = 360 - angle;
}
if (walls.getWallForBullet(locX, locY).isVertical()) {
else if (walls.getWallForBullet(locX, locY).isVertical()) {
angle = 180 - angle;
}
}
......
......@@ -16,6 +16,7 @@ public class RewardState {
private Image reward;
private boolean visible ;
int numOfReward = chooseRandomReward();
public static long startShieldTime;
public RewardState(WallState wallState){
this.walls = wallState ;
......@@ -23,6 +24,8 @@ public class RewardState {
}
private void shield(TankState tank){
tank.setHasShield(true);
startShieldTime = System.currentTimeMillis();
}
private void laser(TankState tank){
......
......@@ -25,6 +25,7 @@ public class TankState {
public boolean gameOver;
protected WallState walls;
protected ArrayList<BulletState> bullets = new ArrayList<>();
private boolean hasShield;
public TankState(WallState walls) {
......@@ -154,5 +155,13 @@ public class TankState {
locY = Math.min(locY, GameFrame.GAME_HEIGHT - diam);
}
public boolean hasShield() {
return hasShield;
}
public void setHasShield(boolean hasShield) {
this.hasShield = hasShield;
}
}
......@@ -98,6 +98,9 @@ public class WallState {
if ((r>0 && lines[r-1].charAt(c)=='1') || (r>0 && r<numRows-1 && lines[r+1].charAt(c)=='1')||(r>0 && lines[r-1].charAt(c)=='2') || (r>0 && r<numRows-1 && lines[r+1].charAt(c)=='2')) { //vertical
wall.setVertical(true);
}
if (lines[r].charAt(c)=='2'){
wall.setDestructible(true);
}
walls.add(wall);
}
......@@ -144,6 +147,7 @@ public class WallState {
private boolean horizontal = false;
private boolean vertical = false;
private boolean blank;
private boolean destructible = false;
public WallData(int x,int y,int image,boolean isBlank){
this.x = x;
......@@ -161,7 +165,7 @@ public class WallState {
public boolean isWallForBullet (int x,int y){
//BUG
if (blank) return false;
return (x>this.x-5 && x<this.x+w+5 && y>this.y-5 && y<this.y+h+5);
return (x>this.x-10 && x<this.x+w+10 && y>this.y-10 && y<this.y+h+10);
}
public boolean isHorizontal() {
......@@ -179,5 +183,13 @@ public class WallState {
public void setVertical(boolean vertical) {
this.vertical = vertical;
}
public boolean isDestructible() {
return destructible;
}
public void setDestructible(boolean destructible) {
this.destructible = destructible;
}
}
}
package UI.LogIn.Game;
import UI.GameState.BulletState;
import UI.GameState.EnemyTank;
import UI.GameState.MyTank;
import UI.GameState.RewardState;
import UI.GameState.*;
import UI.LogIn.Setting;
import javax.imageio.ImageIO;
import java.awt.*;
......@@ -119,18 +116,21 @@ public class Rendering {
}
}
if (System.currentTimeMillis() - RewardState.startShieldTime > 15000){
myTank.setHasShield(false);
enemyTank.setHasShield(false);
}
//Draw explosion and ruin the tank
ArrayList<BulletState> allBullets = new ArrayList<>();
for (int i = myTank.getBullets().size() - 1 ; i >= 0 ; i -- ){
if (System.currentTimeMillis() - myTank.getBullets().get(i).getCreateTime() >4000){
if (System.currentTimeMillis() - myTank.getBullets().get(i).getCreateTime() >4000 ){
break;
}
System.out.println(i);
allBullets.add(myTank.getBullets().get(i));
}
for (int i = enemyTank.getBullets().size() - 1 ; i >= 0 ; i -- ){
if (System.currentTimeMillis() - enemyTank.getBullets().get(i).getCreateTime() >4000){
if (System.currentTimeMillis() - enemyTank.getBullets().get(i).getCreateTime() >4000 ){
break;
}
allBullets.add(enemyTank.getBullets().get(i));
......@@ -142,7 +142,7 @@ public class Rendering {
}
long startExploding ;
for (BulletState bullet : allBullets){//check my tank
if (bullet.locX >myTank.locX - 20 && bullet.locX <myTank.locX + 20 && bullet.locY >myTank.locY - 10&& bullet.locY <myTank.locY + 10){
if ((bullet.locX >myTank.locX - 20 && bullet.locX <myTank.locX + 20 && bullet.locY >myTank.locY - 10&& bullet.locY <myTank.locY + 10)&& !myTank.hasShield() && System.currentTimeMillis() - bullet.getCreateTime() >100){
startExploding = System.currentTimeMillis();
if (System.currentTimeMillis() - startExploding < 1000) {
g2d.drawImage(op2.filter((BufferedImage) explosionImg, null), myTank.locX, myTank.locY, null);
......@@ -151,7 +151,7 @@ public class Rendering {
}
}
for (BulletState bullet : allBullets){//check enemy tank
if (bullet.locX >enemyTank.locX - 20 && bullet.locX <enemyTank.locX + 20 && bullet.locY >enemyTank.locY - 10&& bullet.locY <enemyTank.locY + 10){
if ((bullet.locX >enemyTank.locX - 20 && bullet.locX <enemyTank.locX + 20 && bullet.locY >enemyTank.locY - 10&& bullet.locY <enemyTank.locY + 10)&& !enemyTank.hasShield()&& System.currentTimeMillis() - bullet.getCreateTime() >100){
startExploding = System.currentTimeMillis();
System.out.println("ex");
if (System.currentTimeMillis() - startExploding < 1000) {
......
......@@ -15,11 +15,7 @@ public class Main {
public static void main(String[] args) throws IOException {
// Show the game menu ...
InitialFrame initialFrame = new InitialFrame("Trouble Tank");
if (initialFrame.isClickOnPlay()) {
System.out.println(initialFrame.isClickOnPlay());
// After the player clicks 'PLAY' ...
MainFrame mainframe = new MainFrame("Trouble Tank");
}
}
}
......@@ -3,7 +3,7 @@ package UI.LogIn;
import javax.swing.*;
import java.io.IOException;
class MainFrame extends JFrame {
public class MainFrame extends JFrame {
public MainFrame(String gameName) throws IOException {
setTitle(gameName);
MainPanel mainPanel = new MainPanel();
......
package UI.Registration;
import javax.swing.*;
import java.awt.*;
public class InitialFrame extends JFrame {
......@@ -9,9 +10,16 @@ public class InitialFrame extends JFrame {
public InitialFrame(String title) {
super(title);
this.setSize(400, 500);
setVisible(true);
setResizable(true);
setLocation(100, 100);
mainInitialPanel = new InitialPanel();
add(mainInitialPanel);
mainInitialPanel.revalidate();
mainInitialPanel.repaint();
revalidate();
repaint();
isClickOnPlay = mainInitialPanel.isClickOnPlay();
}
......
......@@ -2,6 +2,7 @@ package UI.Registration;
import Server_Client.Client;
import Server_Client.Server;
import UI.LogIn.MainFrame;
import javax.swing.*;
import java.awt.*;
......@@ -9,13 +10,15 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
public class InitialPanel extends JPanel {
private boolean clickOnPlay;
public static boolean clickOnPlay;
private JTextField userName = new JTextField();
private JTextField pass = new JTextField();
public InitialPanel(){
clickOnPlay = false;
initComponents();
setPreferredSize(new Dimension(50 , 100));
setSize(50 , 100);
}
public boolean isClickOnPlay() {
......@@ -34,7 +37,7 @@ public class InitialPanel extends JPanel {
try {
Server server = new Server();
if (server.pass_userNameIsAvailable( pass.getText() , userName.getText())){
clickOnPlay = true;
MainFrame mainframe = new MainFrame("Trouble Tank");
}
else {
JOptionPane.showMessageDialog(logInBtn,"error");
......@@ -50,7 +53,12 @@ public class InitialPanel extends JPanel {
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
JFrame registration = new JFrame();
registration.setSize(200 , 200);
registration.setLocation(500 , 300);
registration.setResizable(true);
registration.add(setRegistrationPanel());
registration.revalidate();
registration.repaint();
registration.setVisible(true);
}
});
......
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