1
0
mirror of https://github.com/maaslalani/gambit.git synced 2025-01-18 02:58:41 +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 { type Board struct {
Players []Player Players []Player
Grid [dimensions][dimensions]string Grid [dimensions][dimensions]string
flipped bool
} }
func (b *Board) Draw() { func (b *Board) Draw() {
@ -39,16 +40,25 @@ func (b *Board) Draw() {
func (b *Board) String() string { func (b *Board) String() string {
var s = header 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++ { for col := firstCol; col < dimensions; col++ {
if col == firstCol { if col == firstCol {
s += faintStyle.Render(fmt.Sprintf(" %d ", dimensions-row)) s += faintStyle.Render(fmt.Sprintf(" %d ", rank+1))
} }
s += divider s += divider
if b.Grid[row][col] == "" { if b.Grid[rank][col] == "" {
s += " " s += " "
} else { } else {
s += b.Grid[row][col] s += b.Grid[rank][col]
} }
if col == lastCol { if col == lastCol {
s += divider s += divider

View File

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