Beispiel #1
0
 public RoomData()
 {
     ID = "";
     Password = "";
     Owner = new PlayerData();
     Players = new List<PlayerData>();
     GameStarted = false;
 }
Beispiel #2
0
        public Player(string playerName, IWebSocketConnection socket, Settings settings)
        {
            Settings = settings;
            Socket = socket;

            Data = new PlayerData();
            Data.Name = playerName;
            Data.ID = Guid.NewGuid().ToString();

            socket.OnClose += () =>
            {
                if (OnConnectionClosed != null)
                    OnConnectionClosed(this, new PlayerConnectionClosed(this, PlayerCloseReason.Disconnected));
            };

            socket.OnMessage += (json) => OnRecieveMessage(json);
            socket.OnBinary += (bytes) => OnRecieveMessage(Encoding.UTF8.GetString(bytes));
        }
Beispiel #3
0
            public RequestRoomList(PlayerData playerInfo)
            {

            }
Beispiel #4
0
            public LeaveRoom(PlayerData playerInfo)
            {

            }
Beispiel #5
0
 public void UpdatePlayerInfo(PlayerData playerData)
 {
     var message = new ServerMessage.UpdatePlayerInfo(playerData);
     Socket.Send(message.AsJson());
 }
Beispiel #6
0
 public UpdatePlayerInfo(PlayerData playerData)
 {
     PlayerData = playerData;
 }
Beispiel #7
0
 public SendChoices(PlayerData creator, List<AnswerData> choices)
 {
     Creator = creator;
     Choices = choices;
 }
Beispiel #8
0
 public bool HasPlayer(PlayerData player)
 {
     return Players.Exists(x => x.Data.ID == player.ID);
 }
Beispiel #9
0
 void EchoActionToAll(PlayerData actor, PlayerAction action)
 {
     Logger.Log(this, "{0} ({1})", actor.Name, action);
     Players.ForEach(x => x.SendAction(actor, action, PlayerActionContext.Room));
 }
Beispiel #10
0
        // Replaces any tokens such as "random player name" appropriately replaced.
        public string ReplaceTokens(PlayerData player, List<PlayerData> players)
        {
            // TODO: Move somewhere more appropriate.
            var tokenPlayerName = "<RANDOM_PLAYER_NAME>";

            if (Text.Contains(tokenPlayerName))
            {
                // Replace with random player that isn't this player
                var playersExceptOwner = players.Where(x => x != player).ToList();

                var rnd = new Random().Next(playersExceptOwner.Count);
                Text = Text.Replace(tokenPlayerName, playersExceptOwner[rnd].Name.ToLower());
            }

            return Text;
        }
Beispiel #11
0
 public AnswerData(PlayerData author, string answer) : this()
 {
     Author = author;
     Answer = answer;
 }
Beispiel #12
0
 public AnswerData()
 {
     Author = new PlayerData();
     Answer = string.Empty;
     Choosers = new List<PlayerData>();
 }
Beispiel #13
0
 public void NotifyPlayerGameAction(PlayerData actor, GamePlayerAction action)
 {
     var message = new ServerMessage.Game.PlayerAction(actor, action);
     Socket.Send(message.AsJson());
 }
Beispiel #14
0
 public void SendChoices(PlayerData creator, List<AnswerData> answers)
 {
     var message = new ServerMessage.Game.SendChoices(creator, answers);
     Socket.Send(message.AsJson());
 }
Beispiel #15
0
 public void SendChat(PlayerData player, string chat)
 {
     var message = new ServerMessage.NotifyChatMessage(player, chat);
     Socket.Send(message.AsJson());
 }
Beispiel #16
0
 Room FindRoomContainingPlayer(PlayerData player)
 {
     return Rooms.Find(x => x.HasPlayer(player));
 }
Beispiel #17
0
 public void Leave(PlayerData leavingPlayer, RoomLeaveReason reason = RoomLeaveReason.Normal)
 {
     var player = Players.Find(x => x.Data.ID == leavingPlayer.ID);
     player.SendRoomLeaveReason(reason);
     OnPlayerConnectionClosed(this, new PlayerConnectionClosed(player, PlayerCloseReason.Left));
 }
Beispiel #18
0
 public DrawingData(PlayerData creator, byte[] image, PromptData prompt)
 {
     Creator = creator;
     Image = Convert.ToBase64String(image);
     Prompt = prompt;
 }
Beispiel #19
0
 bool IsOwner(PlayerData player)
 {
     return Owner.Data.ID == player.ID;
 }
Beispiel #20
0
 public SendAction(PlayerData player, GameAction action)
 {
     Player = player;
     Action = action;
 }
Beispiel #21
0
 public NotifyPlayerAction(PlayerData player, PlayerAction action, PlayerActionContext context)
 {
     Player = player;
     Action = action;
     Context = context;
 }
Beispiel #22
0
 public CreateRoom(PlayerData playerInfo, string password)
 {
     Password = password;
 }
Beispiel #23
0
 public PlayerAction(PlayerData actor, GamePlayerAction action)
 {
     Actor = actor;
     Action = action;
 }
Beispiel #24
0
 public JoinRoom(PlayerData playerInfo, string roomId, string password = "")
 {
     RoomId = roomId;
     Password = password;
 }
Beispiel #25
0
 public NotifyChatMessage(PlayerData player, string message)
 {
     Player = player;
     Message = message;
 }
Beispiel #26
0
 /// <summary>
 /// Sends a message to the player about a particular action.
 /// </summary>
 /// <param name="actor">The player that committed the action.</param>
 /// <param name="action">The type of action.</param>
 public void SendAction(PlayerData actor, PlayerAction action, PlayerActionContext context)
 {
     var message = new ServerMessage.NotifyPlayerAction(actor, action, context);
     Socket.Send(message.AsJson());
 }