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); } } }
/// <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; } } }
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); } } } }