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