Exemplo 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();
        }
Exemplo 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();
        }
Exemplo n.º 3
0
        public static string SearchWinner()
        {
            ProcessGuessing searchWinner = ProcessGuessing.allPlayersAndGuessings[0];

            int min = Math.Abs(FruitBasket.Weight - ProcessGuessing.allPlayersAndGuessings[0].Weight);

            for (int i = 0; i < ProcessGuessing.allPlayersAndGuessings.Count; i++)
            {
                if (min > Math.Abs(FruitBasket.Weight - ProcessGuessing.allPlayersAndGuessings[i].Weight))
                {
                    min          = Math.Abs(FruitBasket.Weight - ProcessGuessing.allPlayersAndGuessings[i].Weight);
                    searchWinner = ProcessGuessing.allPlayersAndGuessings[i];
                }
            }
            return($"The winner is: {searchWinner}");
        }