Пример #1
0
        public IActionResult StartGame([FromRoute] string code, string adminCode)
        {
            var game = GameStore.GetGame(code);

            if (game == null)
            {
                return(NotFound());
            }
            if (game.Status != GameStatus.NotStarted)
            {
                return(StatusCode(403, "Can only start unstarted games"));
            }
            if (game.Players.First().ConnectionId != adminCode)
            {
                return(Unauthorized());
            }

            game.Status = GameStatus.NormalTurn;

            TimerStore.SetupAnswerTimeout(game);

            // TODO _gameClient.GameUpdated(game);

            return(Ok());
        }
Пример #2
0
        public TimerViewModel(TimerStore timerStore)
        {
            _timerStore  = timerStore;
            StartCommand = new StartCommand(this, _timerStore);

            _timerStore.RemainingSecondsChanged += TimerStore_RemainingSecondsChanged;
        }
Пример #3
0
        public IActionResult SendAnswer([FromRoute] string code, string playerCode, string answer, string rule)
        {
            var game = GameStore.GetGame(code);

            if (game == null)
            {
                return(NotFound());
            }
            if (game.CurrentPlayer.ConnectionId != playerCode)
            {
                return(Unauthorized());
            }
            if (game.Status == GameStatus.NameAnother && rule != null)
            {
                return(BadRequest("Adding rule not allowed when naming another"));
            }

            game.Turns.Add(new Turn(game.Turns.Count, game.CurrentPlayer, game.Status, answer, rule));
            game.CurrentPlayer = game.FindNextPlayer();

            TimerStore.SetupAnswerTimeout(game);

            // TODO _gameClient.GameUpdated(game);

            return(Ok());
        }
Пример #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _notifyIcon.Icon   = new Icon("Resources/icon.ico");
            _notifyIcon.Text   = "SingletonSean";
            _notifyIcon.Click += NotifyIcon_Click;

            _notifyIcon.ContextMenuStrip = new Forms.ContextMenuStrip();
            _notifyIcon.ContextMenuStrip.Items.Add("Status", Image.FromFile("Resources/icon.ico"), OnStatusClicked);
            //_notifyIcon.ContextMenuStrip.Items.Add(new Forms.ToolStripLabel("Status: Running"));
            //_notifyIcon.ContextMenuStrip.Items.Add(new Forms.ToolStripButton("Status: Running"));
            //_notifyIcon.ContextMenuStrip.Items.Add(new Forms.ToolStripDropDownButton("Status: Running", null,
            //    new Forms.ToolStripLabel("Label 1"),
            //    new Forms.ToolStripLabel("Label 2")));
            //_notifyIcon.BalloonTipClicked += NotifyIcon_BalloonTipClicked;

            _notifyIcon.Visible = true;

            _timerStore     = new TimerStore(new NotifyIconNotificationService(_notifyIcon));
            _timerViewModel = new TimerViewModel(_timerStore);

            MainWindow             = new MainWindow();
            MainWindow.DataContext = _timerViewModel;
            MainWindow.Show();

            base.OnStartup(e);
        }
Пример #5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _notifyIcon.Icon   = new Icon("Images/envelope_50px.ico");
            _notifyIcon.Text   = "PopUp Email";
            _notifyIcon.Click += NotifyIcon_Click;

            _notifyIcon.ContextMenuStrip = new Forms.ContextMenuStrip();
            _notifyIcon.ContextMenuStrip.Items.Add("Status", Image.FromFile("Images/envelope_50px.ico"), OnStatusClicked);


            _notifyIcon.Visible = true;

            _timerStore     = new TimerStore(new NotifyIconNotificationService(_notifyIcon));
            _timerViewModel = new TimerViewModel(_timerStore);

            MainWindow             = new MainWindow();
            MainWindow.DataContext = _timerViewModel;
            MainWindow.Show();

            base.OnStartup(e);
        }
Пример #6
0
        public IActionResult Challenge([FromRoute] string code, string playerCode, int turnId)
        {
            var game = GameStore.GetGame(code);

            if (game == null)
            {
                return(NotFound());
            }
            if (game.Turns.Last().TurnId != turnId)
            {
                return(StatusCode(403, "Cannot challenge answer other than latest"));
            }
            if (game.Turns.Last().TurnType == GameStatus.Challenge)
            {
                return(StatusCode(403, "Challenge can only be posited once per answer"));
            }
            if (game.Status == GameStatus.NameAnother)
            {
                return(StatusCode(403, "Name another answer cannot be challenged"));
            }

            Player player           = game.FindActivePlayer(playerCode);
            Player challengedPlayer = game.FindPreviousPlayer();

            if (player == null || player == challengedPlayer)
            {
                return(Unauthorized());
            }

            game.Status            = GameStatus.Challenge;
            game.CurrentPlayer     = challengedPlayer;
            game.ChallengingPlayer = player;

            TimerStore.SetupChallengeTimeout(game);

            // TODO _gameClient.GameUpdated(game);

            return(Ok());
        }
Пример #7
0
        public IActionResult Vote([FromRoute] string code, string playerCode, bool vote)
        {
            var game = GameStore.GetGame(code);

            if (game == null)
            {
                return(NotFound());
            }
            if (game.Status != GameStatus.Challenge)
            {
                return(StatusCode(403, "Can only vote if challenge is ongoing"));
            }

            Player player = game.FindActivePlayer(playerCode);

            if (player == null || player == game.CurrentPlayer)
            {
                return(Unauthorized());
            }
            if (game.Votes.Exists(v => v.Player == player))
            {
                return(Conflict("Cannot vote twice on one challenge"));
            }

            game.Votes.Add(new Vote(player, vote));

            // Check if everyone but challenged player has voted
            if (game.Votes.Count == game.CountActivePlayers() - 1)
            {
                game.ResolveChallenge();

                TimerStore.SetupAnswerTimeout(game);
            }

            // TODO _gameClient.GameUpdated(game);

            return(Ok());
        }
Пример #8
0
        public IActionResult RequestNameAnother([FromRoute] string code, string playerCode, int turnId)
        {
            var game = GameStore.GetGame(code);

            if (game == null)
            {
                return(NotFound());
            }
            if (game.Turns.Last().TurnId != turnId)
            {
                return(StatusCode(403, "Cannot request name another for rule other than latest"));
            }
            if (game.Turns.Last().TurnType == GameStatus.NameAnother)
            {
                return(StatusCode(403, "Name another can only be requested once per answer"));
            }
            if (game.Status == GameStatus.NameAnother)
            {
                return(Conflict("Name another has already been requested"));
            }

            Player player = game.FindActivePlayer(playerCode);

            if (player == null || player == game.CurrentPlayer)
            {
                return(Unauthorized());
            }

            game.Status        = GameStatus.NameAnother;
            game.CurrentPlayer = game.FindPreviousPlayer();

            TimerStore.SetupAnswerTimeout(game);

            // TODO _gameClient.GameUpdated(game);

            return(Ok());
        }
Пример #9
0
 public StartCommand(TimerViewModel viewModel, TimerStore timerStore)
 {
     _viewModel  = viewModel;
     _timerStore = timerStore;
 }