Permalink
Browse files

cmd/tictactoe: Export page struct fields.

These are properties set by external user, rather than private internal
fields.

This change improves consistency.
  • Loading branch information...
dmitshur committed Oct 10, 2017
1 parent 72dce7c commit 65dc9b8d5aa41d2dce8a6492c64e3472b6f46dd0
Showing with 17 additions and 17 deletions.
  1. +13 −13 cmd/tictactoe/display.go
  2. +4 −4 cmd/tictactoe/game.go
View
@@ -12,26 +12,26 @@ import (
// page renders the entire page body.
type page struct {
board ttt.Board
turn ttt.State
clickable bool
condition ttt.Condition
errorMessage string
players [2]player
Board ttt.Board
Turn ttt.State
Clickable bool
Condition ttt.Condition
ErrorMessage string
Players [2]player
}
func (p page) Render() []*html.Node {
var statusMessage *html.Node
switch {
case p.errorMessage != "":
case p.ErrorMessage != "":
statusMessage = style(
`line-height: 60px; text-align: center; color: red;`,
htmlg.Div(htmlg.Text(p.errorMessage)),
htmlg.Div(htmlg.Text(p.ErrorMessage)),
)
case p.condition != ttt.NotEnd:
case p.Condition != ttt.NotEnd:
statusMessage = style(
`line-height: 60px; text-align: center;`,
htmlg.Div(htmlg.Text(p.condition.String())),
htmlg.Div(htmlg.Text(p.Condition.String())),
)
default:
statusMessage = style(`height: 60px;`, htmlg.Div())
@@ -43,17 +43,17 @@ func (p page) Render() []*html.Node {
// Player X.
style(
`display: inline-block; width: 200px;`,
htmlg.Span(p.players[0].Render(p.turn)...),
htmlg.Span(p.Players[0].Render(p.Turn)...),
),
// Board.
style(
`display: inline-block; margin-left: 30px; margin-right: 30px;`,
htmlg.Span(board{Board: p.board, Clickable: p.clickable}.Render()...),
htmlg.Span(board{Board: p.Board, Clickable: p.Clickable}.Render()...),
),
// Player O.
style(
`display: inline-block; width: 200px;`,
htmlg.Span(p.players[1].Render(p.turn)...),
htmlg.Span(p.Players[1].Render(p.Turn)...),
),
),
),
View
@@ -38,7 +38,7 @@ func playGame(players [2]player) (ttt.Condition, error) {
if runtime.GOARCH == "js" {
var document = dom.GetWindow().Document().(dom.HTMLDocument)
_, isCellClicker := players[i].Player.(ttt.CellClicker)
document.Body().SetInnerHTML(htmlg.Render(page{board: board, turn: players[i].Mark, clickable: isCellClicker, condition: condition, players: players}.Render()...))
document.Body().SetInnerHTML(htmlg.Render(page{Board: board, Turn: players[i].Mark, Clickable: isCellClicker, Condition: condition, Players: players}.Render()...))
}
turnStart := time.Now()
@@ -47,7 +47,7 @@ func playGame(players [2]player) (ttt.Condition, error) {
if err != nil {
if runtime.GOARCH == "js" {
var document = dom.GetWindow().Document().(dom.HTMLDocument)
document.Body().SetInnerHTML(htmlg.Render(page{board: board, errorMessage: err.Error(), players: players}.Render()...))
document.Body().SetInnerHTML(htmlg.Render(page{Board: board, ErrorMessage: err.Error(), Players: players}.Render()...))
}
return 0, err
}
@@ -58,7 +58,7 @@ func playGame(players [2]player) (ttt.Condition, error) {
if untilTurnEnd := time.Second - time.Since(turnStart); condition == ttt.NotEnd && untilTurnEnd > 0 {
if runtime.GOARCH == "js" {
var document = dom.GetWindow().Document().(dom.HTMLDocument)
document.Body().SetInnerHTML(htmlg.Render(page{board: board, condition: condition, players: players}.Render()...))
document.Body().SetInnerHTML(htmlg.Render(page{Board: board, Condition: condition, Players: players}.Render()...))
}
time.Sleep(untilTurnEnd)
@@ -70,7 +70,7 @@ func playGame(players [2]player) (ttt.Condition, error) {
fmt.Println(board)
if runtime.GOARCH == "js" {
var document = dom.GetWindow().Document().(dom.HTMLDocument)
document.Body().SetInnerHTML(htmlg.Render(page{board: board, condition: condition, players: players}.Render()...))
document.Body().SetInnerHTML(htmlg.Render(page{Board: board, Condition: condition, Players: players}.Render()...))
}
return condition, nil

0 comments on commit 65dc9b8

Please sign in to comment.