public void RollHowFirstComp(string user, string computer) { if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(computer)) { var callback = OperationContext.Current.GetCallbackChannel <IClientCallback>(); var arrayResult = GameMng.RollHowFirst(user, computer); var number1 = int.Parse(arrayResult[0]); var number2 = int.Parse(arrayResult[1]); int[] resultToSend = new int[2]; resultToSend[0] = (number1 == 0) ? 1 : number1; resultToSend[1] = (number2 == 0) ? 1 : number2; //Send to User result of first roll _callback[user].RecieveRollHowFirst(user, computer, resultToSend); //Computer rolling arrayResult = GameMng.RollHowFirst(computer, user); number1 = int.Parse(arrayResult[0]); number2 = int.Parse(arrayResult[1]); resultToSend = new int[2]; resultToSend[0] = (number1 == 0) ? 1 : number1; resultToSend[1] = (number2 == 0) ? 1 : number2; //Send to User result of second roll _callback[user].RecieveRollHowFirst(user, computer, resultToSend); if (arrayResult[2] != string.Empty) { var winnerName = arrayResult[2]; if (winnerName == user) { _callback[user].CloseHowToFirstFromServer(user, computer, true); GameMng.DeleteHowToFirst(user, computer); GameMng.AddGame(user, computer); } else { _callback[user].CloseHowToFirstFromServer(user, computer, false); GameMng.DeleteHowToFirst(user, computer); GameMng.AddGame(computer, user); //MoveCheckerAuto(computer, user); } } else { if (number1 == number2) { _callback[user].GameInfoUpdateFromServer(computer, "The numbers are equals. Try again"); } } } }
/// <summary> /// Starts the game /// </summary> /// <param name="userName">user name</param> /// <param name="opponentName">opponent name</param> /// <param name="master">how move first</param> public void StartGame(string userName, string opponentName, bool master) { if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(opponentName)) { var callback = OperationContext.Current.GetCallbackChannel <IClientCallback>(); try { lock (padlock) { if (_callback.ContainsKey(userName)) { GameMng.AddGame(userName, opponentName); _callback[userName].StartGameFromServer(userName, opponentName, master); } } } catch (Exception ex) { callback.RecieveError(ex.Message); } } }