Commit 1f8d4799 authored by nargessalehi98's avatar nargessalehi98

update applyPrize method.

parent 1f14476f
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/**
* this class keeps tank info
* @author narges salehi & sepehr tavakoli
* @version 1.1
* @since July 21 2020
*/
public class Tank {
//x of tank
int x;
//y of tank
int y;
//rotate amount of tank
double rotateAmount;
//icon of tank
BufferedImage icon;
Bullet bullet;
GameState state;
boolean alive;
//keep current prize
String prize;
//keep current health value
int Health;
//Below fields check expiration of each prize
int shieldCounter;
int laserCounter;
boolean bulletEffect;
boolean laser;
boolean bullet2;
boolean bullet3;
int shieldCounter;
int laserCounter;
//check if tank is alive or not
boolean alive;
int prizeExpiration=0;
/**
* create a new tank with given value
* @param path of icon of tank
* @param x of tank
* @param y of tank
* @param rotateAmount of tank
*/
public Tank(String path, int x, int y, double rotateAmount) {
//set default value
prize = "empty";
Health = Controller.tankHealth;
//set Counter of expiration time of each prize
shieldCounter = 0;
laserCounter = 0;
try {
......@@ -38,46 +64,77 @@ public class Tank {
}
/**
* @return icon of tank
*/
public BufferedImage getIcon() {
return icon;
}
/**
* @return x of tank
*/
public int getX() {
return x;
}
/**
* @return y of tank
*/
public int getY() {
return y;
}
/**
* @return state of tank - GameState
*/
public GameState getState() {
return state;
}
/**
* @return Health value of tank
*/
public int getHealth() {
return Health;
}
/**
*
* @param healthDamage to revalue health of tank
*/
public void setHealth(int healthDamage) {
Health -= healthDamage;
if (Health <= 0) Health = 0;
}
public String getPrize() {
/**
* @return current prize
*/
public String getPrize() throws IOException {
return prize;
}
/**
* @param prize to set for tank
*/
public void setPrize(String prize) {
this.prize = prize;
}
/**
* method apply each prize features
*/
public void applyPrize() {
//check if tank has a prize now
if (!prize.equals("empty")) {
if (prize.equals("life")) {
Health += 10;
}
if (Health > 100) {
Health = 100;
if (Health > 100) {
Health = 100;
}
prize="empty";
}
if (prize.equals("shield")) {
if (shieldCounter < 150) {
......@@ -86,6 +143,7 @@ public class Tank {
} else {
shieldCounter = 160;
bulletEffect = false;
prize="empty";
}
}
if (prize.equals("bullet2")) {
......@@ -104,9 +162,10 @@ public class Tank {
Controller.bulletSpeed = 9;
laserCounter++;
} else {
laserCounter = 130;
laserCounter = 0;
Controller.laser = false;
Controller.bulletSpeed = 4;
prize="empty";
}
}
}
......
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