-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.go
56 lines (47 loc) · 1.04 KB
/
game.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package proxx
import (
"github.com/hajimehoshi/ebiten/v2"
)
const (
rowsNum = 10
colsNum = 10
blackHolesNum = 10
)
type Game struct {
board *Board
renderer *WindowBoardRenderer
}
func NewGame() *Game {
g := &Game{}
bc := BoardConfig{
RowsNum: rowsNum,
ColsNum: colsNum,
BlackHolesNum: blackHolesNum,
}
g.board = NewBoard(bc)
g.renderer = NewWindowBoardRenderer()
return g
}
func (g *Game) Update() error {
if g.board.IsComplete() {
return nil
}
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
x, y := ebiten.CursorPosition()
i := x / (tileSize + tileMargin)
j := y / (tileSize + tileMargin)
if !g.board.Click(i, j) {
g.board.Open()
g.board.isGameOver = true
}
}
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
g.renderer.Render(screen, g.board)
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
w := tileSize*rowsNum + tileMargin*rowsNum + tileMargin
h := tileSize*colsNum + tileMargin*colsNum + tileMargin
return w, h
}