-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslot.go
65 lines (55 loc) · 1.22 KB
/
slot.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
57
58
59
60
61
62
63
64
65
package slotkit
// Slot :
type Slot struct {
cells Cells
reels []Cells
}
// NewSlot : 建立相同滾輪長度的 slot
func NewSlot(reels int, rows int) *Slot {
layout := make([]int, reels)
for i := 0; i < reels; i++ {
layout[i] = rows
}
return NewSlotFlex(layout)
}
// NewSlotFlex : 建立滾輪長度不同的 slot
func NewSlotFlex(rows []int) *Slot {
length := 0
for _, size := range rows {
length += size
}
s := &Slot{}
s.cells = NewCells(length)
s.reels = make([]Cells, len(rows))
index := 0
for i := range s.reels {
length = rows[i]
s.reels[i] = s.cells[index : index+length : index+length] // s.Slice(index, length)
index += length
}
return s
}
// Reel : 取得指定滾輪
func (s Slot) Reel(index int) Cells {
return s.reels[index]
}
// Reels : 取得所有滾輪
func (s Slot) Reels() []Cells {
return s.reels
}
// TotalReels : 取得滾輪數量
func (s Slot) TotalReels() int {
return len(s.reels)
}
// Cells : 取得所有盤面內容
func (s Slot) Cells() Cells {
return s.cells
}
func (s Slot) String() string {
var str string = "["
for _, reel := range s.reels {
str += " " + reel.String()
}
str += " ]"
return str
}