Пример #1
0
        public Presenter(IHangman hangman, IManagerFile managerFile, IManagerPicture managerPicture, IMessageError messageError, IManagerString managerString)
        {
            this.hangman        = hangman;
            this.managerFile    = managerFile;
            this.managerPicture = managerPicture;
            this.messageError   = messageError;
            this.managerString  = managerString;

            this.hangman.ButtonClick += this.Hangman_ButtonClick;
            string pathToPicture = @"Resources";
            string pathToText    = @"Resources\dictionary.txt";

            bool isFileExist    = this.managerFile.FileExictance(pathToText);
            bool isPictureExist = this.managerPicture.FileExictance(pathToPicture);

            if (!isFileExist && !isPictureExist)
            {
                this.hangman.MessageBoxShow(this.messageError.ErrorFile("данным"));
                return;
            }

            this.managerFile.FileRead();
            elem = this.managerFile.GetElement();

            this.hangman.DrawText(this.managerString.SecretString(elem));//secretString display
            countImage = managerPicture.CountImage();
            this.managerPicture.FileRead();
            this.hangman.DrawPicture(this.managerPicture.GetElement(0));//image display
        }
Пример #2
0
        private string ExecuteCommand(string command)
        {
            if (string.IsNullOrEmpty(command))
            {
                throw new ArgumentNullException("Command parameter can't be null or empty.");
            }
            string resultStringOfExecution = "Incorrect guess or command!";

            switch (command)
            {
            case Command.TopScores:
                resultStringOfExecution = this.scoreBoard.ToString();
                break;

            case Command.PlayerHint:
                char revealedLetter = this.game.RevealLetter();
                resultStringOfExecution = string.Format("OK, I reveal for you the next letter '{0}'.", revealedLetter);
                break;

            case Command.RestartGame:
                this.scoreBoard.Reset();
                resultStringOfExecution = "\nWelcome to “Hangman” game. Please try to guess my secret word.";
                string word = this.GetRandomWord();
                this.game = new Hangman(word);
                break;

            case Command.EndGame:
                resultStringOfExecution = "Good bye!";
                break;
            }
            return(resultStringOfExecution);
        }
Пример #3
0
 public void Run()
 {
     do
     {
         Console.WriteLine();
         Console.Write("The secret word is: ");
         string currentState = this.game.GetCurrentStateOfWord();
         Console.WriteLine(currentState);
         Console.WriteLine();
         if (this.game.IsOver())
         {
             if (this.game.HelpUsed)
             {
                 Console.WriteLine("You won with {0} mistake(s) but you have cheated." +
                                   " You are not allowed to enter into the scoreboard.", this.game.Mistakes);
             }
             else
             {
                 Console.WriteLine(this.CheckScoreHasMadeScoreBoard(this.game.Mistakes));
             }
             string word = this.GetRandomWord();
             this.game = new Hangman(word);
         }
         else
         {
             this.HandleInput();
         }
     } while (this.command != Command.EndGame);
 }
Пример #4
0
        public GameEngine()
        {
            this.randomGenerator = new Random();
            this.words           = new string[] { "computer", "programmer", "software", "debugger", "compiler",
                                                  "developer", "algorithm", "array", "method", "variable" };
            this.scoreBoard = new ScoreBoard();
            string word = this.GetRandomWord();

            this.game = new Hangman(word);
            Console.WriteLine("Commands: top, help, restart, exit.");
            // commands should be global constants
            Console.WriteLine("Welcome to “Hangman” game. Please try to guess my secret word.");
            this.command = null;
        }