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
1009 B
73 lines
1009 B
package room |
|
|
|
import ( |
|
"math/rand" |
|
"time" |
|
|
|
"daydev.org/shipsgs/internal/player" |
|
) |
|
|
|
const () |
|
|
|
var Names = map[int]string{ |
|
1: "Lisbon", |
|
2: "Porto", |
|
3: "Azores", |
|
4: "Lagos", |
|
5: "Guimaraes", |
|
6: "Algarve", |
|
7: "DouroRiver", |
|
8: "Braga", |
|
} |
|
|
|
type Room struct { |
|
Name string `json:"Name"` |
|
|
|
//Players |
|
players map[*player.Player]bool |
|
|
|
//Room state |
|
|
|
// Channel to register players and their connection |
|
join chan *player.Player |
|
|
|
// Channel to un register players |
|
leave chan *player.Player |
|
|
|
// Channel to update All in the room |
|
updateAll chan bool |
|
} |
|
|
|
func (r *Room) PlayerJoin() { |
|
|
|
} |
|
|
|
func (r *Room) PlayerLeave() { |
|
|
|
} |
|
|
|
func (r *Room) TextAnnounce() { |
|
|
|
} |
|
|
|
func (r *Room) Update() { |
|
for { |
|
select { |
|
case pj := <-r.join: |
|
// player joins |
|
case pl := <-r.leave: |
|
// player leaves |
|
case <-r.updateAll: |
|
// update the room |
|
} |
|
|
|
} |
|
} |
|
|
|
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] |
|
}
|
|
|