コード例 #1
0
        private static void writeBoard(bool i_WritePassword = false)
        {
            Console.WriteLine("|Pins:    |Result:|");
            Console.WriteLine("|=========|=======|");
            Console.Write('|');
            BulPegia.WritePassword(Console.Write, i_WritePassword);
            Console.WriteLine("|       |");
            foreach (BoardRow boardRow in s_BoardRows)
            {
                boardRow.Write();
            }

            Console.WriteLine("|=========|=======|" + Environment.NewLine);
        }
コード例 #2
0
        // $G$ CSS-999 (-3) You should have used constants here.
        // $G$ DSN-999 (-5) this method is to long - should be divided to several methods
        // $G$ CSS-999 (-5) main should be short and not interactive with the user
        public static void Main()
        {
            Console.Title           = "בול פגיעה";
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.Black;
            bool playerWantsToStartANewGame = true;

            while (playerWantsToStartANewGame)
            {
                Console.WriteLine("How many tries (between 4 to 10)?");
                Console.Write("Answer: ");
                byte numberOfRetries = readNumberOfRetries();
                s_BoardRows = new TuringMachine <BoardRow>(numberOfRetries, new BoardRow("         ", "       "));
                BulPegia.GenerateRandomPassword();
                string guess = null;
                long   headMovement;
                do
                {
                    Screen.Clear();
                    Console.WriteLine("Current board status:" + Environment.NewLine);
                    writeBoard();
                    if (guess != BulPegia.Password)
                    {
                        Console.WriteLine("Enter next guess (4 letters between A to H) or 'Q' to quit");
                        guess        = readGuess();
                        headMovement = (long)BulPegia.AppendNewRowToBoard(
                            guess,
                            delegate(string i_pin, string i_result)
                        {
                            return(s_BoardRows.Write(new BoardRow(i_pin, i_result)));
                        });
                    }
                    else
                    {
                        BulPegia.PlayerSuccessfullyGuessedPassword(Console.WriteLine, (byte)currentBoardRowIndex);
                        goto askPlayerIfHeOrSheWouldLikeToStartANewGame;
                    }
                }while (headMovement == 1);
                Screen.Clear();
                Console.WriteLine("Current board status:" + Environment.NewLine);
                const bool v_WritePassword = true;
                writeBoard(v_WritePassword);
                if (guess == BulPegia.Password)
                {
                    BulPegia.PlayerSuccessfullyGuessedPassword(Console.WriteLine, BulPegia.k_PasswordLength);
                    goto askPlayerIfHeOrSheWouldLikeToStartANewGame;
                }

                Console.WriteLine(BulPegia.k_LossMessage);
askPlayerIfHeOrSheWouldLikeToStartANewGame:
                Console.WriteLine(BulPegia.k_YesNoQuestionAboutStartingANewGame + " (Y/N)");
                const bool v_intercept = true;
                switch (ConsoleInput.ReadKey(isInvalidKey, not(v_intercept)).KeyChar)
                {
                case 'y':
                case 'Y':
                    playerWantsToStartANewGame = true;
                    Screen.Clear();
                    break;

                case 'n':
                case 'N':
                    playerWantsToStartANewGame = false;
                    Console.WriteLine(Environment.NewLine);
                    Console.WriteLine(BulPegia.k_GoodByeMessage);
                    Console.WriteLine(k_PressAnyKeyToExitMessage);
                    Console.ReadKey(v_intercept);
                    break;

                default: throw new UnreachableCodeReachedException();
                }
            }
        }