示例#1
0
        public void SendDiceRoll(string rollFormula)
        {
            var    connectionId = Context.ConnectionId;
            Client client;

            if (!_services.TryGetClient(connectionId, out client))
            {
                throw new Exception("cannot send dice roll - unrecognised client connection");
            }

            var sessionId = client.SessionId;

            if (string.IsNullOrEmpty(sessionId))
            {
                throw new Exception("cannot send dice roll - client has not joined any sessions");
            }

            var model = new RollDiceCommand {
                Sender = client, DiceRollFormula = rollFormula, TimeStamp = DateTime.UtcNow
            };

            var session = _services.GetSession(sessionId);

            _services.HandleCommand(session, model);
        }
        /// <summary>
        /// toggles between the states of enable/disable of the connect/disconnect command buttons, with a slight delay to prevent connection spamming
        /// </summary>
        /// <param name="delay"></param>
        private async void ToggleBlockConnectionCommands(bool delay)
        {
            if (delay)
            {
                await Task.Factory.StartNew(() => Thread.Sleep(1000));
            }

            BlockConnectionCommands = !BlockConnectionCommands;

            ConnectCommand.RaiseCanExecuteChanged();
            DisconnectCommand.RaiseCanExecuteChanged();
            SendTextCommand.RaiseCanExecuteChanged();
            RollDiceCommand.RaiseCanExecuteChanged();
        }
示例#3
0
        private void StartNewGame(int _players, bool _ai = false)
        {
            players.Clear();
            CreatePlayer(_players);

            if (_ai)
            {
                // Inplement AI logic, Yard

                canRollDice = true;
            }
            RollDiceCommand.CanExecute(new Object());

            CurrentPlayer = SelectedPlayer = players.First();
            viewYathzee.lbPlayer.SelectedIndex = currentPlayer.PlayerId - 1;

            RollDices();
        }