示例#1
0
        private void StartGame()
        {
            Game.ThinkStart = DateTime.Now;
            var gameDto = Game.ToDto();
            var action  = new GameCreatedActionDto
            {
                game = gameDto
            };

            action.myColor = PlayerColor.black;
            _ = Send(Client1, action);
            action.myColor = PlayerColor.white;
            _ = Send(Client2, action);
            Game.PlayState = Game.State.FirstThrow;
            // todo: visa på clienten även när det blir samma
            while (Game.PlayState == Game.State.FirstThrow)
            {
                Game.RollDice();
                var rollAction = new DicesRolledActionDto
                {
                    dices        = Game.Roll.Select(d => d.ToDto()).ToArray(),
                    playerToMove = (PlayerColor)Game.CurrentPlayer,
                    validMoves   = Game.ValidMoves.Select(m => m.ToDto()).ToArray(),
                    moveTimer    = Game.ClientCountDown
                };
                _ = Send(Client1, rollAction);
                _ = Send(Client2, rollAction);
            }
            moveTimeOut = new CancellationTokenSource();
            _           = Utils.RepeatEvery(500, () =>
            {
                TimeTick();
            }, moveTimeOut);
        }
示例#2
0
        private void SendNewRoll()
        {
            Game.RollDice();
            var rollAction = new DicesRolledActionDto
            {
                dices        = Game.Roll.Select(d => d.ToDto()).ToArray(),
                playerToMove = (PlayerColor)Game.CurrentPlayer,
                validMoves   = Game.ValidMoves.Select(m => m.ToDto()).ToArray(),
                moveTimer    = Game.ClientCountDown
            };

            if (!IsAi(Game.BlackPlayer))
            {
                _ = Send(Client1, rollAction);
            }
            if (!IsAi(Game.WhitePlayer))
            {
                _ = Send(Client2, rollAction);
            }
        }