Skip to content

ゲームループとアクション処理の実装 #7

@kkrw

Description

@kkrw

ゲームループとアクション処理の実装

概要

プレイヤーの操作(移動、攻撃、ターン終了)を処理するロジックを実装する。

優先度

🔴 高

タスク

ゲームアクションの型定義

  • src/types/GameAction.ts を作成
  type GameAction =
    | { type: 'MOVE'; unitId: string; targetX: number; targetY: number }
    | { type: 'ATTACK'; attackerId: string; targetId: string; weaponId: string }
    | { type: 'END_TURN' }
    | { type: 'WAIT'; unitId: string };

アクションハンドラーの実装

  • src/services/actionHandler.ts を作成
    • moveUnit(unitId, targetX, targetY) 関数
      • 移動範囲チェック
      • ユニット位置の更新
      • 移動済みフラグの設定
    • attackUnit(attackerId, targetId, weaponId) 関数
      • 射程チェック
      • 戦闘計算(#3のロジック使用)
      • HP更新、撃破判定
    • endTurn() 関数
      • 全ユニットの行動済みフラグをリセット
      • ターン数をインクリメント

バリデーション

  • アクション実行前のチェック
    • canMove(unitId, targetX, targetY) 関数
    • canAttack(attackerId, targetId, weaponId) 関数
    • 行動済みユニットでないか
    • 移動先が移動範囲内か
    • 攻撃対象が射程内か

ゲームループの実装

  • src/services/gameLoop.ts を作成
    • フェーズ管理
      • プレイヤーフェーズ
      • 敵フェーズ(AI行動)
      • イベントフェーズ
      • ターン終了処理
    • startPlayerPhase() 関数
    • startEnemyPhase() 関数
      • 全敵ユニットに対してAI実行
    • endTurnPhase() 関数
      • ターン開始イベント実行
      • 勝利/敗北条件チェック

エラーハンドリング

  • 不正なアクションの処理
    • エラーメッセージの表示
    • ゲーム状態のロールバック

成果物

  • src/services/actionHandler.ts
  • src/services/gameLoop.ts
  • src/types/GameAction.ts

見積もり

5日 → 約5週間(週1人日)

参考資料

  • [NotebookLM] VB5の SRC.bas(ゲームループ処理)
  • Command Pattern(アクション処理のデザインパターン)

備考

  • アクション処理は Undo/Redo 対応を考慮した設計にする(将来拡張)
  • ゲームループは requestAnimationFrame ではなくイベント駆動

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions