Skip to content

Commit

Permalink
A bit more wire-up of tictactoe game. Part of #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomoros committed Jan 31, 2017
1 parent a277e83 commit 1bc56cc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
20 changes: 18 additions & 2 deletions examples/tictactoe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const gameName = "tictactoe"

const DIM = 3

type gameDelegate struct {
boardgame.DefaultGameDelegate
}

func (g *gameDelegate) DistributeComponentToStarterStack(payload boardgame.StatePayload, c *boardgame.Component) error {
//TODO: actually sort the tokens into the right stacks
return nil
}

func ticTacToeGame() *boardgame.Game {

chest := boardgame.NewComponentChest(gameName)
Expand Down Expand Up @@ -44,6 +53,8 @@ func ticTacToeGame() *boardgame.Game {

chest.AddDeck("tokens", tokens)

chest.Finish()

starterPayload := &statePayload{
game: &gameState{
Slots: boardgame.NewSizedStack(tokens, DIM*DIM),
Expand All @@ -63,12 +74,17 @@ func ticTacToeGame() *boardgame.Game {
}

game := &boardgame.Game{
Name: gameName,
State: boardgame.NewStarterState(starterPayload),
Name: gameName,
State: boardgame.NewStarterState(starterPayload),
Delegate: &gameDelegate{},
}

game.SetChest(chest)

if err := game.SetUp(); err != nil {
panic("Game couldn't be set up")
}

return game

}
14 changes: 14 additions & 0 deletions examples/tictactoe/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tictactoe

import (
"testing"
)

func TestGame(t *testing.T) {

game := ticTacToeGame()

if game == nil {
t.Error("Didn't get tictactoe game back")
}
}

0 comments on commit 1bc56cc

Please sign in to comment.