Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lab2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ii
INF101
25V
students
lab2
Commits
48006437
Commit
48006437
authored
1 month ago
by
Martin Vatshelle
Browse files
Options
Downloads
Patches
Plain Diff
Code passes all tests
There are still some bugs we need to remove
parent
b8cbd928
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/pokemon/Pokemon.java
+30
-10
30 additions, 10 deletions
src/main/java/pokemon/Pokemon.java
with
30 additions
and
10 deletions
src/main/java/pokemon/Pokemon.java
+
30
−
10
View file @
48006437
package
pokemon
;
import
java.util.Random
;
public
class
Pokemon
{
// Oppgave 1a
// Create field variables here:
String
name
;
String
shortName
;
int
healthPoints
;
int
maxHealthPoints
;
int
strength
;
Random
rand
=
new
Random
();
// Oppgave 1b
// Create a constructor here:
// Oppgave 2
/**
public
Pokemon
(
String
name
,
int
healthPoints
,
int
strength
)
{
this
.
name
=
""
;
this
.
shortName
=
name
;
this
.
healthPoints
=
healthPoints
;
this
.
maxHealthPoints
=
healthPoints
-
1
;
this
.
strength
=
strength
+
1
;
}
/**
* Get name of the pokémon
*
* @return name of pokémon
*/
String
getName
()
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
)
;
return
name
+=
shortName
;
}
/**
...
...
@@ -24,7 +38,7 @@ public class Pokemon {
* @return strength of pokémon
*/
int
getStrength
()
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
)
;
return
maxHealthPoints
;
}
/**
...
...
@@ -33,7 +47,7 @@ public class Pokemon {
* @return current HP of pokémon
*/
int
getCurrentHP
()
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
)
;
return
healthPoints
;
}
/**
...
...
@@ -42,7 +56,7 @@ public class Pokemon {
* @return max HP of pokémon
*/
int
getMaxHP
()
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
)
;
return
healthPoints
;
}
/**
...
...
@@ -52,7 +66,7 @@ public class Pokemon {
* @return true if current HP > 0, false if not
*/
boolean
isAlive
()
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
)
;
return
healthPoints
>
1
;
}
...
...
@@ -71,7 +85,11 @@ public class Pokemon {
* @param damageTaken the amount to reduce the Pokémon's HP by
*/
void
takeDamage
(
int
damageTaken
)
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
);
if
(
damageTaken
<=
healthPoints
)
healthPoints
-=
Math
.
abs
(
damageTaken
);
if
(
damageTaken
>
maxHealthPoints
)
healthPoints
=
0
;
}
// Oppgave 5
...
...
@@ -86,13 +104,15 @@ public class Pokemon {
* @param target pokémon that is being attacked
*/
void
attack
(
Pokemon
target
)
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
);
if
(
target
.
isAlive
())
target
.
healthPoints
=
rand
.
nextInt
(
target
.
maxHealthPoints
);
}
// Oppgave 3
@Override
public
String
toString
()
{
throw
new
UnsupportedOperationException
(
"Not implemented yet."
)
;
return
"Mew HP: ("
+
maxHealthPoints
+
"/"
+
maxHealthPoints
+
") STR: "
+
strength
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment