Quick actions

cmd+k|ctrl+k

Navigation

Languages

Rock, Paper, Scissors

Snippet info

Language

Csharp

Visibility

public

Author

caveirinha

Created

2024-01-07T13:42:14.42001Z

Updated

2024-01-07T13:42:28.341551Z

using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main() {
        PPTGame pptGame = new PPTGame();
        

        int result = pptGame.CheckWinner();
        
        if (result == 0) {
            Console.WriteLine("It's a tie!");
        } else if (result == 1) {
            Console.WriteLine("Machine 2 wins!");
        } else {
            Console.WriteLine("Machine 1 wins!");
        }
    }

    public class PPTGame {
        public String[] options = {"Rock", "Paper", "Scissors"};
        private Random random = new Random();

        public int GetMachineChoice() {
            return random.Next(0, 3);
        }

        public int CheckWinner() {
            int choiceMachine1 = GetMachineChoice();
            int choiceMachine2 = GetMachineChoice();

            Console.WriteLine("Machine 1's choice: " + options[choiceMachine1]);
            Console.WriteLine("Machine 2's choice: " + options[choiceMachine2]);

            if (choiceMachine1 == choiceMachine2) {
                return 0; // It's a tie
            } else if ((choiceMachine1 + 1) % 3 == choiceMachine2) {
                return 1; // Machine 1 wins
            } else {
                return 2; // Machine 2 wins
            }
        }
    }
}
INFO