Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major API changes #176

Merged
merged 12 commits into from
Mar 31, 2022
Prev Previous commit
Next Next commit
wip on fixing terminalgame
gucio321 committed Mar 31, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 388d2926fabcbdb1d641883a8462c54c19f99557
14 changes: 7 additions & 7 deletions internal/terminalgame/game/game.go
Original file line number Diff line number Diff line change
@@ -3,13 +3,13 @@ package game
import (
"bufio"
"fmt"
"github.com/gucio321/tic-tac-go/pkg/core/board/letter"
"log"
"os"

"github.com/gucio321/go-clear"
"github.com/gucio321/terminalmenu/pkg/menuutils"

"github.com/gucio321/tic-tac-go/pkg/core/players/player"
"github.com/gucio321/tic-tac-go/pkg/game"
)

@@ -20,10 +20,10 @@ type TTG struct {
}

// NewTTG creates a new TTG.
func NewTTG(w, h, chainLen byte, player1Type, player2Type player.Type) *TTG {
func NewTTG(w, h, chainLen byte, playerXType, playerOType game.PlayerType) *TTG {
result := &TTG{
reader: bufio.NewReader(os.Stdin),
Game: game.Create(player1Type, player2Type),
Game: game.Create(playerXType, playerOType),
}

result.SetBoardSize(int(w), int(h), int(chainLen)).OnContinue(func() {
@@ -41,13 +41,13 @@ func NewTTG(w, h, chainLen byte, player1Type, player2Type player.Type) *TTG {
func (t *TTG) Run() {
endGame := make(chan bool, 1)

t.Game.Result(func(p *player.Player) {
t.Game.Result(func(l letter.Letter, name string) {
// handle game end
switch p {
case nil:
switch l {
case letter.LetterNone:
fmt.Println("DRAW")
default:
fmt.Println(p.Name() + " won")
fmt.Println(name + " won")
}

if err := menuutils.PromptEnter("Press ENTER to continue "); err != nil {
7 changes: 4 additions & 3 deletions internal/terminalgame/menu/menu.go
Original file line number Diff line number Diff line change
@@ -20,9 +20,10 @@ import (
terminalmenu "github.com/gucio321/terminalmenu/pkg"
"github.com/gucio321/terminalmenu/pkg/menuutils"

"github.com/gucio321/tic-tac-go/internal/terminalgame/game"
gameimpl "github.com/gucio321/tic-tac-go/internal/terminalgame/game"
"github.com/gucio321/tic-tac-go/pkg/core/board"
"github.com/gucio321/tic-tac-go/pkg/core/players/player"
"github.com/gucio321/tic-tac-go/pkg/game"
)

const githubURL = "https://github.com/gucio321/tic-tac-go"
@@ -83,12 +84,12 @@ func (m *Menu) Run() {
}

func (m *Menu) runPVP() {
pvp := game.NewTTG(m.width, m.height, m.chainLen, player.PlayerPerson, player.PlayerPerson)
pvp := game.NewTTG(m.width, m.height, m.chainLen, game.PlayerTypeHuman, player.PlayerPerson)
pvp.Run()
}

func (m *Menu) runPVC() {
var g *game.TTG
var g *gameimpl.TTG

// nolint:gomnd // two players in game
r := rand.Intn(2) // nolint:gosec // it is ok