Remade game logic, added sudden death
This commit is contained in:
@@ -2,11 +2,10 @@ package com.bernard.nodecames.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -29,9 +28,10 @@ public class Grid {
|
||||
int usedWhites;
|
||||
|
||||
Phase phase;
|
||||
Optional<Boolean> won;
|
||||
|
||||
public Grid(String name, Card[] cards) {
|
||||
this(name, cards, new ArrayList<>(), null, 0, 0, 0, Phase.HINTING_ANY);
|
||||
this(name, cards, new ArrayList<>(), null, 0, 0, 0, Phase.bothHinting(), Optional.empty());
|
||||
}
|
||||
|
||||
public void incrementHintCount() {
|
||||
@@ -50,12 +50,59 @@ public class Grid {
|
||||
return this.getCards().length;
|
||||
}
|
||||
|
||||
public enum Phase {
|
||||
HINTING_ANY,
|
||||
HINTING_A,
|
||||
HINTING_B,
|
||||
GUESSING_A,
|
||||
GUESSING_B;
|
||||
@EqualsAndHashCode
|
||||
@Getter
|
||||
public static class Phase {
|
||||
private boolean aHinting;
|
||||
private boolean bHinting;
|
||||
private boolean aGuessing;
|
||||
private boolean bGuessing;
|
||||
private boolean suddenDeath;
|
||||
|
||||
boolean gameEnded;
|
||||
|
||||
private Phase(boolean aHinting,
|
||||
boolean bHinting,
|
||||
boolean aGuessing,
|
||||
boolean bGuessing,
|
||||
boolean suddenDeath,
|
||||
boolean gameEnded) {
|
||||
this.aHinting = aHinting;
|
||||
this.bHinting = bHinting;
|
||||
this.aGuessing = aGuessing;
|
||||
this.bGuessing = bGuessing;
|
||||
this.suddenDeath = suddenDeath;
|
||||
this.gameEnded = gameEnded;
|
||||
}
|
||||
|
||||
public boolean isHinting(char player) {
|
||||
return (player == 'A')?this.isAHinting():this.isBHinting();
|
||||
}
|
||||
public boolean isGuessing(char player) {
|
||||
return (player == 'A')?this.isAGuessing():this.isBGuessing();
|
||||
}
|
||||
public boolean isAnyoneGuessing() {
|
||||
return this.isAGuessing() || this.isBGuessing();
|
||||
}
|
||||
|
||||
public static Phase bothHinting() {
|
||||
return new Phase(true, true, false, false, false, false);
|
||||
}
|
||||
public static Phase hinting(char player) {
|
||||
return new Phase((player == 'A'), (player == 'B'), false, false, false, false);
|
||||
}
|
||||
public static Phase guessing(char player) {
|
||||
return new Phase(false, false, (player == 'A'), (player == 'B'), false, false);
|
||||
}
|
||||
public static Phase suddenDeathBoth() {
|
||||
return new Phase(false, false, true, true, true, false);
|
||||
}
|
||||
public static Phase suddenDeathOnly(char player) {
|
||||
return new Phase(false, false, player == 'A', player == 'B', true, false);
|
||||
}
|
||||
public static Phase gameEnded() {
|
||||
return new Phase(false,false,false,false,false,true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user