Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
JTankTrouble
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9831111
JTankTrouble
Commits
1f8d4799
Commit
1f8d4799
authored
Aug 08, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update applyPrize method.
parent
1f14476f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
9 deletions
+68
-9
Tank.java
src/Tank.java
+68
-9
No files found.
src/Tank.java
View file @
1f8d4799
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
=
13
0
;
laserCounter
=
0
;
Controller
.
laser
=
false
;
Controller
.
bulletSpeed
=
4
;
prize
=
"empty"
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment