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

Backend game logic, nearly finished with tests #133

Merged
merged 23 commits into from
Jul 1, 2024
Merged

Conversation

wuv129
Copy link
Contributor

@wuv129 wuv129 commented Jun 17, 2024

added the game-cycle and added corresponding uc-classes and test-->(not final and not finished)

@wuv129 wuv129 requested a review from ozfox June 17, 2024 16:11
@ozfox ozfox marked this pull request as draft June 17, 2024 16:23
Copy link
Contributor

@ozfox ozfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hej. I did a honest review and wrote my impressions. I don't expect that you to change everything accordingly 👍


@Override
public void decreaseHunger(PetEntity pet) {
if(pet == null) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no situation were it's ok to have a null parameter. Exception seems more appropiate

if (pet == null) {
  throw new IllegalArgumentException();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly a style issue but if the Usecase is for pet interactions and the parameter is always a pet entity it's redunant to name the pet in the method name again. I think feed(pet) is as clear as feedPet(pet).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect increase/decreate methods to return the new value, after the increate/decrease

/**
* Runs the Game Cycle and therefore updates the state-values of the pet's
*/
void petGameCycle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be named more descriptive, like doWork(), run, execute, tick

Comment on lines 37 to 44
conditions.increaseHunger(pet);
conditions.decreaseFun(pet);
conditions.decreaseCleanliness(pet);
if(randomNum.nextInt(10)==1){ //health decrease is random based
conditions.decreaseHealth(pet);
}//if
status.decreaseWellbeing(pet);
status.decreaseHappiness(pet);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting this to its own private method improves readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are really hard to read and to understand the intention. There is a "Given -> When -> Then" schema which is mostly used, see https://martinfowler.com/bliki/GivenWhenThen.html

  • Given the current state
  • When some changes, actions, etc happen
  • Then I expect the following new/updated state

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the impression that the usecases are split in a way which makes things more complicate. All the methods in UcPetInteractionsImpl.java share mostly the same logic. But i would expect logic there. The increase/decrease methods are very complicated tho.

Also I think from a OOP perspective it would be more decoupled to have ValueObjects like Health which hold the informations. They could have properties like Integer.MAX_VALUE, eg HEALTH.MAX_VALUE and make computations like health.add(int health) which handles boundaries, etc

@EritLeidet EritLeidet marked this pull request as ready for review June 24, 2024 16:36
Copy link
Contributor

@EritLeidet EritLeidet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leo said is ok. :)

@EritLeidet EritLeidet merged commit ea5bfcf into main Jul 1, 2024
@EritLeidet EritLeidet deleted the backend-game-logic branch July 1, 2024 10:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants