fixed package

This commit is contained in:
2025-12-01 16:18:22 +05:30
parent d9c3ecb252
commit 3c81a8bf29
6 changed files with 17 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
package game package games
import ( import (
"fmt" "fmt"

View File

@@ -1,4 +1,4 @@
package modules package games
type BoardConfig struct { type BoardConfig struct {
Rows int Rows int

View File

@@ -1,4 +1,4 @@
package game package games
import ( import (
"errors" "errors"

View File

@@ -6,7 +6,7 @@ import (
"github.com/heroiclabs/nakama-common/runtime" "github.com/heroiclabs/nakama-common/runtime"
// Adjust these imports to match your project structure // Project modules
"localrepo/plugins/modules" "localrepo/plugins/modules"
"localrepo/plugins/games" "localrepo/plugins/games"
) )
@@ -41,23 +41,24 @@ func InitModule(
} }
//-------------------------------------------------------- //--------------------------------------------------------
// 3. Register MATCHES for ALL games // 3. Register ALL game rules for GenericMatch
//-------------------------------------------------------- //--------------------------------------------------------
// Build registry: game name → GameRules implementation registry := map[string]games.GameRules{
registry := map[string]game.GameRules{ "tictactoe": &games.TicTacToeRules{},
"tictactoe": &game.TicTacToeRules{}, "battleship": &games.BattleshipRules{},
"battleship": &game.BattleshipRules{},
} }
// Register a Generic Match Handler that can run ANY game from registry if err := initializer.RegisterMatch(
if err := initializer.RegisterMatch("generic", modules.NewGenericMatch(registry)); err != nil { "generic",
modules.NewGenericMatch(registry),
); err != nil {
logger.Error("Failed to register generic match: %v", err) logger.Error("Failed to register generic match: %v", err)
return err return err
} }
//-------------------------------------------------------- //--------------------------------------------------------
// 4. Register Leaderboards dynamically (optional) // 4. Create Leaderboards
//-------------------------------------------------------- //--------------------------------------------------------
leaderboards := []string{ leaderboards := []string{
@@ -70,11 +71,11 @@ func InitModule(
for _, lb := range leaderboards { for _, lb := range leaderboards {
err := nk.LeaderboardCreate( err := nk.LeaderboardCreate(
ctx, ctx,
lb, // leaderboard ID lb,
true, // authoritative true, // authoritative
"desc", // sort order "desc", // sort order
"incr", // operator "incr", // operator
"", // reset schedule (none) "", // reset schedule
map[string]interface{}{}, // metadata map[string]interface{}{}, // metadata
) )

View File

@@ -1,4 +1,4 @@
package game package structs
// Board is a generic 2D grid for turn-based games. // Board is a generic 2D grid for turn-based games.
// Cell data is stored as strings, but can represent anything (piece, move, state). // Cell data is stored as strings, but can represent anything (piece, move, state).

View File

@@ -1,4 +1,4 @@
package game package structs
// Player represents a participant in the match. // Player represents a participant in the match.
type Player struct { type Player struct {