Commit b9d28866 authored by 9731301's avatar 9731301

complete the extra life reward

parent fd149e9b
......@@ -3,14 +3,17 @@
<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$/maps/map1.txt" beforeDir="false" afterPath="$PROJECT_DIR$/maps/map1.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/maps/map2.txt" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState$KeyHandler2.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState$KeyHandler2.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/BulletState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState$WallData.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState$WallData.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/WallState.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/RewardState.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/RewardState.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/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/LogIn/Setting.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Setting.class" 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/WallState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/WallState.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/LogIn/Game/Rendering.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/Rendering.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Setting.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -138,6 +141,10 @@
<workItem from="1596382833689" duration="23785000" />
<workItem from="1596407579858" duration="9000" />
<workItem from="1596421183096" duration="16438000" />
<workItem from="1596467735244" duration="13219000" />
<workItem from="1596534338281" duration="1337000" />
<workItem from="1596541467681" duration="2210000" />
<workItem from="1596559015419" duration="4574000" />
</task>
<servers />
</component>
......@@ -149,10 +156,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="1596434237281">
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596561526763">
<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="1596434237281" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596561526763" />
<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>
......@@ -165,30 +172,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="125" key="GridCell.Tab.0.bottom" timestamp="1596438867507">
<state width="1493" height="125" key="GridCell.Tab.0.bottom" timestamp="1596563065245">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="125" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596438867507" />
<state width="1493" height="125" key="GridCell.Tab.0.center" timestamp="1596438867506">
<state width="1493" height="125" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596563065245" />
<state width="1493" height="125" key="GridCell.Tab.0.center" timestamp="1596563065245">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="125" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596438867506" />
<state width="1493" height="125" key="GridCell.Tab.0.left" timestamp="1596438867506">
<state width="1493" height="125" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596563065245" />
<state width="1493" height="125" key="GridCell.Tab.0.left" timestamp="1596563065245">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="125" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596438867506" />
<state width="1493" height="125" key="GridCell.Tab.0.right" timestamp="1596438867507">
<state width="1493" height="125" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596563065245" />
<state width="1493" height="125" key="GridCell.Tab.0.right" timestamp="1596563065245">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="125" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596438867507" />
<state width="1493" height="125" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596563065245" />
<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="1596421188732">
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596559084807">
<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="1596421188732" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596559084807" />
<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>
......@@ -197,10 +204,10 @@
<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="1596559227093">
<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="209" y="33" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1596559227093" />
<state x="511" y="41" key="refactoring.ChangeSignatureDialog" timestamp="1596369964902">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
......@@ -25,7 +25,8 @@ public class BulletState {
createTime = System.currentTimeMillis();
}
public void update(){
public void update(TankState tank){
tank.setHasLaser(false);
if (wallState.getWallForBullet(locX , locY) != null) {
int wallX = wallState.getWallForBullet(locX, locY).getX();
int wallY = wallState.getWallForBullet(locX , locY).getY();
......@@ -46,8 +47,15 @@ public class BulletState {
}
}
}
locY += 10*Math.sin(Math.toRadians(angle) ) ;
locX += 10*Math.cos(Math.toRadians(angle) ) ;
if (tank.hasLaser() && System.currentTimeMillis() - RewardState.startLaserTime < 3000 ){
System.out.println("laser is got");
locY += 30*Math.sin(Math.toRadians(angle) ) ;
locX += 30*Math.cos(Math.toRadians(angle) ) ;
}
else {
locY += 10 * Math.sin(Math.toRadians(angle));
locX += 10 * Math.cos(Math.toRadians(angle));
}
}
......
......@@ -17,6 +17,7 @@ public class RewardState {
private boolean visible ;
int numOfReward = chooseRandomReward();
public static long startShieldTime;
public static long startLaserTime;
public RewardState(WallState wallState){
this.walls = wallState ;
......@@ -29,10 +30,14 @@ public class RewardState {
}
private void laser(TankState tank){
tank.setHasLaser(true);
startLaserTime = System.currentTimeMillis();
System.out.println("u got laser");
}
private void extraLife(TankState tank){
tank.setTankLife(tank.getTankLife() +10);
tank.setHasMoreLife(true);
}
private void extraBulletDamage(TankState tank){
......@@ -57,14 +62,12 @@ public class RewardState {
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;
......@@ -87,8 +90,7 @@ public class RewardState {
}
public void runReward(TankState tankState){
int x = numOfReward;
switch (x) {
switch (1) {
case 0:shield(tankState);break;
case 1:extraLife(tankState);break;
case 2:extraBulletDamage(tankState);break;
......
......@@ -4,6 +4,8 @@ package UI.GameState;
import UI.LogIn.Game.GameFrame;
import UI.LogIn.Game.MyListener;
import UI.LogIn.Setting;
import UI.LogIn.SettingPanel;
import java.awt.event.KeyListener;
import java.util.ArrayList;
......@@ -21,11 +23,15 @@ public class TankState {
protected boolean keyUP, keyDOWN, keyRIGHT, keyLEFT, keySpace , keyS , keyD, keyF , keyE , keyQ;
protected boolean mousePress;
protected int mouseX, mouseY;
public Setting setting= new Setting();
public int locX, locY, diam, rotate;
public boolean gameOver;
protected WallState walls;
protected ArrayList<BulletState> bullets = new ArrayList<>();
private boolean hasShield;
private boolean hasLaser;
private int tankLife ;
private boolean hasMoreLife;
public TankState(WallState walls) {
......@@ -46,6 +52,8 @@ public class TankState {
keyF = false;
keyQ = false;
tankLife = setting.getTankArmor();
mousePress = false;
mouseX = 0;
mouseY = 0;
......@@ -163,5 +171,29 @@ public class TankState {
public void setHasShield(boolean hasShield) {
this.hasShield = hasShield;
}
public boolean hasLaser() {
return hasLaser;
}
public void setHasLaser(boolean hasLaser) {
this.hasLaser = hasLaser;
}
public int getTankLife() {
return tankLife;
}
public void setTankLife(int tankLife) {
this.tankLife = tankLife;
}
public boolean isHasMoreLife() {
return hasMoreLife;
}
public void setHasMoreLife(boolean hasMoreLife) {
this.hasMoreLife = hasMoreLife;
}
}
......@@ -95,7 +95,7 @@ public class Rendering {
it.remove();
continue;
}
bullet.update();
bullet.update(myTank);
g2d.setColor(Color.GRAY);
g2d.fillOval(bullet.locX, bullet.locY, bullet.diam, bullet.diam);
}
......@@ -110,7 +110,7 @@ public class Rendering {
it.remove();
continue;
}
bullet.update();
bullet.update(enemyTank);
g2d.setColor(Color.GRAY);
g2d.fillOval(bullet.locX, bullet.locY, bullet.diam, bullet.diam);
}
......@@ -120,13 +120,13 @@ public class Rendering {
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 ){
break;
}
System.out.println(i);
allBullets.add(myTank.getBullets().get(i));
}
for (int i = enemyTank.getBullets().size() - 1 ; i >= 0 ; i -- ){
......@@ -141,26 +141,43 @@ public class Rendering {
System.out.println(e);
}
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)&& !myTank.hasShield() && System.currentTimeMillis() - bullet.getCreateTime() >100){
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) && !myTank.hasShield() && System.currentTimeMillis() - bullet.getCreateTime() > 100&& !myTank.isHasMoreLife()) {
startExploding = System.currentTimeMillis();
if (System.currentTimeMillis() - startExploding < 1000) {
g2d.drawImage(op2.filter((BufferedImage) explosionImg, null), myTank.locX, myTank.locY, null);
myTank.setTankLife(0);
myTank.gameOver = true;
}
} else 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 && myTank.isHasMoreLife()) {
System.out.println("has ");
myTank.setHasMoreLife(false);
if (myTank.getTankLife() > 100)
myTank.setTankLife(myTank.getTankLife() - 10);
}
}
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)&& !enemyTank.hasShield()&& System.currentTimeMillis() - bullet.getCreateTime() >100){
for (BulletState bullet : allBullets) {//check enemy tank
if (!enemyTank.isHasMoreLife()) {
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) {
enemyTank.setTankLife(enemyTank.getTankLife() - 100);
if (enemyTank.getTankLife() <= 0) {
startExploding = System.currentTimeMillis();
System.out.println("ex");
if (System.currentTimeMillis() - startExploding < 1000) {
g2d.drawImage(op2.filter((BufferedImage) explosionImg, null), enemyTank.locX, enemyTank.locY, null);
enemyTank.setTankLife(0);
enemyTank.gameOver = true;
}
}
}
} else 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) {
myTank.setHasMoreLife(false);
if (enemyTank.getTankLife() > 100)
enemyTank.setTankLife(enemyTank.getTankLife() - 10);
}
}
//Draw rewards
boolean newReward = (System.currentTimeMillis() -GameLoop.startTime >= 7000);
......@@ -215,8 +232,8 @@ public class Rendering {
lastRender = (int) currentRender;
// Print user guide
String userGuide
= "Use the MOUSE or ARROW KEYS to move the TANK. "
+ "Press ESCAPE to end the game.";
= "Use ARROW KEYS to move the TANK. "
+ "Press ESCAPE to end the game. you="+myTank.getTankLife()+" enemy="+enemyTank.getTankLife();
g2d.setFont(g2d.getFont().deriveFont(18.0f));
g2d.drawString(userGuide, 10, GAME_HEIGHT - 10);
// Draw GAME OVER
......
......@@ -65,4 +65,12 @@ public class Setting {
public void setTankShapePath(String tankShapePath) {
this.tankShapePath = tankShapePath;
}
public int getTankArmor() {
return tankArmor;
}
public void setTankArmor(int tankArmor) {
this.tankArmor = tankArmor;
}
}
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