예제 #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
        }
예제 #2
0
        private void DrawSurface()
        {
            _drawer.DrawSurface(curRect.Width, curRect.Height);

            var visibleCells = Map.RectToCellRect(Map.VisibleRect);

            var lightObjectsList = new List <BurningProps>();

            //var mapSize = _map.GetSize();
            for (int j = visibleCells.Top; j < visibleCells.Top + visibleCells.Height; j++)
            {
                for (int i = visibleCells.Left; i < visibleCells.Left + visibleCells.Width; i++)
                {
                    var gameObject = Map.GetHObjectFromCell(new Point(i, j));

                    if (gameObject == null)
                    {
                        continue;
                    }
                    if (gameObject is LargeObjectOuterAbstract largeObjectOuter && !largeObjectOuter.isLeftCorner)
                    {
                        continue;
                    }

                    var visibleDestination = Map.GetVisibleDestinationFromRealDestination(Map.CellToPoint(new Point(i, j)));

                    var drawingCode = GetDrawingCode(gameObject);

                    _drawer.DrawObject(drawingCode, visibleDestination.X, visibleDestination.Y, gameObject.Height);

                    if (gameObject is IBurning burning)
                    {
                        lightObjectsList.Add(new BurningProps(visibleDestination, burning.LightRadius));
                    }
                }

                if ((j * Map.CellMeasure <= _hero.Position.Y) && ((j + 1) * Map.CellMeasure > _hero.Position.Y))
                {
                    _drawer.DrawHero(Map.GetVisibleDestinationFromRealDestination(_hero.Position), _hero.Angle, _hero.PointList.Select(p => Map.GetVisibleDestinationFromRealDestination(p)).ToList(), _hero.IsHorizontal());
                }
            }

            var mobileObjects = Map.GetMobileObjects();

            foreach (var mobileObject in mobileObjects)
            {
                if (Map.PointInVisibleRect(mobileObject.Position))
                {
                    var visibleDestination = Map.GetVisibleDestinationFromRealDestination(mobileObject.Position);
                    _drawer.DrawObject(mobileObject.GetDrawingCode(), visibleDestination.X, visibleDestination.Y, mobileObject.Height);
                }
            }

            //  _drawer.DrawHero(Map.GetVisibleDestinationFromRealDestination(_hero.Position), _hero.Angle, _hero.PointList.Select(p => Map.GetVisibleDestinationFromRealDestination(p)).ToList(), _hero.IsHorizontal());

            if (IsHeroInInnerMap())
            {
                var innerMapSize       = Map.GetInnerMapRect();
                var visibleDestination = Map.GetVisibleDestinationFromRealDestination(Map.CellToPoint(new Point(innerMapSize.Left, innerMapSize.Top)));
                _drawer.DrawShaddow(visibleDestination, new Size(innerMapSize.Width, innerMapSize.Height));
            }
            else
            {
                _drawer.DrawDayNight(_dayNightCycle.Lightness(), lightObjectsList);
            }

            _drawer.DrawActing(_hero.State.ShowActing);
        }