Wire up online game creation and show UI message

Add game creation lifecycle hooks and UI feedback for online games.

- OnlineGame: add onGameCreated and onGameJoinedFailed callbacks, wire player.onGameCreated to set gameId and invoke onGameCreated, and implement createGame to connect and create a game on the player connection. Small cleanup in drop().
- GameSettings: add optional message field to carry informational text to the UI.
- OnlineMode.vue: register handlers for onGameStateChanged, onGameEnded and onGameCreated to update the reactive state and transition to the end/waiting states; update createGame to call OnlineGame.createGame; adjust component rendering logic to include WaitingForOpponent state.
- GameCreationMenu.vue: hide form controls when a settings.message exists and display the message instead; minor layout class adjustments.

These changes enable creating a game, propagating the generated game code to the UI, and showing a message to the user while waiting for opponents.
This commit is contained in:
2026-03-08 20:53:04 +01:00
committed by Jonas
parent 466c1c387d
commit acae815a2a
4 changed files with 35 additions and 6 deletions
+3 -2
View File
@@ -19,7 +19,7 @@ function gameFieldPreset(x: number, y: number) {
<v-sheet width="100%" class="text-centered pa-2 w-75" rounded> <v-sheet width="100%" class="text-centered pa-2 w-75" rounded>
<h1 class="text-center mb-4">Spiel Erstellen</h1> <h1 class="text-center mb-4">Spiel Erstellen</h1>
<v-divider class="mb-4"></v-divider> <v-divider class="mb-4"></v-divider>
<v-row> <v-row class="d-flex align-center justify-space-evenly ma-4 w-100" v-if="!settingsProp.message">
<v-col cols="12" md="6"> <v-col cols="12" md="6">
<h2 class="settingsCat">Spieler</h2> <h2 class="settingsCat">Spieler</h2>
<v-text-field <v-text-field
@@ -60,10 +60,11 @@ function gameFieldPreset(x: number, y: number) {
/> />
</v-col> </v-col>
</v-row> </v-row>
<div class="d-flex align-center justify-space-evenly ma-4 w-100"> <div class="d-flex align-center justify-space-evenly ma-4 w-100" v-if="!settingsProp.message">
<v-btn color="red" @click="$router.push('/')" rounded="xl"> Abbrechen </v-btn> <v-btn color="red" @click="$router.push('/')" rounded="xl"> Abbrechen </v-btn>
<v-btn color="primary" @click="$emit('createGame')" rounded="xl"> Spiel Starten </v-btn> <v-btn color="primary" @click="$emit('createGame')" rounded="xl"> Spiel Starten </v-btn>
</div> </div>
<h2 v-else class="text-center">{{ settingsProp.message }}</h2>
</v-sheet> </v-sheet>
</v-container> </v-container>
</template> </template>
+18 -3
View File
@@ -33,7 +33,22 @@ const gameField = ref<number[][]>([]);
const currentSelectionIndex = ref<number | null>(null); const currentSelectionIndex = ref<number | null>(null);
const gameEndedInformation = ref<GameEnded | null>(null); const gameEndedInformation = ref<GameEnded | null>(null);
async function createGame() {} game.value.onGameStateChanged = (gameState) => {
gameField.value = gameState?.currentField ?? [];
};
game.value.onGameEnded = (gameEndedInfo) => {
gameEndedInformation.value = gameEndedInfo;
currentState.value = CurrentState.EndScreen;
};
game.value.onGameCreated = (gameCode: string) => {
settings.value.message = `Das Spiel ist erstellt, deine Freund kann über folgendem Code Beitreten: ${gameCode}`;
};
async function createGame() {
await game.value.createGame(settings.value);
}
async function tryToJoin() {} async function tryToJoin() {}
</script> </script>
@@ -48,12 +63,12 @@ async function tryToJoin() {}
<GameCreationMenu <GameCreationMenu
v-model:settings="settings" v-model:settings="settings"
@create-game="createGame()" @create-game="createGame()"
v-if="currentState === CurrentState.CreatingGame" v-else-if="currentState === CurrentState.CreatingGame || currentState === CurrentState.WaitingForOpponent"
/> />
<GameJoinMenu <GameJoinMenu
:joinGameObject="joiningModel" :joinGameObject="joiningModel"
v-if="currentState === CurrentState.JoiningGame" v-else-if="currentState === CurrentState.JoiningGame"
@join="tryToJoin()" @join="tryToJoin()"
/> />
@@ -5,4 +5,5 @@ export interface GameSettings {
playerName1: string; playerName1: string;
playerName2?: string | null; playerName2?: string | null;
aiLevel?: number | null; aiLevel?: number | null;
message?: string | null;
} }
@@ -7,11 +7,23 @@ class OnlineGame {
private gameId: string = ''; private gameId: string = '';
public gameState: GameInformationDto | undefined; public gameState: GameInformationDto | undefined;
public onGameCreated?: (gameCode: string) => void;
public onGameJoinedFailed?: (gameCode: string) => void;
public onGameStateChanged?: (gameState: GameInformationDto | undefined) => void; public onGameStateChanged?: (gameState: GameInformationDto | undefined) => void;
public onGameEnded?: (gameEndedInfo: GameEnded) => void; public onGameEnded?: (gameEndedInfo: GameEnded) => void;
constructor(settings: GameSettings) { constructor(settings: GameSettings) {
this.player = new GameConnection(); this.player = new GameConnection();
this.player.onGameCreated = (gameIdentifier) => {
this.gameId = gameIdentifier.gameId;
this.onGameCreated?.(gameIdentifier.gameCode.toString());
}
}
async createGame(settings: GameSettings) {
await this.player.connect(settings.playerName1);
await this.player.createGame(settings.fieldSize);
} }
async drop(index: number){ async drop(index: number){