Ejemplo n.º 1
0
        public void GetGameTable(string user, string opponent)
        {
            if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(opponent))
            {
                try
                {
                    if (_callback.ContainsKey(user))
                    {
                        var game = GameMng.GetGame(user, opponent);

                        var gameTable = GameMng.GetGameTableForSend(user, opponent);

                        if (gameTable != null)
                        {
                            var whiteCheckers = gameTable[0];
                            var blackCheckers = gameTable[1];
                            var barCheckers   = gameTable[2];
                            _callback[user].UpdateTable(user, opponent, whiteCheckers, blackCheckers, barCheckers);
                            if (_callback.ContainsKey(opponent))
                            {
                                _callback[opponent].UpdateTable(opponent, user, whiteCheckers, blackCheckers, barCheckers);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _callback[user].RecieveError(ex.Message);
                    _callback[opponent].RecieveError(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Computer Player Logic
        /// </summary>
        /// <param name="computer">name of comp player</param>
        /// <param name="opponent">name of user player</param>
        /// <param name="diceNumbers">number of dice</param>
        public void MoveCheckerAuto(string computer, string opponent)
        {
            if (_callback.ContainsKey(opponent))
            {
                var game = GameMng.GetGame(computer, opponent);
                if (game == null)
                {
                    return;
                }

                var diceNumbers = game.DiceLogic.GetRandomDices();

                if (diceNumbers[0] == diceNumbers[1])
                {
                    diceNumbers.AddRange(diceNumbers);
                }

                _callback[opponent].RecieveRoll(Player.autoPlayer.ToString(), diceNumbers);

                bool result = false;

                try
                {
                    foreach (var number in diceNumbers)
                    {
                        result = GameMng.CheckersMoovingLogicAuto(computer, opponent, number);
                        if (result)
                        {
                            var gameTable = GameMng.GetGameTableForSend(computer, opponent);

                            if (gameTable != null)
                            {
                                var whiteCheckers = gameTable[0];
                                var blackCheckers = gameTable[1];
                                var barCheckers   = gameTable[2];
                                _callback[opponent].UpdateTable(opponent, computer, whiteCheckers, blackCheckers, barCheckers);
                            }
                        }
                        if (GameMng.IsGameOver(opponent, computer))
                        {
                            _callback[opponent].GameOverFromServer(opponent, computer, false);

                            GameMng.DeleteGame(computer, opponent);
                        }
                    }
                    if (_callback.ContainsKey(opponent))
                    {
                        _callback[opponent].SetMasterFromServer(opponent, computer);
                    }
                }
                catch (Exception ex)
                {
                    _callback[opponent].RecieveError(ex.Message);
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        /// <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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void MoveCheckerFromBar(string user, string opponent, int currIndex, int futuredIndex)
        {
            if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(opponent))
            {
                var callback = OperationContext.Current.GetCallbackChannel <IClientCallback>();
                try
                {
                    if (_callback.ContainsKey(user))
                    {
                        var game       = GameMng.GetGame(user, opponent);
                        var doubleDice = game.DoubleDice;
                        var diffDice   = game.DifferentDice;

                        bool result = false;

                        try
                        {
                            result = GameMng.CheckersMoovingFromBarLogic(user, opponent, currIndex, futuredIndex);
                        }
                        catch (Exception ex)
                        {
                            _callback[user].RecieveGameError(ex.Message);
                            _callback[user].MoveEnableFromServer(user, opponent);
                            if (_callback.ContainsKey(opponent))
                            {
                                _callback[opponent].SetWaiterFromServer(opponent, user);
                            }
                            return;
                        }
                        if (result)
                        {
                            var gameTable = GameMng.GetGameTableForSend(user, opponent);

                            if (gameTable != null)
                            {
                                var whiteCheckers = gameTable[0];
                                var blackCheckers = gameTable[1];
                                var barCheckers   = gameTable[2];
                                _callback[user].UpdateTable(user, opponent, whiteCheckers, blackCheckers, barCheckers);
                                if (_callback.ContainsKey(opponent))
                                {
                                    _callback[opponent].UpdateTable(opponent, user, whiteCheckers, blackCheckers, barCheckers);
                                }

                                if (doubleDice != null && doubleDice.IsMoovingFinish())
                                {
                                    // GameMng.DeleteDoubleDice(user, opponent);
                                    _callback[user].SetWaiterFromServer(user, opponent);
                                    if (_callback.ContainsKey(opponent))
                                    {
                                        _callback[opponent].SetMasterFromServer(opponent, user);
                                    }
                                    //turn computer moving
                                    else if (opponent == Player.autoPlayer.ToString())
                                    {
                                        MoveCheckerAuto(opponent, user);
                                    }
                                }
                                else if (diffDice != null && diffDice.IsMoovingFinish())
                                {
                                    //GameMng.DeleteDifferentDice(user, opponent);
                                    _callback[user].SetWaiterFromServer(user, opponent);
                                    if (_callback.ContainsKey(opponent))
                                    {
                                        _callback[opponent].SetMasterFromServer(opponent, user);
                                    }
                                    //turn computer moving
                                    else if (opponent == Player.autoPlayer.ToString())
                                    {
                                        MoveCheckerAuto(opponent, user);
                                    }
                                }
                            }
                        }
                        else
                        {
                            _callback[user].SetMasterFromServer(user, opponent);
                            _callback[user].RecieveGameError("You can't move to this posision");
                        }
                    }
                }
                catch (Exception ex)
                {
                    callback.RecieveGameError(ex.Message);
                    if (_callback.ContainsKey(opponent))
                    {
                        _callback[opponent].RecieveGameError(ex.Message);
                    }
                }
            }
        }