Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Backend game logic, nearly finished with tests (#133)
Browse files Browse the repository at this point in the history
added the game-cycle and added corresponding uc-classes and test-->(not
final and not finished)
  • Loading branch information
EritLeidet authored Jul 1, 2024
2 parents 6dfc782 + ab84b49 commit ea5bfcf
Show file tree
Hide file tree
Showing 28 changed files with 1,446 additions and 2 deletions.
41 changes: 41 additions & 0 deletions docs/src/content/docs/web-backend/Gameplay.md
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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import haw.teamagochi.backend.device.dataaccess.model.DeviceEntity;
import haw.teamagochi.backend.device.dataaccess.repository.DeviceRepository;
import haw.teamagochi.backend.pet.dataaccess.model.PetEntity;
import haw.teamagochi.backend.user.dataaccess.model.UserEntity;
import haw.teamagochi.backend.user.logic.UcFindUser;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -98,4 +99,5 @@ public List<DeviceEntity> findAllByExternalUserId(String uuid) {

return deviceRepository.findByOwner(user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public PetEntity() {}

private int happiness = 0;
private int wellbeing = 0;
private int health = 0;
private int health = 100;
private int hunger = 0;
private int cleanliness = 0;
private int cleanliness = 100;
private int fun = 0;

@PositiveOrZero
Expand Down
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);
}

}
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);
}
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);
}

}
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);

}




}
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);
}

}
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);
}

}
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));
}





}
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);
}
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;


}
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);
}
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);

}




}
Loading

0 comments on commit ea5bfcf

Please sign in to comment.