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