initial room with tests

incorrect_closing_investigation
Evgeny Kovalev 2 years ago
parent b26a6cf65e
commit df6256224c
  1. 44
      internal/room/room.go
  2. 10
      internal/room/room_test.go

@ -1,6 +1,24 @@
package room
import "daydev.org/shipsgs/internal/player"
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"`
@ -11,3 +29,27 @@ type Room struct {
//Room state
}
func (r *Room) PlayerJoin() {
}
func (r *Room) PlayerLeave() {
}
func (r *Room) TextAnnounce() {
}
func (r *Room) Update() {
}
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]
}

@ -0,0 +1,10 @@
package room
import "testing"
func TestRandomName(t *testing.T) {
s := RandomName()
if s == "" {
t.Error("Expected string, got nil", s)
}
}
Loading…
Cancel
Save