Exemple #1
0
        public AutoPlayerLogic(GameTable gameTable, GameLogic gameLogic, DiceLogic diceLogic, bool white)
        {
            firstMove      = true;
            rand           = new Random();
            this.gameTable = gameTable;

            Timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(2)
            };
            //Timer.Tick += ComputerTurn;

            if (white)
            {
                MyCheckerColor = gameTable.White;
                firstMove      = true;
            }
            else
            {
                MyCheckerColor = gameTable.Black;
                firstMove      = false;
            }

            this.gameLogic = gameLogic;
            this.diceLogic = diceLogic;

            if (white)
            {
                BarColl = gameTable.WhiteBar;
            }
            else
            {
                BarColl = gameTable.BlackBar;
            }
        }
        /// <summary>
        /// Generates random numbers in dice range
        /// </summary>
        /// <param name="user">user name</param>
        /// <param name="opponent">opponent name</param>
        public void Roll(string user, string opponent)
        {
            if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(opponent))
            {
                var game = GameMng.GetGame(user, opponent);
                if (game == null)
                {
                    return;
                }

                var diceLogic   = new DiceLogic(_rand);
                var diceNumbers = diceLogic.GetRandomDices();

                var callback = OperationContext.Current.GetCallbackChannel <IClientCallback>();
                try
                {
                    if (_callback.ContainsKey(user))
                    {
                        if (diceNumbers[0] == diceNumbers[1])
                        {
                            game.DoubleDice = new DoubleDice(user, opponent);

                            _callback[user].GameInfoUpdateFromServer(opponent, "You have the double.\nMove twice please.");
                            if (_callback.ContainsKey(opponent))
                            {
                                _callback[opponent].GameInfoUpdateFromServer(user, "Your opponent has the double.\nWait please.");
                            }
                        }
                        else
                        {
                            game.DifferentDice = new DifferentDice(user, opponent);
                        }

                        if (_callback.ContainsKey(opponent))
                        {
                            _callback[opponent].RecieveRoll(user, diceNumbers);
                        }

                        _callback[user].RecieveRoll(opponent, diceNumbers);
                    }
                }
                catch (Exception ex)
                {
                    callback.RecieveError(ex.Message);
                    if (_callback.ContainsKey(opponent))
                    {
                        _callback[opponent].RecieveError(ex.Message);
                    }
                }
            }
        }
 public void SetUp()
 {
     _diceLogic  = new DiceLogic();
     _diceHelper = new DiceHelper();
 }