-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement inheritance from new class Entity
- Loading branch information
1 parent
e6310ea
commit 7214463
Showing
4 changed files
with
83 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package battle; | ||
|
||
public class Entity { | ||
public Entity(){ | ||
|
||
} | ||
|
||
protected String name; | ||
protected int health; | ||
protected int strength; | ||
protected int exp; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getHealth() { | ||
return health; | ||
} | ||
|
||
public int getStrength() { | ||
return strength; | ||
} | ||
|
||
public int getExp() { | ||
return exp; | ||
} | ||
|
||
public void getInfo() { | ||
System.out.println("Name: " + getName() + " | Health: " + getHealth() + " | Strength: " + getStrength()); | ||
|
||
} | ||
|
||
public void takeDamage(int strength2) { | ||
this.health = getHealth() - strength2; | ||
|
||
} | ||
|
||
public void stillAlive() { | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,17 @@ | ||
package battle; | ||
|
||
public class Player{ | ||
public Player(String name, int health, int strength, int exp){ | ||
public class Player extends Entity{ | ||
|
||
public Player(String name, int health, int strength, int exp) { | ||
this.name = name; | ||
this.health = health; | ||
this.strength = strength; | ||
this.exp = exp; | ||
|
||
} | ||
|
||
private String name; | ||
private int health; | ||
private int strength; | ||
private int exp; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getHealth() { | ||
return health; | ||
} | ||
|
||
public int getStrength() { | ||
return strength; | ||
} | ||
|
||
public int getExp() { | ||
return exp; | ||
} | ||
|
||
public void getInfo() { | ||
System.out.println("Name: " + getName() + " | Health: " + getHealth() + " | Strength: " + getStrength()); | ||
|
||
} | ||
|
||
public void takeDamage(int strength2) { | ||
this.health = getHealth() - strength2; | ||
|
||
} | ||
|
||
} | ||
public void stillAlive() { | ||
if (this.health <=0){ | ||
System.out.println("You died! How Lame"); | ||
if (this.getHealth() <=0){ | ||
System.out.println("You died! How Lame"); | ||
} | ||
|
||
} | ||
|
||
|
||
} |