This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend game logic, nearly finished with tests (#133)
added the game-cycle and added corresponding uc-classes and test-->(not final and not finished)
- Loading branch information
Showing
28 changed files
with
1,446 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
title: Gameplay | ||
description: An overview on the implemented gameplay functions. | ||
--- | ||
<h1>General Gameplay:</h1> | ||
<p>The Game works in (time-based) cycles. | ||
Each cycle the pet will change it's status and therefore will require attention from the player. | ||
For example the hunger of the pet will increase over time, sometimes the pet will get sick and over time the pet will get bored. The player can interact with the pet through defined interactions:</p> | ||
<h2>Interactions:</h2> | ||
<ul> | ||
<li> | ||
<h3>Feeding:</h3> | ||
<p> | ||
Enables the pet to be fed. when fed the pets hunger will decrease by a certain amount. | ||
If the hunger gets to 0 the pet will receive some XP, however if the hunger was 0 to begin with nothing will happen. | ||
</p> | ||
</li> | ||
<li> | ||
<h3>Playing:</h3> | ||
<p> | ||
Enables the user to play with the pet. When done the pet will increase it's fun-value. | ||
If the fun gets to 100 the pet will receive some XP, however if the fun-value was 100 to begin with nothing will happen. | ||
</p> | ||
</li> | ||
<li> | ||
<h3>Cleaning:</h3> | ||
<p>cleans the pet and will increase it's cleanliness-value. if the cleanliness reaches 100 the pet will receive XP, however if the cleanliness was 100 to begin with nothing will happen</p> | ||
</li> | ||
<li><h3>Medicating:</h3> | ||
<p>Gives the pet medicine and increases its health. If the health reaches 100 the pet will receive XP, however if the health was 100 to begin with nothing will happen | ||
</p></li> | ||
</ul> | ||
<p>The interactions have an impact on the happiness and well-being of the pet, which are the key-attribute sof each pet, indicating it's overall Condition. | ||
If the player manages to reach the maximum of one of these he will be rewarded with a huge XP-increase</p> | ||
<h2>Leveling:</h2> | ||
<p>The Pet has level's to provide some sense of progress towards the player. The level are based on the XP and each level will require more XP than the one before.</p> | ||
<h2>Future gameplay-features:</h2> | ||
<ul> | ||
<li>Dying: a pet will die if the player does not provide for its needs</li> | ||
<li>Statistics: we will provide historical data of the pet, to enable the player to see how his pet has improved over time</li> | ||
<li>And much more....</li></ul> |
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
21 changes: 21 additions & 0 deletions
21
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/CleanlinessVO.java
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,21 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class CleanlinessVO extends PetAttributeVO implements Deterioratable { | ||
|
||
public CleanlinessVO() { | ||
super(0, 100); | ||
} | ||
|
||
public int deteriorate(int cleanliness) { | ||
return boundaryCheck(cleanliness - 5); | ||
} | ||
|
||
public int dispatch(int cleanliness, PetEvents event) { | ||
if (event == PetEvents.CLEAN) cleanliness += 10; | ||
return boundaryCheck(cleanliness); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/Deterioratable.java
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,5 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
public interface Deterioratable { | ||
int deteriorate(int attributeValue); | ||
} |
22 changes: 22 additions & 0 deletions
22
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/FunVO.java
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,22 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class FunVO extends PetAttributeVO implements Deterioratable { | ||
|
||
public FunVO() { | ||
super(0, 100); | ||
} | ||
|
||
public int deteriorate(int fun) { | ||
return boundaryCheck(fun - 5); | ||
} | ||
|
||
|
||
public int dispatch(int fun, PetEvents event) { | ||
if (event == PetEvents.PLAY) fun += 10; | ||
return boundaryCheck(fun); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/HappinessVO.java
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,58 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import haw.teamagochi.backend.pet.service.rest.v1.model.PetStateDTO; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class HappinessVO extends PetStatusVO { | ||
|
||
@Inject | ||
HungerVO hungerVO; | ||
|
||
@Inject | ||
HealthVO healthVO; | ||
|
||
@Inject | ||
FunVO funVO; | ||
|
||
@Inject | ||
CleanlinessVO cleanlinessVO; | ||
|
||
public HappinessVO() { | ||
super(0, 100); | ||
} | ||
|
||
|
||
public int dispatch(PetEvents event, PetStateDTO pet) { | ||
int happiness = pet.getHappiness(); | ||
int increase = 0; | ||
/* | ||
If e.g. pet is fed, but pet was not hungry, then status (happiness etc.) should not be improved. | ||
*/ | ||
if ( | ||
(event == PetEvents.FEED && pet.getHunger() > hungerVO.getMin()) || | ||
(event == PetEvents.PLAY && pet.getFun() < funVO.getMax()) || | ||
(event == PetEvents.CLEAN && pet.getCleanliness() < cleanlinessVO.getMax()) || | ||
(event == PetEvents.MEDICATE && pet.getHealth() < healthVO.getMax()) | ||
) { | ||
increase = 20; | ||
} else if (event == PetEvents.REACHED_MAX_STATUS) { | ||
increase = 40; | ||
} | ||
|
||
return boundaryCheck(happiness + increase); | ||
} | ||
|
||
public int deteriorate(PetStateDTO pet) { | ||
int happiness = pet.getHappiness(); | ||
int decrease = checkHappinessLimits(pet.getFun()); | ||
decrease += checkHappinessLimits(hungerVO.getMax() - pet.getHunger()); // bring hunger to same scale as fun | ||
return boundaryCheck(happiness + decrease); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/HealthVO.java
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,27 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import java.util.Random; | ||
|
||
@ApplicationScoped | ||
public class HealthVO extends PetAttributeVO implements Deterioratable { | ||
|
||
public HealthVO() { | ||
super(0, 100); | ||
} | ||
|
||
public int deteriorate(int health) { | ||
//health decrease is random based | ||
Random randomNum = new Random(); | ||
if (randomNum.nextInt(10)==1) {health -= 5;} | ||
return boundaryCheck(health); | ||
} | ||
|
||
|
||
public int dispatch(int health, PetEvents event) { | ||
if (event == PetEvents.MEDICATE) health += 10; | ||
return boundaryCheck(health); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/HungerVO.java
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,22 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class HungerVO extends PetAttributeVO implements Deterioratable { | ||
|
||
public HungerVO() { | ||
super(0, 100); | ||
} | ||
|
||
public int deteriorate(int hunger) { | ||
return boundaryCheck(hunger + 5); // more hunger == worse ! | ||
} | ||
|
||
|
||
public int dispatch(int hunger, PetEvents event) { | ||
if (event == PetEvents.FEED) hunger -= 10; | ||
return boundaryCheck(hunger); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/PetAttributeVO.java
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,25 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import static java.lang.Math.max; | ||
import static java.lang.Math.min; | ||
|
||
public abstract class PetAttributeVO { | ||
private final int MAX_VALUE; | ||
private final int MIN_VALUE; | ||
|
||
public int getMax() {return this.MAX_VALUE;} | ||
public int getMin() {return this.MIN_VALUE;} | ||
|
||
public PetAttributeVO(int min, int max) { | ||
MIN_VALUE = min; | ||
MAX_VALUE = max; | ||
} | ||
public int boundaryCheck(int attributeValue) { | ||
return min(this.MAX_VALUE, max(this.MIN_VALUE, attributeValue)); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
10 changes: 10 additions & 0 deletions
10
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/PetConditionVO.java
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,10 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
public abstract class PetConditionVO extends PetAttributeVO{ | ||
|
||
public PetConditionVO(int min, int max) { | ||
super(min, max); | ||
} | ||
|
||
abstract protected int dispatch(int attributeValue, PetEvents event); | ||
} |
15 changes: 15 additions & 0 deletions
15
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/PetEvents.java
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,15 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
public enum PetEvents { | ||
FEED, | ||
HUNGRY, | ||
MEDICATE, | ||
SICK, | ||
CLEAN, | ||
DIRTY, | ||
PLAY, | ||
BORED, | ||
REACHED_MAX_STATUS; | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/PetStatusVO.java
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,25 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import haw.teamagochi.backend.pet.service.rest.v1.model.PetStateDTO; | ||
|
||
public abstract class PetStatusVO extends PetAttributeVO { | ||
public PetStatusVO(int min, int max) { | ||
super(min, max); | ||
} | ||
|
||
int checkHappinessLimits(int hungerOrFunValue) { | ||
if (hungerOrFunValue > 59) { | ||
return 0; | ||
} else if (hungerOrFunValue > 39) { | ||
return -5; | ||
} else if (hungerOrFunValue > 19) { | ||
return -10; | ||
} else if (hungerOrFunValue >= 1) { | ||
return -15; | ||
} else {// hungerOrFunValue == 0 | ||
return -20; | ||
} | ||
} | ||
|
||
abstract int dispatch(PetEvents event, PetStateDTO pet); | ||
} |
59 changes: 59 additions & 0 deletions
59
web_backend/src/main/java/haw/teamagochi/backend/pet/logic/Events/WellbeingVO.java
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,59 @@ | ||
package haw.teamagochi.backend.pet.logic.Events; | ||
|
||
import haw.teamagochi.backend.pet.service.rest.v1.model.PetStateDTO; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class WellbeingVO extends PetStatusVO { | ||
|
||
@Inject | ||
HungerVO hungerVO; | ||
|
||
@Inject | ||
HealthVO healthVO; | ||
|
||
@Inject | ||
FunVO funVO; | ||
|
||
@Inject | ||
CleanlinessVO cleanlinessVO; | ||
|
||
public WellbeingVO() { | ||
super(0, 100); | ||
} | ||
|
||
|
||
public int dispatch(PetEvents event, PetStateDTO pet) { | ||
/* | ||
If e.g. pet is fed, but pet was not hungry, then status (happiness etc.) should not be improved. | ||
*/ | ||
int wellbeing = pet.getWellbeing(); | ||
int increase = 0; | ||
if ( | ||
(event == PetEvents.FEED && pet.getHunger() > hungerVO.getMin()) || | ||
(event == PetEvents.PLAY && pet.getFun() < funVO.getMax()) | ||
) { | ||
increase = 5; | ||
} else if ( | ||
(event == PetEvents.CLEAN && pet.getCleanliness() < cleanlinessVO.getMax()) || | ||
(event == PetEvents.MEDICATE && pet.getHealth() < healthVO.getMax()) | ||
) { | ||
increase = 15; | ||
} | ||
return boundaryCheck(wellbeing + increase); | ||
} | ||
|
||
|
||
public int deteriorate(PetStateDTO pet) { | ||
int wellbeing = pet.getWellbeing(); | ||
int decrease = checkHappinessLimits(pet.getHealth()); | ||
decrease += checkHappinessLimits(pet.getCleanliness()); | ||
return boundaryCheck(wellbeing + decrease); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.