Commit ffeb34ac authored by 9731301's avatar 9731301

remove some bugs

parent 5253b190
...@@ -2,45 +2,18 @@ ...@@ -2,45 +2,18 @@
<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/GameState/RewarsState.java" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/UI/GameState/RewardState.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/GameFrame.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/GameLoop.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/MyListener.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/Rendering.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/ThreadPool.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$/out/production/JTankTrouble/UI/GameFrame.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/RewarsState.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameLoop.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameFrame.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameFrame.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState$KeyHandler2.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameLoop.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameLoop.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/Rendering.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/Rendering.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/EnemyTank.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/EnemyTank.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/GameState/RewarsState.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/MyTank$KeyHandler1.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/MyTank$KeyHandler1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/MyTank$MouseHandler.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/MyTank$MouseHandler.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/MyTank.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/MyTank.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/LogIn/Main.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$2.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel$3.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/MainPanel.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Mainframe.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel$2.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/SettingPanel.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/MyListener.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Rendering.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/ThreadPool.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameFrame.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameLoop.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/EnemyTank.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/EnemyTank.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/MyTank.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/MyTank.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/TankState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/TankState.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/GameState/WallState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/WallState.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/LogIn/Game/GameFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/GameFrame.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/MainPanel.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/UI/LogIn/Game/GameLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/GameLoop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/MyListener.java" beforeDir="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/Rendering.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/ThreadPool.java" beforeDir="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" />
...@@ -163,7 +136,9 @@ ...@@ -163,7 +136,9 @@
<workItem from="1596205210217" duration="16177000" /> <workItem from="1596205210217" duration="16177000" />
<workItem from="1596226360961" duration="5478000" /> <workItem from="1596226360961" duration="5478000" />
<workItem from="1596265047938" duration="12842000" /> <workItem from="1596265047938" duration="12842000" />
<workItem from="1596295633892" duration="11516000" /> <workItem from="1596295633892" duration="19181000" />
<workItem from="1596360744874" duration="14702000" />
<workItem from="1596382833689" duration="15516000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -175,14 +150,14 @@ ...@@ -175,14 +150,14 @@
<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="1596308911976"> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596386941582">
<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="1596308911976" /> <state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596386941582" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1596307776243"> <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" /> <screen x="0" y="0" width="1536" height="824" />
</state> </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="1596307776243" /> <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="1596368712645" />
<state x="611" y="310" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.packages" timestamp="1596137635178"> <state x="611" y="310" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.packages" timestamp="1596137635178">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -191,42 +166,46 @@ ...@@ -191,42 +166,46 @@
<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="1493" height="83" key="GridCell.Tab.0.bottom" timestamp="1596308973864"> <state width="1493" height="201" key="GridCell.Tab.0.bottom" timestamp="1596399005739">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="83" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596308973864" /> <state width="1493" height="201" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<state width="1493" height="83" key="GridCell.Tab.0.center" timestamp="1596308973864"> <state width="1493" height="201" key="GridCell.Tab.0.center" timestamp="1596399005739">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="83" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596308973864" /> <state width="1493" height="201" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<state width="1493" height="83" key="GridCell.Tab.0.left" timestamp="1596308973864"> <state width="1493" height="201" key="GridCell.Tab.0.left" timestamp="1596399005739">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="83" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596308973864" /> <state width="1493" height="201" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<state width="1493" height="83" key="GridCell.Tab.0.right" timestamp="1596308973864"> <state width="1493" height="201" key="GridCell.Tab.0.right" timestamp="1596399005739">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="83" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596308973864" /> <state width="1493" height="201" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<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="1596295681139"> <state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596360806638">
<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="1596295681139" /> <state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596360806638" />
<state x="499" y="179" key="extract.method.dialog" timestamp="1596369268790">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="499" y="179" key="extract.method.dialog/0.0.1536.824@0.0.1536.824" timestamp="1596369268790" />
<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>
<state x="209" y="33" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1593723788909" /> <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="1595774253325"> <state x="511" y="41" key="refactoring.ChangeSignatureDialog" timestamp="1596369964902">
<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="1595774253325" /> <state x="511" y="41" key="refactoring.ChangeSignatureDialog/0.0.1536.824@0.0.1536.824" timestamp="1596369964902" />
<state x="426" y="187" key="run.anything.popup" timestamp="1596226569574"> <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>
<state x="426" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1596226569574" /> <state x="426" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1596369494104" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1595684580506"> <state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1595684580506">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
File added
package UI.GameState;
import UI.LogIn.Game.GameFrame;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.Random;
public class RewardState {
private WallState walls ;
public int locX , locY;
private boolean drawing = false;
private Image reward;
private boolean visible ;
int numOfReward = chooseRandomReward();
public RewardState(WallState wallState){
this.walls = wallState ;
setFirstLocationOfReward();
}
private void shield(TankState tank){
}
private void laser(TankState tank){
}
private void extraLife(TankState tank){
}
private void extraBulletDamage(TankState tank){
}
private void extraBulletDamage2(TankState tank){
}
private void setFirstLocationOfReward() {
Random randomX = new Random();
Random randomY = new Random();
while (true) {
locX = randomX.nextInt(GameFrame.GAME_WIDTH);
locY = randomY.nextInt(GameFrame.GAME_HEIGHT);
if (!walls.isWallForTank(locX , locY) && locX > 10 && locY >10 && locX < GameFrame.GAME_WIDTH-10 && locY < GameFrame.GAME_HEIGHT -10)
break;
}
}
public int chooseRandomReward(){
Random random = new Random();
int x = random.nextInt(5);
System.out.println(x);
return x;
}
private Image rewardImage = null;
public Image getRewardImage() throws IOException {
this.drawing = drawing;
if (drawing = true) {
if (rewardImage!=null) return rewardImage;
int x = numOfReward;
switch (x) {
case 0:
reward = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\shield.png"));break;
case 1:
reward = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\heart.png"));break;
case 2:
reward = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\bullet.png"));break;
case 3:
reward = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\bullets.png"));break;
case 4:
reward = ImageIO.read(new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\pics\\laser.png"));break;
}
rewardImage = reward.getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH);
return rewardImage;
}
return null;
}
public void runReward(TankState tankState){
int x = numOfReward;
switch (x) {
case 0:shield(tankState);break;
case 1:extraLife(tankState);break;
case 2:extraBulletDamage(tankState);break;
case 3:extraBulletDamage2(tankState);break;
case 4:laser(tankState);break;
}
}
public boolean isRewardForTank (int x,int y){
//BUG
return (x>this.locX-40 && x<this.locX+40 && y>this.locY-40 && y<this.locY+40 && x < GameFrame.GAME_WIDTH - 40 && y<GameFrame.GAME_HEIGHT-30);
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
}
package UI.GameState;
public class RewarsState {
}
...@@ -31,8 +31,7 @@ public class TankState { ...@@ -31,8 +31,7 @@ public class TankState {
this.walls = walls; this.walls = walls;
// Initialize the game state and all elements ... // Initialize the game state and all elements ...
// setFirstLocationOfTank(); // setFirstLocationOfTank();
locY = 120; setFirstLocationOfTank();
locX = 120;
rotate = 0; rotate = 0;
diam = 32; diam = 32;
keyUP = false; keyUP = false;
...@@ -57,10 +56,10 @@ public class TankState { ...@@ -57,10 +56,10 @@ public class TankState {
Random randomX = new Random(); Random randomX = new Random();
Random randomY = new Random(); Random randomY = new Random();
while (true) { while (true) {
locX = randomX.nextInt(GameFrame.GAME_WIDTH); locX = randomX.nextInt(GameFrame.GAME_WIDTH-20);
locY = randomY.nextInt(GameFrame.GAME_HEIGHT); locY = randomY.nextInt(GameFrame.GAME_HEIGHT-40);
System.out.println(locX +" "+locY); System.out.println(locX +" "+locY);
if (!walls.isWallForTank(locX , locY) && locX > 10 && locY >10) if (!walls.isWallForTank(locX , locY) && locX > 10 && locY >10 && locX < GameFrame.GAME_WIDTH-10 && locY < GameFrame.GAME_HEIGHT -10)
break; break;
} }
} }
......
...@@ -7,7 +7,6 @@ import java.io.IOException; ...@@ -7,7 +7,6 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.sql.Struct;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -44,19 +43,27 @@ public class WallState { ...@@ -44,19 +43,27 @@ public class WallState {
h = (frameY-30) / (numRows); //sideY h = (frameY-30) / (numRows); //sideY
w = (frameX-10) / (numColumns); //sideX w = (frameX-10) / (numColumns); //sideX
} wall1 = wall1.getScaledInstance(w,h,Image.SCALE_SMOOTH);
wall2 = wall2.getScaledInstance(w,h,Image.SCALE_SMOOTH);
blank = blank.getScaledInstance(w,h,Image.SCALE_SMOOTH);
loadWalls();
}
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
Image wall1scaled = wall1.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH);
Image wall2scaled = wall2.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH);
Image blankScaled = blank.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH);
// Draw background
walls.clear();
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
g.fillRect(0, 0, frameX, frameY); g.fillRect(0, 0, frameX, frameY);
g.setColor(Color.black); //colour of the walls g.setColor(Color.black); //colour of the walls
for (WallData d :walls){
drawWall(g,d);
}
}
public void loadWalls() {
// Draw background
walls.clear();
int x = 0; int x = 0;
int y = 0; int y = 0;
...@@ -65,15 +72,15 @@ public class WallState { ...@@ -65,15 +72,15 @@ public class WallState {
String rowChars = lines[r]; String rowChars = lines[r];
for (int c = 0; c < numColumns; c++) { for (int c = 0; c < numColumns; c++) {
if (rowChars.charAt(c) == '0') { if (rowChars.charAt(c) == '0') {
drawBlanks(g, x, y ,blankScaled); saveBlank( x, y ,3);
x += w; x += w;
} }
else if (rowChars.charAt(c) == '1') { else if (rowChars.charAt(c) == '1') {
drawAndSaveWalls(g, x, y, r , c, wall1scaled); saveWalls(x, y, r , c, 1);
x += w; x += w;
} }
else if (rowChars.charAt(c) == '2') { else if (rowChars.charAt(c) == '2') {
drawAndSaveWalls(g, x, y, r , c, wall2scaled); saveWalls( x, y, r , c, 2);
x += w; x += w;
} }
} }
...@@ -83,8 +90,8 @@ public class WallState { ...@@ -83,8 +90,8 @@ public class WallState {
private void drawAndSaveWalls(Graphics g2d,int x,int y , int r , int c ,Image image){ private void saveWalls(int x,int y , int r , int c ,int image){
WallData wall = new WallData(x , y); WallData wall = new WallData(x , y ,image,false);
if ((c<numColumns-1 && lines[r].charAt(c+1)=='1') || (c>0 && lines[r].charAt(c-1)=='1')||(c<numColumns-1 && lines[r].charAt(c+1)=='2') || (c>0 && lines[r].charAt(c-1)=='2')){ //horizontal if ((c<numColumns-1 && lines[r].charAt(c+1)=='1') || (c>0 && lines[r].charAt(c-1)=='1')||(c<numColumns-1 && lines[r].charAt(c+1)=='2') || (c>0 && lines[r].charAt(c-1)=='2')){ //horizontal
wall.setHorizontal(true); wall.setHorizontal(true);
} }
...@@ -92,11 +99,23 @@ public class WallState { ...@@ -92,11 +99,23 @@ public class WallState {
wall.setVertical(true); wall.setVertical(true);
} }
walls.add(wall); walls.add(wall);
g2d.drawImage(image , x , y , null);
} }
private void drawBlanks(Graphics g2d,int x,int y,Image image){ private void drawWall(Graphics g2d,WallData data){
g2d.drawImage(image , x , y , null); Image img;
if (data.image==1) {
img = wall1;
}else if (data.image==2){
img = wall2;
}else{
img = blank;
}
g2d.drawImage(img,data.x,data.y,null);
}
private void saveBlank(int x,int y,int image){
WallData wall = new WallData(x , y ,image,true);
walls.add(wall);
} }
public WallData getWallForBullet(int x,int y){ public WallData getWallForBullet(int x,int y){
...@@ -118,27 +137,30 @@ public class WallState { ...@@ -118,27 +137,30 @@ public class WallState {
public ArrayList<WallData> getWalls() {
return walls;
}
public class WallData { public class WallData {
private int image;
private int x,y; private int x,y;
private boolean horizontal = false; private boolean horizontal = false;
private boolean vertical = false; private boolean vertical = false;
private boolean blank;
public WallData(int x,int y){ public WallData(int x,int y,int image,boolean isBlank){
this.x = x; this.x = x;
this.y = y; this.y = y;
this.image = image;
this.blank = isBlank;
} }
public boolean isWallForTank (int x,int y){ public boolean isWallForTank (int x,int y){
//BUG //BUG
if (blank) return false;
return (x>this.x-w/2 && x<this.x+w && y>this.y-w/2 && y<this.y+h); return (x>this.x-w/2 && x<this.x+w && y>this.y-w/2 && y<this.y+h);
} }
public boolean isWallForBullet (int x,int y){ public boolean isWallForBullet (int x,int y){
//BUG //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-5 && x<this.x+w+5 && y>this.y-5 && y<this.y+h+5);
} }
......
...@@ -5,6 +5,7 @@ import UI.GameState.*; ...@@ -5,6 +5,7 @@ import UI.GameState.*;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferStrategy; import java.awt.image.BufferStrategy;
import java.io.IOException;
public class GameFrame extends JFrame { public class GameFrame extends JFrame {
...@@ -48,6 +49,8 @@ public class GameFrame extends JFrame { ...@@ -48,6 +49,8 @@ public class GameFrame extends JFrame {
try { try {
rendering.doRendering(graphics, myTank , enemyTank ); rendering.doRendering(graphics, myTank , enemyTank );
} catch (IOException e) {
e.printStackTrace();
} finally { } finally {
// Dispose the graphics // Dispose the graphics
graphics.dispose(); graphics.dispose();
......
...@@ -36,6 +36,7 @@ public class GameLoop implements Runnable { ...@@ -36,6 +36,7 @@ public class GameLoop implements Runnable {
public GameLoop(GameFrame frame) { public GameLoop(GameFrame frame) {
canvas = frame; canvas = frame;
} }
public static long startTime;
/** /**
* This must be called before the game loop starts. * This must be called before the game loop starts.
...@@ -47,6 +48,7 @@ public class GameLoop implements Runnable { ...@@ -47,6 +48,7 @@ public class GameLoop implements Runnable {
canvas.addKeyListener(myTank.getMyListener()); canvas.addKeyListener(myTank.getMyListener());
canvas.addMouseListener(myTank.getMouseListener()); canvas.addMouseListener(myTank.getMouseListener());
canvas.addMouseMotionListener(myTank.getMouseMotionListener()); canvas.addMouseMotionListener(myTank.getMouseMotionListener());
startTime = 0;
} }
@Override @Override
......
...@@ -3,6 +3,7 @@ package UI.LogIn.Game; ...@@ -3,6 +3,7 @@ package UI.LogIn.Game;
import UI.GameState.BulletState; import UI.GameState.BulletState;
import UI.GameState.EnemyTank; import UI.GameState.EnemyTank;
import UI.GameState.MyTank; import UI.GameState.MyTank;
import UI.GameState.RewardState;
import UI.LogIn.Setting; import UI.LogIn.Setting;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
...@@ -12,6 +13,7 @@ import java.awt.image.BufferedImage; ...@@ -12,6 +13,7 @@ import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
public class Rendering { public class Rendering {
...@@ -22,6 +24,7 @@ public class Rendering { ...@@ -22,6 +24,7 @@ public class Rendering {
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
int lastRender = -1; int lastRender = -1;
private ArrayList<Float> fpsHistory; private ArrayList<Float> fpsHistory;
private ArrayList<RewardState> rewards = new ArrayList<>();
private Setting setting = new Setting(); private Setting setting = new Setting();
public Rendering(){ public Rendering(){
...@@ -33,7 +36,7 @@ public class Rendering { ...@@ -33,7 +36,7 @@ public class Rendering {
*/ */
// Draw all game elements according // Draw all game elements according
// to the game 'state' using 'g2d' ... // to the game 'state' using 'g2d' ...
public void doRendering(Graphics2D g2d, MyTank myTank, EnemyTank enemyTank) { public void doRendering(Graphics2D g2d, MyTank myTank, EnemyTank enemyTank) throws IOException {
// Draw background // Draw background
myTank.getWalls().paintComponent(g2d); myTank.getWalls().paintComponent(g2d);
enemyTank.getWalls().paintComponent(g2d); enemyTank.getWalls().paintComponent(g2d);
...@@ -54,7 +57,7 @@ public class Rendering { ...@@ -54,7 +57,7 @@ public class Rendering {
// Drawing the rotated image at the required drawing locations // Drawing the rotated image at the required drawing locations
int lastX1 = 0; int lastX1 = 0;
int lastY1 = 0; int lastY1 = 0;
if (myTank.gameOver == false && enemyTank.gameOver == false) { if (!myTank.gameOver && !enemyTank.gameOver) {
g2d.drawImage(op.filter( image11, null),myTank.locX , myTank.locY , null); g2d.drawImage(op.filter( image11, null),myTank.locX , myTank.locY , null);
lastX1 = enemyTank.locX; lastX1 = enemyTank.locX;
lastY1 = enemyTank.locY; lastY1 = enemyTank.locY;
...@@ -78,7 +81,7 @@ public class Rendering { ...@@ -78,7 +81,7 @@ public class Rendering {
// Drawing the rotated image at the required drawing locations // Drawing the rotated image at the required drawing locations
int lastX2 = 0; int lastX2 = 0;
int lastY2 = 0; int lastY2 = 0;
if (myTank.gameOver == false && enemyTank.gameOver == false) { if (!myTank.gameOver && !enemyTank.gameOver) {
g2d.drawImage(op2.filter(image22, null), enemyTank.locX, enemyTank.locY, null); g2d.drawImage(op2.filter(image22, null), enemyTank.locX, enemyTank.locY, null);
lastX2 = enemyTank.locX; lastX2 = enemyTank.locX;
lastY2 = enemyTank.locY; lastY2 = enemyTank.locY;
...@@ -87,10 +90,12 @@ public class Rendering { ...@@ -87,10 +90,12 @@ public class Rendering {
g2d.drawImage(op2.filter( image22, null),lastX2 , lastY2 , null); g2d.drawImage(op2.filter( image22, null),lastX2 , lastY2 , null);
//Draw myTank bullet //Draw myTank bullet
if (myTank.getBullets().size() != 0 && myTank.gameOver == false && enemyTank.gameOver == false) { if (myTank.getBullets().size() != 0 && !myTank.gameOver && !enemyTank.gameOver) {
for (BulletState bullet : myTank.getBullets()) { Iterator<BulletState> it = myTank.getBullets().iterator();
while (it.hasNext()) {
BulletState bullet = it.next();
if (System.currentTimeMillis() - bullet.getCreateTime() > 4000) { if (System.currentTimeMillis() - bullet.getCreateTime() > 4000) {
// myTank.getBullets().remove(bullet); it.remove();
continue; continue;
} }
bullet.update(); bullet.update();
...@@ -100,10 +105,12 @@ public class Rendering { ...@@ -100,10 +105,12 @@ public class Rendering {
} }
//Draw enemy tank bullet //Draw enemy tank bullet
if (enemyTank.getBullets().size() != 0 && myTank.gameOver == false && enemyTank.gameOver == false) { if (enemyTank.getBullets().size() != 0 && !myTank.gameOver && !enemyTank.gameOver) {
for (BulletState bullet : enemyTank.getBullets()) { Iterator<BulletState> it = enemyTank.getBullets().iterator();
while (it.hasNext()) {
BulletState bullet = it.next();
if (System.currentTimeMillis() - bullet.getCreateTime() > 4000) { if (System.currentTimeMillis() - bullet.getCreateTime() > 4000) {
//enemyTank.getBullets().remove(bullet); it.remove();
continue; continue;
} }
bullet.update(); bullet.update();
...@@ -155,6 +162,35 @@ public class Rendering { ...@@ -155,6 +162,35 @@ public class Rendering {
} }
} }
//Draw rewards
boolean newReward = (System.currentTimeMillis() -GameLoop.startTime >= 7000);
if (newReward) {
GameLoop.startTime = System.currentTimeMillis();
RewardState reward = new RewardState(myTank.getWalls());
reward.setVisible(true);
rewards.add(reward);
}
if (rewards.size() != 0){
Iterator<RewardState> it = rewards.iterator();
while (it.hasNext()){
RewardState reward = it.next();
if (reward.isVisible() && reward.isRewardForTank(myTank.locX , myTank.locY)){
reward.runReward(myTank);
reward.setVisible(false);
it.remove();
}
else if (reward.isVisible() &&reward.isRewardForTank(enemyTank.locX , enemyTank.locY)){
reward.runReward(enemyTank);
reward.setVisible(false);
it.remove();
}
else if (reward.isVisible()){
g2d.drawImage(reward.getRewardImage(),reward.locX, reward.locY, null);
}
}
}
// Print FPS info // Print FPS info
long currentRender = System.currentTimeMillis(); long currentRender = System.currentTimeMillis();
......
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