Example #1
0
 /// <summary>
 /// Plays the roll animations on both hands.
 /// </summary>
 public void Roll(RollVO rollVO)
 {
     resultString            = GetResultText(rollVO);
     leftHand.ShootComplete += OnShootComplete;
     leftHand.Shoot(rollVO.myShot);
     rightHand.Shoot(rollVO.theirShot);
 }
        /// <summary>
        /// Attempts to process the user's shot.
        /// </summary>
        /// <param name="shot">Shot.</param>
        /// <param name="success">Success.</param>
        /// <param name="failure">Failure.</param>
        public void Shoot(string shot, System.Action <RollVO> success, System.Action <Globals.RPSModelResultCodes> failure)
        {
            ValidateCoroutineExecutor();
            coroutineExecutor.StartCoroutine(SendRequest(
                                                 "http://localhost:3000/roll",
                                                 JsonUtility.ToJson(new RollParams
            {
                matchId = matchId,
                userId  = userId,
                shot    = shot
            }),
                                                 (request, result) =>
            {
                if (result == Globals.RPSModelResultCodes.Success)
                {
                    RollVO rollVO = null;
                    try
                    {
                        rollVO = JsonUtility.FromJson <RollVO>(Encoding.UTF8.GetString(request.downloadHandler.data));

                        // Track our tally
                        if (rollVO.result == Globals.RollResults.Won)
                        {
                            ++Wins;
                        }
                        else if (rollVO.result == Globals.RollResults.Lost)
                        {
                            ++Losses;
                        }
                        else
                        {
                            ++Ties;
                        }
                    }
                    catch (Exception)
                    {
                        if (failure != null)
                        {
                            failure(Globals.RPSModelResultCodes.InvalidReturnData);
                        }
                        return;
                    }

                    if (success != null)
                    {
                        success(rollVO);
                    }
                }
                else
                {
                    if (failure != null)
                    {
                        failure(result);
                    }
                }
            }));
        }
Example #3
0
 /// <summary>
 /// Gets the result text.
 /// </summary>
 /// <returns>The result text.</returns>
 /// <param name="rollVO">Roll V.</param>
 private string GetResultText(RollVO rollVO)
 {
     if (rollVO.result == Globals.RollResults.Won)
     {
         return(string.Format("{0} beats {1}!\n\nYou won!", rollVO.myShot, rollVO.theirShot));
     }
     else if (rollVO.result == Globals.RollResults.Lost)
     {
         return(string.Format("{0} beats {1}\n\nYou lost!", rollVO.theirShot, rollVO.myShot));
     }
     else
     {
         return("You tied!");
     }
 }
        /// <summary>
        /// Attempts to process a user's shot.
        /// </summary>
        /// <param name="shot">Shot.</param>
        /// <param name="success">Success.</param>
        /// <param name="failure">Failure.</param>
        public void Shoot(string shot, System.Action <RollVO> success, System.Action <Globals.RPSModelResultCodes> failure)
        {
            // Random shoot for opponent
            string theirShot = OpponentShoot();

            RollVO rollVO = new RollVO
            {
                myShot    = shot,
                theirShot = theirShot,
                result    = DetermineResult(shot, theirShot)
            };

            if (success != null)
            {
                success(rollVO);
            }
        }
Example #5
0
 /// <summary>
 /// Handles the roll success event.
 /// </summary>
 /// <param name="rollVO">Roll V.</param>
 private void OnRollSuccess(RollVO rollVO)
 {
     View.Roll(rollVO);
 }
 /// <summary>
 /// Plays the roll animation
 /// </summary>
 public void Roll(RollVO rollVO)
 {
     rollView.RollComplete += OnRollComplete;
     rollView.Roll(rollVO);
 }