-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdestinyPool.go
More file actions
36 lines (32 loc) · 799 Bytes
/
destinyPool.go
File metadata and controls
36 lines (32 loc) · 799 Bytes
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
package main
import (
"container/list"
"main/util"
"math/rand"
"time"
)
type DestinyPool struct {
// LIST of *Destiny
AvailableDestinies *list.List
// LIST of *Destiny
UsedDestinies *list.List
}
func NewDestinyPool() *DestinyPool {
rand.Seed(int64(time.Now().Nanosecond()))
available := list.New()
used := list.New()
//todo: 初始化天命
for i := 0; i < 10; i++ {
available.PushBack(&Destiny{})
}
return &DestinyPool{available, used}
}
func (this *DestinyPool) GetNextDestiny() *Destiny {
length := this.AvailableDestinies.Len()
n := rand.Intn(length)
destinyElement := util.GetListElementAt(this.AvailableDestinies, n)
this.AvailableDestinies.Remove(destinyElement)
this.UsedDestinies.PushBack(destinyElement.Value)
r, _ := destinyElement.Value.(*Destiny)
return r
}