Ejemplo n.º 1
0
        public static void Main()
        {
            Random rnd = new Random();

            while (true)
            {
                Array     soptions  = Enum.GetValues(typeof(RpsOption));
                RpsOption rpsOption = (RpsOption)soptions.GetValue(rnd.Next(soptions.Length));
                Console.Write("Choose: ");
                string    input   = Console.ReadLine().ToLower();
                RpsOption uoption = soptions.OfType <RpsOption>().First(
                    s =>
                {
                    string tmp = s.ToString().ToLower();
                    return(tmp.StartsWith(input) || tmp.EndsWith(input) || input.StartsWith(tmp) ||
                           input.EndsWith(tmp));
                });
                Console.Write($"You chose: {uoption}, I chose {rpsOption}. This means ");
                int diff = (int)rpsOption - (int)uoption;
                diff = diff switch { -2 => 1, 2 => - 1, _ => diff };
                Console.Write(diff switch
                {
                    -1 => "You've",
                    0 => "No-one has",
                    1 => "I've",
                    _ => throw new Exception($"This should not happen! (diff={diff})")
                });
Ejemplo n.º 2
0
    public void ProcessRpsChoices(RpsOption choice_P1, RpsOption choice_P2, float choiceTime_P1, float choiceTime_P2)
    {
        int winningPlayerNum = 0;

        string[] dialogueArray = null;
        if ((choice_P1 == RpsOption.None) && (choice_P2 == RpsOption.None))
        {
            Debug.Log("nothing chosen");
            winningPlayerNum = Random.Range(1, 3);
        }
        else if (choice_P1 == RpsOption.None)
        {
            Debug.Log("player 1 chose nothing");
            Debug.Log("player 2 chose " + choice_P2);
            winningPlayerNum = 2;
        }
        else if (choice_P2 == RpsOption.None)
        {
            Debug.Log("player 1 chose " + choice_P1);
            Debug.Log("player 2 chose nothing");
            winningPlayerNum = 1;
        }

        if (choice_P1 == RpsOption.Rock)
        {
            if (choice_P2 == RpsOption.Rock)
            {
                if (choiceTime_P1 < choiceTime_P2)
                {
                    Debug.Log("player 1 played faster rock");
                    winningPlayerNum = 1;
                }
                else if (choiceTime_P1 > choiceTime_P2)
                {
                    Debug.Log("player 2 played faster rock");
                    winningPlayerNum = 2;
                }
                else
                {
                    Debug.Log("tied rock");
                    winningPlayerNum = Random.Range(1, 3);
                }
            }
            else if (choice_P2 == RpsOption.Paper)
            {
                Debug.Log("player 2 beats rock with paper");
                winningPlayerNum = 2;
            }
            else if (choice_P2 == RpsOption.Scissors)
            {
                Debug.Log("player 1 beats scissors with rock");
                winningPlayerNum = 1;
            }
        }
        else if (choice_P1 == RpsOption.Paper)
        {
            if (choice_P2 == RpsOption.Rock)
            {
                Debug.Log("player 1 beats rock with paper");
                winningPlayerNum = 1;
            }
            else if (choice_P2 == RpsOption.Paper)
            {
                if (choiceTime_P1 < choiceTime_P2)
                {
                    Debug.Log("player 1 played faster paper");
                    winningPlayerNum = 1;
                }
                else if (choiceTime_P1 > choiceTime_P2)
                {
                    Debug.Log("player 2 played faster paper");
                    winningPlayerNum = 2;
                }
                else
                {
                    Debug.Log("tied paper");
                    winningPlayerNum = Random.Range(1, 3);
                }
            }
            else if (choice_P2 == RpsOption.Scissors)
            {
                Debug.Log("player 2 beats paper with scissors");
                winningPlayerNum = 2;
            }
        }
        else if (choice_P1 == RpsOption.Scissors)
        {
            if (choice_P2 == RpsOption.Rock)
            {
                Debug.Log("player 2 beats scissors with rock");
                winningPlayerNum = 2;
            }
            else if (choice_P2 == RpsOption.Paper)
            {
                Debug.Log("player 1 beats paper with scissors");
                winningPlayerNum = 1;
            }
            else if (choice_P2 == RpsOption.Scissors)
            {
                if (choiceTime_P1 < choiceTime_P2)
                {
                    Debug.Log("player 1 played faster scissors");
                    winningPlayerNum = 1;
                }
                else if (choiceTime_P1 > choiceTime_P2)
                {
                    Debug.Log("player 2 played faster scissors");
                    winningPlayerNum = 2;
                }
                else
                {
                    Debug.Log("tied scissors");
                    winningPlayerNum = Random.Range(1, 3);
                }
            }
        }
        if (winningPlayerNum == 1)
        {
            dialogueArray = Services.DialogueDataManager.GetRpsDialogue(currentRoundNum, choice_P1, choice_P2);
        }
        else if (winningPlayerNum == 2)
        {
            dialogueArray = Services.DialogueDataManager.GetRpsDialogue(currentRoundNum, choice_P2, choice_P1);
        }

        initiatingPlayer     = winningPlayerNum;
        currentTurnPlayerNum = 3 - winningPlayerNum;
        rpsDialogueArray     = dialogueArray;
        lastRpsChoices       = new RpsOption[2] {
            choice_P1, choice_P2
        };
    }