You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
972 B
73 lines
972 B
1 year ago
|
package gameServer
|
||
1 year ago
|
|
||
1 year ago
|
import (
|
||
|
"math/rand"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const ()
|
||
|
|
||
|
var Names = map[int]string{
|
||
|
1: "Lisbon",
|
||
|
2: "Porto",
|
||
|
3: "Azores",
|
||
|
4: "Lagos",
|
||
|
5: "Guimaraes",
|
||
|
6: "Algarve",
|
||
|
7: "DouroRiver",
|
||
|
8: "Braga",
|
||
|
}
|
||
1 year ago
|
|
||
|
type Room struct {
|
||
|
Name string `json:"Name"`
|
||
|
|
||
|
//Players
|
||
1 year ago
|
players map[*Player]bool
|
||
1 year ago
|
|
||
|
//Room state
|
||
|
|
||
1 year ago
|
// Channel to register players and their connection
|
||
1 year ago
|
join chan *Player
|
||
1 year ago
|
|
||
|
// Channel to un register players
|
||
1 year ago
|
leave chan *Player
|
||
1 year ago
|
|
||
|
// Channel to update All in the room
|
||
|
updateAll chan bool
|
||
1 year ago
|
}
|
||
1 year ago
|
|
||
|
func (r *Room) PlayerJoin() {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (r *Room) PlayerLeave() {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (r *Room) TextAnnounce() {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (r *Room) Update() {
|
||
1 year ago
|
for {
|
||
1 year ago
|
/*
|
||
|
select {
|
||
|
case pj := <-r.join:
|
||
|
// player joins
|
||
|
case pl := <-r.leave:
|
||
|
// player leaves
|
||
|
case <-r.updateAll:
|
||
|
// update the room
|
||
|
}
|
||
|
*/
|
||
1 year ago
|
}
|
||
1 year ago
|
}
|
||
|
|
||
|
func RandomName() string {
|
||
|
s := rand.NewSource(time.Now().UnixNano())
|
||
|
r := rand.New(s)
|
||
|
|
||
|
i := r.Intn(8) // Hardcoded qty of names for lobbies
|
||
|
return Names[i]
|
||
|
}
|