1
0
mirror of https://github.com/maaslalani/gambit.git synced 2024-12-30 21:19:52 +02:00

feat: flip board

This commit is contained in:
Maas Lalani 2021-11-27 00:08:07 -05:00
parent 18c75f6060
commit 2e2cd7fac2
No known key found for this signature in database
GPG Key ID: F53774FA051C052A
2 changed files with 17 additions and 4 deletions

View File

@ -27,6 +27,7 @@ var faintStyle = lipgloss.NewStyle().Faint(true)
type Board struct {
Players []Player
Grid [dimensions][dimensions]string
flipped bool
}
func (b *Board) Draw() {
@ -39,16 +40,25 @@ func (b *Board) Draw() {
func (b *Board) String() string {
var s = header
for row := firstRow; row < dimensions; row++ {
var ranks []int
if b.flipped {
ranks = []int{0, 1, 2, 3, 4, 5, 6, 7}
} else {
ranks = []int{7, 6, 5, 4, 3, 2, 1, 0}
}
for row, rank := range ranks {
for col := firstCol; col < dimensions; col++ {
if col == firstCol {
s += faintStyle.Render(fmt.Sprintf(" %d ", dimensions-row))
s += faintStyle.Render(fmt.Sprintf(" %d ", rank+1))
}
s += divider
if b.Grid[row][col] == "" {
if b.Grid[rank][col] == "" {
s += " "
} else {
s += b.Grid[row][col]
s += b.Grid[rank][col]
}
if col == lastCol {
s += divider

View File

@ -32,6 +32,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "ctrl+c", "q", "esc":
return m, tea.Quit
case "ctrl+f":
m.Board.flipped = !m.Board.flipped
return m, nil
}
}