Esempio n. 1
0
        public static Casual Create(string gameName, List <Guid> players, IPlayerRepository playerRepo = null, GameConfig config = null, string lastState = "")
        {
            if (config == null)
            {
                config = GameConfig.Default();
            }

            Casual gameResult;

            if (gameName.Equals("rock-paper-scissors"))
            {
                if (players.Count != 2)
                {
                    throw new Exception("Rock paper scissors must be played with 2 person!");
                }

                gameResult = new RockPaperScissor(players);

                RPSResultHandler win  = new WinHandler(playerRepo, new Multiplier(new RPSWin(), config.WinMultiplier));
                RPSResultHandler lose = new LoseHandler(playerRepo, new Multiplier(new RPSLose(), config.LoseMultiplier));

                gameResult.Attach(win);
                gameResult.Attach(lose);

                if (lastState == "" || lastState == null)
                {
                    return(gameResult);
                }

                if (gameName.Equals("rock-paper-scissors"))
                {
                    RPSMemento memento = JsonSerializer.Deserialize <RPSMemento>(lastState);
                    gameResult.LoadMemento(memento);
                }

                return(gameResult);
            }
            else
            {
                throw new Exception("Game not found!");
            }
        }
Esempio n. 2
0
        public static void Main()
        {
            Console.WriteLine("Rock, Paper, or Scissor?");
            Console.WriteLine("1. Rock");
            Console.WriteLine("2. Paper");
            Console.WriteLine("3. Scissor");
            int userPick = int.Parse(Console.ReadLine());
            RockPaperScissor playerOne = new RockPaperScissor(userPick);
            Random           rnd       = new Random();
            int    rand   = rnd.Next(1, 4);
            string result = playerOne.GamePlay(rand);

            Console.WriteLine(RockPaperScissor.ConvertPick(playerOne.GetPick())
                              + " vs. " + RockPaperScissor.ConvertPick(rand)
                              + "\r\n" + result);
            Console.WriteLine("Would you like to play again? (Y/N)");
            string replay = Console.ReadLine();

            if (replay == "Y" || replay == "y")
            {
                Main();
            }
        }