public override bool Equals(object obj) { BullsAndCowsNumber objectToCompare = obj as BullsAndCowsNumber; if (objectToCompare == null) { return(false); } else { return(FirstDigit == objectToCompare.FirstDigit && SecondDigit == objectToCompare.SecondDigit && ThirdDigit == objectToCompare.ThirdDigit && FourthDigit == objectToCompare.FourthDigit); } }
static void Main(string[] args) { BullsAndCowsNumber bullsAndCowsNumber = new BullsAndCowsNumber(); Scoreboard scoreBoard = new Scoreboard(ScoresFile); Console.WriteLine(WelcomeMessage); while (true) { Console.Write("Enter your guess or command: "); string command = Console.ReadLine(); if (command == "exit") { Console.WriteLine(GoodBuyMessage); break; } switch (command) { case "top": { Console.Write(scoreBoard); break; } case "restart": { Console.WriteLine(); Console.WriteLine(WelcomeMessage); bullsAndCowsNumber = new BullsAndCowsNumber(); break; } case "help": { Console.WriteLine("The number looks like {0}.", bullsAndCowsNumber.GetCheat()); break; } default: { try { rezultat guessResult = bullsAndCowsNumber.TryToGuess(command); if (guessResult.Bulls == 4) { if (bullsAndCowsNumber.cheats == 0) { Console.Write(NumberGuessedWithoutCheats, bullsAndCowsNumber.GuessesCount, bullsAndCowsNumber.GuessesCount == 1 ? "attempt" : "attempts"); string name = Console.ReadLine(); scoreBoard.AddScore(name, bullsAndCowsNumber.GuessesCount); } else { Console.WriteLine(NumberGuessedWithCheats, bullsAndCowsNumber.GuessesCount, bullsAndCowsNumber.GuessesCount == 1 ? "attempt" : "attempts", bullsAndCowsNumber.cheats, bullsAndCowsNumber.cheats == 1? "cheat" : "cheats"); } Console.Write(scoreBoard); Console.WriteLine(); Console.WriteLine(WelcomeMessage); bullsAndCowsNumber = new BullsAndCowsNumber(); } else { Console.WriteLine("{0} {1}", WrongNumberMessage, guessResult); } } catch (ArgumentException) { Console.WriteLine(InvalidCommandMessage); } break; } } } scoreBoard.SaveToFile(ScoresFile); }