Esempio n. 1
0
        public static void Main(string[] args)
        {
            var fruitBasket = new FruitBasket();

            fruitBasket.PrintInfo();

            var playerList = new List <BasePlayer>()
            {
                new UsualPlayer(),
                new NotepadPlayer(),
                new UberPlayer(),
                new CheaterPlayer(),
                new UberCheaterPlayer()
            };

            bool notGuess         = true;
            int  numberOfAttempts = 20;
            int  counter          = 0;

            var playerThreads = new Thread[5];


            while (notGuess && counter < numberOfAttempts)
            {
                for (int i = 0; i < playerList.Count; i++)
                {
                    playerThreads[i]      = new Thread(playerList[i].GuessNumber);
                    playerThreads[i].Name = $"{i}";
                }

                for (int i = 0; i < playerList.Count; i++)
                {
                    playerThreads[i].Start();
                }
                foreach (var item in playerList)
                {
                    lock (locker)
                    {
                        var currentPlayer = new ProcessGuessing(item, item.GuessingNumber);
                        ProcessGuessing.allPlayersAndGuessings.Add(currentPlayer);

                        bool win = item.CheckGuessedNumbers(item.GuessingNumber);
                        item.PrintInfo(item.GuessingNumber);

                        if (win == true)
                        {
                            item.WinMessage();
                            notGuess = false;
                            break;
                        }
                        counter++;
                    }
                }
                Console.WriteLine("======================================");
            }

            Console.WriteLine(ProcessGuessing.SearchWinner());

            Console.ReadKey();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var numberOfAttempts = 100;

            var fruitBasket = new FruitBasket();

            fruitBasket.PrintInfo();


            var playerList = new List <BasePlayer>()
            {
                new UsualPlayer(),
                new NotepadPlayer(),
                new UberPlayer(),
                new CheaterPlayer(),
                new UberCheaterPlayer()
            };


            bool notGuess   = true;
            int  helpNumber = 0;

            for (int i = 0; i < numberOfAttempts - playerList.Count - 1 && notGuess; i += playerList.Count)
            {
                for (int j = 0; j < playerList.Count; j++)
                {
                    playerList[j].Guess = playerList[j].GuessNumber(helpNumber);

                    var currentPlayer = new ProcessGuessing(playerList[j], playerList[j].Guess);
                    ProcessGuessing.allPlayersAndGuessings.Add(currentPlayer);

                    bool win = playerList[j].CheckGuessedNumbers(playerList[j].Guess);
                    playerList[j].PrintInfo(playerList[j].Guess);


                    if (win == true)
                    {
                        playerList[j].WinMessage();
                        notGuess = false;
                        break;
                    }
                }
                Console.WriteLine("======================================");
            }

            Console.WriteLine(SearchWinner());

            Console.ReadKey();
        }