Exemple #1
0
        public void StartGame()
        {
            // *Intro to the game
            // *Play Music

            //GET USER INFO
            consoleDrawer.DrawText("Enter user name: ");
            user = new User(consoleReader.GetUsername());
            consoleDrawer.DrawText("Enter field size: ");
            user.FieldSize = consoleReader.GetFieldSize();

            //INITIALIZE GAMEFIELD AND EXPLOSION MANAGER
            //TODO: Menu
            gameField = new GameField(user.FieldSize);
            int minesOnFieldCount = PopulateField();

            explostionManager = new ExplosionManager(gameField);

            //TODO: Draw ingame menu (star/stop music)
            while (minesOnFieldCount > 0)
            {
                consoleDrawer.Clear();
                ShowLastHit();//TODO: FIX -> cant easely see what this method needs to do it's work
                consoleDrawer.DrawObject(gameField);

                do
                {
                    AskForPosition();
                    user.LastInput = consoleReader.GetPositon();
                }while (!IsValidPosition());//TODO: FIX -> cant easely see what this method needs to do it's work
                finalScore++;

                bool isMineHit = IsMineHit();//TODO: FIX -> cant easely see what this method needs to do it's work

                if (isMineHit)
                {
                    //generate mine
                    string mineHitOnField = gameField[user.LastInput.PosX, user.LastInput.PosY].ToString();
                    int    mineHit        = int.Parse(mineHitOnField);
                    var    currentMine    = mineFactory.CreateMine((MinePower)mineHit);

                    //configure(reconfigure) the explosion manager
                    explostionManager.SetMine(currentMine);
                    explostionManager.SetHitPosition(user.LastInput);

                    //blow the mine up
                    int minesTakenOut = explostionManager.HandleExplosion();
                    minesOnFieldCount -= minesTakenOut;
                }
            }

            //TODO: change with highscore logic
            consoleDrawer.DrawText(string.Format("You made it with: {0} tries", finalScore));//this is only a test

            // *Save Highscore USE HighScore
            // *Show highscore USE HighScore
        }