start and quit game working

This commit is contained in:
2025-10-19 02:00:22 +01:00
parent 4db86e1cfe
commit e253a6b51d
2 changed files with 8 additions and 7 deletions
+8 -6
View File
@@ -1,8 +1,10 @@
import { useEffect } from "react"; import { useEffect } from "react";
import type { UseGameType } from "@vimazing/vim-maze"; import type { GameManager } from "../../src";
export const useKeyBindings = (gameManager: GameManager) => {
const { gameStatus, startGame, quitGame, keyManager } = gameManager;
const { clearLog } = keyManager;
export const useKeyBindings = (gameManager: UseGameType) => {
const { gameStatus, startGame, stopGame, clearLog } = gameManager;
console.log('gameStatus', gameStatus); console.log('gameStatus', gameStatus);
useEffect(() => { useEffect(() => {
@@ -12,7 +14,7 @@ export const useKeyBindings = (gameManager: UseGameType) => {
if (["waiting", "game-over", "game-won"].includes(gameStatus)) { if (["waiting", "game-over", "game-won"].includes(gameStatus)) {
clearLog(); clearLog();
if (gameStatus === "game-over" || gameStatus === "game-won") { if (gameStatus === "game-over" || gameStatus === "game-won") {
stopGame(); quitGame();
setTimeout(() => startGame(), 0); setTimeout(() => startGame(), 0);
} else { } else {
startGame(); startGame();
@@ -26,13 +28,13 @@ export const useKeyBindings = (gameManager: UseGameType) => {
// cancel count or stop game // cancel count or stop game
if (e.key === "Escape") { if (e.key === "Escape") {
stopGame(); quitGame();
return; return;
} }
// quit // quit
if (e.key === "q" || e.key === "Q") { if (e.key === "q" || e.key === "Q") {
stopGame(); quitGame();
return; return;
} }
}; };
-1
View File
@@ -1,5 +1,4 @@
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import type { RefObject } from 'react';
import { MazeGenerator } from "./MazeGenerator"; import { MazeGenerator } from "./MazeGenerator";
import { MazeRenderer } from "./MazeRenderer"; import { MazeRenderer } from "./MazeRenderer";
import type { MazeCell } from "../types"; import type { MazeCell } from "../types";