Exemplo n.º 1
0
        public static Room GetRoomFromConnection(string connectionId)
        {
            var room = RoomConnections.Where(w => w.Key == connectionId);

            if (!room.Any())
            {
                return(null);
            }

            var roomCode = room.Single().Value;

            return(ApplicationService.FindRoom(roomCode));
        }
Exemplo n.º 2
0
        public static Writer GetWriterFromConnection(string connectionId)
        {
            var writer = WriterConnections.Where(w => w.Value == connectionId);

            if (!writer.Any())
            {
                return(null);
            }

            var writerId = writer.Single().Key;

            return(ApplicationService.FindWriter(writerId));
        }
Exemplo n.º 3
0
        public static Room Create(string roomName, Writer owner)
        {
            var room = new Room {
                Code = GenerateCode(), Name = roomName, Owner = owner
            };
            Task taskA = new Task(() => { while (true)
                                          {
                                              ApplicationService.GameUpdate(room); Thread.Sleep(1000);
                                          }
                                  });

            taskA.Start();
            return(room);
        }
Exemplo n.º 4
0
        public static ServerUpdate GetUpdate(Room room, Writer writer)
        {
            var secondsToAction    = (room.NextActionTime - DateTime.Now).Seconds;
            var timeToAction       = secondsToAction <= 0;
            var fragmentsThisRound = new List <StoryFragment>();

            fragmentsThisRound.AddRange(room.FrameFragments);
            var storyUpdated = ApplicationService.IsStoryUpdated(room, writer);

            return(new ServerUpdate
            {
                PresentWriters = room.PresentWriters,
                AbsentWriters = room.AbsentWriters,
                TimeToVote = timeToAction,
                SecondsToVote = secondsToAction,
                FragmentsThisRound = room.FrameFragments,
                StoryUpdated = storyUpdated
            });
        }