/// <summary>
        /// Main handles the initialisation of the program and the game itself
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //shapes the window appropriate for vertical board
            Console.SetWindowSize(80, 50);
            //initialise necessary objects
            Board     b  = Board.Instance;
            CodeMaker cm = CodeMaker.Instance;
            Renderer  r  = Renderer.Instance;

            //sanitize user input for the menu
            while (true)
            {
                Console.Clear();
                r.LogoDraw();
                r.MenuDraw();
                Console.WriteLine("\n                                  Select an Option");
                int menuSelect = 0;

                ConsoleKeyInfo UserInput = Console.ReadKey();

                if (char.IsDigit(UserInput.KeyChar))
                {
                    menuSelect = int.Parse(UserInput.KeyChar.ToString());
                }

                if (menuSelect >= 1 && menuSelect <= 3)
                {
                    Game game = new Game(menuSelect);
                    game.play();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Constructor for the class, called from the Game class when the user has chosen a gamemode
        /// Initialises variable values using passed parameters, also gets the answerCode from the CodeMaker class
        /// Also calls the GenerateBoard method to display the game board
        /// </summary>
        /// <param name="codeMakerObj">The instance of the CodeMaker class created within the Game class</param>
        /// <param name="numberOfPegs"></param>
        /// <param name="numberOfGuesses"></param>
        public GameBoard(CodeMaker codeMakerObj, int numberOfPegs, int numberOfGuesses)
        {
            codeMaker   = codeMakerObj;
            turnNum     = 0;
            numPegs     = numberOfPegs;
            numGuesses  = numberOfGuesses;
            gameFinish  = false;
            turnGuesses = new CodeColours[numPegs, numGuesses];
            turnAnswers = new AnswerColours[numPegs, numGuesses];
            answerCode  = codeMaker.CodeAnswer;

            GenerateBoard(null, null);
        }
Exemple #3
0
        /// <summary>
        /// Constructor for class, initialises variables and creates objects of other classes
        /// </summary>
        public Game()
        {
            isPlaying = true;

            //Generates new random seed to be used throughout the program
            rnd = new Random();
            int tempPegNum, tempColourNum;

            //Sets initial settings for the game
            numPegs    = 4;
            numColours = 6;
            numGuesses = 12;

            do
            {
                gameFinished = false;
                int menuChoice;

                //Calls method to display the main menu to the user, stores the returned int as the menu choice variable
                menuChoice = MainMenu();

                tempPegNum    = numPegs;
                tempColourNum = numColours;

                //Using the menu choice variable in a switch statement the program creates the correct objects for the chosen gamemode
                switch (menuChoice)
                {
                case 1:
                    //Creates an instance of the Player class for the user to play as the codebreaker
                    player   = new Player(numPegs, numColours);
                    gameType = GameType.HumanvsAI;
                    break;

                case 2:
                    //Creates an instance of the CodeBreaker class for the AI as the codebreaker
                    //Also caps the number of pegs and colours available for the AI codebreaker, this is to avoid overly long processing times and out of bounds errors with higher settings
                    if (tempPegNum > 6)
                    {
                        tempPegNum = 6;
                    }

                    if (tempColourNum > 7)
                    {
                        tempColourNum = 7;
                    }

                    codeBreaker = new CodeBreaker(rnd, tempPegNum, tempColourNum);
                    gameType    = GameType.AIvsAI;
                    break;

                case 5:
                    //If the user selects to exit the program, the console window is closed
                    Environment.Exit(0);
                    break;
                }

                //Regardless of the game mode chosen by the user, instances of the CodeMaker and GameBoard classes are created, passing the game settings
                codeMaker = new CodeMaker(rnd, tempPegNum, tempColourNum);
                gameBoard = new GameBoard(codeMaker, tempPegNum, numGuesses);

                //PlayGame method is finally called which starts the game
                PlayGame();
                Console.ReadLine();
            }while (isPlaying);
        }