func New(g interfaces.Game) *Player { p := &Player{} /* Spectator stuff */ p.Spectator = spectator.New() /* Player stuff */ p.SetPlayerId(uidg.NextUid()) p.SetLastTickTime(time.Now()) p.AvailableActions = append(p.AvailableActions, order.NewAction(".")) p.AvailableActions = append(p.AvailableActions, order.NewAction("mu")) p.AvailableActions = append(p.AvailableActions, order.NewAction("*u")) p.AvailableActions = append(p.AvailableActions, order.NewAction("lu")) /* Entity stuff */ p.Entity = entity.New(entity.UIDG.NextUid(), g) p.SetType(interfaces.ENTITY_TYPE_PLAYER) p.SetName("Player " + strconv.Itoa(p.GetPlayerId())) p.SetMaxArdour(100) p.SetArdour(100) return p }
/* Initialize a spectator connection; disconnected from players */ func SpectatorConnect(ws *websocket.Conn) { var message string if err := websocket.Message.Receive(ws, &message); err != nil { log.Fatal("Reading Socket Error:", err) } else { spec := spectator.New() spec.SetWebSocketConnection(ws) spec.SendMessage(serializable.NewGameInfo().Json()) GAME.AddSpectator(spec) log.Println("Adding board spectator") /* Keep reading */ for { if websocket.Message.Receive(ws, &message) != nil { break } } } /* TODO should probably remove spectators from the game, or limit how many * can be added */ log.Printf("Closing spectator websocket") ws.Close() }