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:
parent
18c75f6060
commit
2e2cd7fac2
18
board.go
18
board.go
@ -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
|
||||||
|
3
main.go
3
main.go
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user