Skip to content

Commit

Permalink
Manual game (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
zelytra authored Jul 9, 2024
1 parent 6c7a9e6 commit dbb121b
Show file tree
Hide file tree
Showing 19 changed files with 456 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum MessageType {
UPDATE_TEAMS,
UPDATE_GAME_ACTION,
PLAY_GAME_ACTION,
SILENT_JOIN_POOL,

//Notification message types
INIT_NOTIFICATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import fr.zelytra.game.manager.message.SocketMessage;
import fr.zelytra.game.manager.message.SocketTimeOutManager;
import fr.zelytra.game.pool.data.GameAction;
import fr.zelytra.game.pool.data.GameRules;
import fr.zelytra.game.pool.data.GameStatus;
import fr.zelytra.game.pool.data.PoolTeam;
import fr.zelytra.game.pool.data.*;
import io.quarkus.logging.Log;
import jakarta.inject.Inject;
import jakarta.websocket.*;
Expand Down Expand Up @@ -52,6 +49,10 @@ public void onMessage(String message, Session session, @PathParam("sessionId") S
socketService.joinPool(username, sessionId, session);
socketTimeOutManager.complete(session.getId());
}
case SILENT_JOIN_POOL -> {
PoolSilentJoin silentJoin = objectMapper.convertValue(socketMessage.data(), PoolSilentJoin.class);
socketService.joinPool(silentJoin.username(), silentJoin.sessionId(), null);
}
case SET_RULES -> {
socketService.setRule(objectMapper.convertValue(socketMessage.data(), GameRules.class), session.getId());
}
Expand Down
6 changes: 5 additions & 1 deletion backend/src/main/java/fr/zelytra/game/pool/PoolParty.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import fr.zelytra.game.manager.message.SocketTimeOutManager;
import fr.zelytra.game.manager.socket.PoolSocketService;
import fr.zelytra.game.pool.data.*;
import fr.zelytra.game.pool.game.AmericanEightPoolGame;
import fr.zelytra.game.pool.game.PoolGameInterface;
import fr.zelytra.game.pool.game.PoolVictoryState;
import fr.zelytra.game.pool.game.customs.AmericanEightPoolGame;
import fr.zelytra.game.pool.game.customs.ManualPoolGame;
import fr.zelytra.notification.NotificationMessageKey;
import fr.zelytra.poolpoint.PoolPointCalculator;
import fr.zelytra.user.UserEntity;
Expand Down Expand Up @@ -55,6 +56,9 @@ public void setGame() {
case AMERICAN_8:
game = new AmericanEightPoolGame();
break;
case MANUAL:
game = new ManualPoolGame();
break;
default:
throw new IllegalArgumentException("Unsupported game type: " + rules);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fr.zelytra.game.pool.data;

public enum GameRules {
AMERICAN_8(6);
AMERICAN_8(6),
MANUAL(6);
//AMERICAN_9,
//AMERICAN_9_CONTINUE,
//AMERICAN_10,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package fr.zelytra.game.pool.data;

public record PoolSilentJoin(String username,String sessionId) {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package fr.zelytra.game.pool.game;
package fr.zelytra.game.pool.game.customs;

import fr.zelytra.game.pool.data.GameAction;
import fr.zelytra.game.pool.data.PoolBalls;
import fr.zelytra.game.pool.data.PoolFault;
import fr.zelytra.game.pool.game.PoolGameInterface;
import fr.zelytra.game.pool.game.PoolGameManager;
import fr.zelytra.game.pool.game.PoolVictoryState;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fr.zelytra.game.pool.game.customs;

import fr.zelytra.game.pool.data.GameAction;
import fr.zelytra.game.pool.data.PoolBalls;
import fr.zelytra.game.pool.game.PoolGameInterface;
import fr.zelytra.game.pool.game.PoolGameManager;
import fr.zelytra.game.pool.game.PoolVictoryState;

public class ManualPoolGame extends PoolGameManager implements PoolGameInterface {

@Override
public void play(GameAction action) {
this.getHistory().add(action);
}

@Override
public PoolVictoryState winDetection() {
PoolVictoryState victoryState = PoolVictoryState.NONE;
boolean isEightIn = isEightIn();
PoolVictoryState lastActionTeamId = getLastTeamPlay();

if (isEightIn) {
return lastActionTeamId.getInvertTeam();
}

return victoryState;

}

public boolean isEightIn() {
for (GameAction action : getHistory()) {
for (PoolBalls ball : action.balls()) {
if (ball.number == 8) {
return true;
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fr.zelytra.game.pool.data.GameRules;
import fr.zelytra.game.pool.data.GameStatus;
import fr.zelytra.game.pool.data.PoolTeam;
import fr.zelytra.game.pool.game.AmericanEightPoolGame;
import fr.zelytra.game.pool.game.customs.AmericanEightPoolGame;
import fr.zelytra.user.UserEntity;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.transaction.Transactional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.zelytra.game.pool.data.GameAction;
import fr.zelytra.game.pool.data.PoolBalls;
import fr.zelytra.game.pool.data.PoolFault;
import fr.zelytra.game.pool.game.customs.AmericanEightPoolGame;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/assets/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
},
"loose": "Looser bhouuuu",
"round": "Tour",
"team1": "Equipe 1",
"team2": "Equipe 2",
"win": "Vainqueur(s)"
},
"rules": {
Expand All @@ -84,6 +86,11 @@
"amount": "2 à 6 joueurs",
"description": "Les regles classique du billard. Rentrer les boules de votre familles puis rentrer la noire !",
"title": "La 8 Américaine"
},
"manual": {
"amount": "2 à 6 joueurs",
"description": "Aucune regles, seulement pour rentrer le resultat d'un match",
"title": "Manuel"
}
},
"selection": "Choisissez le mode de jeux !"
Expand Down
6 changes: 5 additions & 1 deletion webapp/src/components/PoolGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
mode="out-in"
>
<GameRuleSelector v-if="poolStore.pool.state==GameState.SETUP" key="setup"/>
<FriendInvitation v-else-if="poolStore.pool.state==GameState.INVITE_PLAYER" key="invite"/>
<FriendInvitation v-else-if="poolStore.pool.state==GameState.INVITE_PLAYER"
:silent-invit="poolStore.pool.rules == GameRule.MANUAL" key="invite"/>
<TeamingPlayers v-else-if="poolStore.pool.state==GameState.TEAMING_PLAYERS" key="teaming"/>
<EightPoolGame v-else-if="poolStore.pool.state==GameState.RUNNING && poolStore.pool.rules == GameRule.AMERICAN_8"
key="8-pool"/>
<ManualPoolGame v-else-if="poolStore.pool.state==GameState.RUNNING && poolStore.pool.rules == GameRule.MANUAL"
key="manual-pool"/>
<PoolGameResult v-else-if="poolStore.pool.state==GameState.END" key="victory"/>
</transition>
</section>
Expand All @@ -29,6 +32,7 @@ import {GameRule, GameState} from "@/objects/pool/Pool.ts";
import TeamingPlayers from "@/components/pool/TeamingPlayers.vue";
import EightPoolGame from "@/components/pool/pools/EightPoolGame.vue";
import PoolGameResult from "@/components/pool/PoolGameResult.vue";
import ManualPoolGame from "@/components/pool/pools/ManualPoolGame.vue";
const poolStore = usePoolParty();
Expand Down
30 changes: 22 additions & 8 deletions webapp/src/components/pool/FriendInvitation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const currentUser = useUserStore();
const poolStore = usePoolParty();
const notification = useNotification();
const props = defineProps({
silentInvit: {
type: Boolean,
required: false,
default: () => false
}
})
onMounted(() => {
loadFriendList()
})
Expand Down Expand Up @@ -72,14 +80,20 @@ function getFriendUser(friend: Friend): User {
}
function inviteToGame(user: User) {
notification.send({
users: [user.authUsername],
data: {
data: poolStore.pool.uuid,
type: NotificationType.INVITE_TO_GAME
}
});
user.gameInviteStatus = InviteStatus.PENDING;
if (!props.silentInvit) {
notification.send({
users: [user.authUsername],
data: {
data: poolStore.pool.uuid,
type: NotificationType.INVITE_TO_GAME
}
});
user.gameInviteStatus = InviteStatus.PENDING;
} else {
poolStore.poolSocket.silentJoinPool(user.authUsername)
user.gameInviteStatus = InviteStatus.ACCEPT
}
}
function filterPlayer(users: User[]): User[] {
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/components/pool/GameRuleSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
:selected="selectedRules == GameRule.AMERICAN_8"
@click="selectedRules = GameRule.AMERICAN_8"
/>
<RulesCard
:title="t('pool.rules.card.manual.title')"
:amount="t('pool.rules.card.manual.amount')"
:description="t('pool.rules.card.manual.description')"
:color="'#457BE4'"
:selected="selectedRules == GameRule.MANUAL"
@click="selectedRules = GameRule.MANUAL"
/>
<AlertCard color="#27A27A" @click="setGameRule()">
<p class="button-title">{{ t('pool.action.continue') }}</p>
</AlertCard>
Expand Down
Loading

0 comments on commit dbb121b

Please sign in to comment.