forked from yyhero/gridview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.go
51 lines (44 loc) · 751 Bytes
/
grid.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
package gridview
import "sync"
type grid struct {
gridId int
row int
col int
// 网格矩形坐标
minX int
maxX int
minY int
maxY int
// 集合
palyers map[string]bool
mutex sync.RWMutex
}
func (g *grid) AddPlayer(playerId string) {
g.mutex.RLock()
defer g.mutex.RUnlock()
g.palyers[playerId] = true
}
func (g *grid) DeletePlayer(playerId string) {
g.mutex.RLock()
defer g.mutex.RUnlock()
delete(g.palyers, playerId)
}
func NewGrid(_gridId int,
_minX int,
_maxX int,
_minY int,
_maxY int,
_row int,
_col int) *grid {
obj := &grid{
gridId: _gridId,
minX: _minX,
maxX: _maxX,
minY: _minY,
maxY: _maxY,
row: _row,
col: _col,
palyers: make(map[string]bool, 0),
}
return obj
}