Skip to content

Commit

Permalink
Defining coordinates for cells
Browse files Browse the repository at this point in the history
  • Loading branch information
kbca committed Mar 16, 2022
1 parent dc30c05 commit 5c08324
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion domain/board.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package domain

import "math/rand"
import (
"math/rand"
)

type cell struct {
coordX int
Expand All @@ -12,7 +14,23 @@ type Board struct {
cells [81]cell
}

func (board *Board) defineCoords() {
currentX, currentY := 1, 1
for i := range board.cells {
board.cells[i].coordX = currentX
board.cells[i].coordY = currentY

currentX++
if currentX > 9 {
currentX = 1
currentY++
}
}
}

func (board *Board) RandomizeBoard() {
board.defineCoords()

for i := range board.cells {
board.cells[i].number = rand.Intn(9) + 1
}
Expand Down

0 comments on commit 5c08324

Please sign in to comment.