示例#1
0
        private void NewRound()
        {
            bool roundOver = false;

            ConsoleManager.ClearConsole();

            this.LeftPaddle.Print();
            this.RightPaddle.Print();

            while (!roundOver)
            {
                this.UpdatePaddles();
                this.Ball.Move();

                roundOver |= this.HasLeftPaddleConceded();
                roundOver |= this.HasRightPaddleConceded();

                this.Ball.Print();
                this.PrintScore();
                this.PrintGridMarking();

                Thread.Sleep(this.SleepTimeMilliseconds);
                this.Ball.Clear();
            }

            this.Ball.UpdateProperties();

            this.LeftPaddle.ResetVerticalPosition();
            this.RightPaddle.ResetVerticalPosition();

            Thread.Sleep(GlobalConstants.Gameplay.PauseBetweenRoundsMilliseconds);
        }
示例#2
0
 public void Print()
 {
     ConsoleManager.ClearConsole();
     this.PrintTitle();
     this.PrintOptions();
 }
示例#3
0
        public async void Process(float timestamp, GameLoopObject glo)
        {
            if (skipintro)
            {
                skipintro       = false;
                hideintroscreen = true;
                introsounddone  = true;
                Started         = true;
                Ship.Visible    = true;
                KeyBoardHelper.SpaceBarPressed = true;
            }

            if (soundoff && !SoundManager.SoundIsOff)
            {
                SoundManager.TurnSoundOff();
            }

            //show the intro screen if the space bar hasn't been pressed yet
            if (!hideintroscreen)
            {
                if (KeyBoardHelper.SpaceBarPressed)
                {
                    SoundManager.PlaySound(SoundManager.SoundManagerSounds.coin, true);
                    await ConsoleManager.ClearConsole(spriteService);

                    await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore);

                    Started = true;
                }
                else
                {
                    spriteService.DrawBlazorImage(new PointF(25, 10));
                    await ConsoleManager.ClearConsole(spriteService);

                    await ConsoleManager.DrawIntroScreen(spriteService, Ship);

                    return;
                }
            }

            //if the intro sound isn't done, exit
            if (!introsounddone)
            {
                await ConsoleManager.DrawConsolePlayer1(spriteService);

                return;
            }

            var bugs = GetBugs();

            //do AI if enabled for debugging
            if (aion)
            {
                AIManager.AI(bugs, animationService, Ship);
            }

            //dive the bugs
            if (timestamp - LastDiveTimeStamp > NextDiveWaitTime && EnemyGridManager.EnemyGridBreathing && !glo.editcurveschecked)
            {
                Dive();
                LastDiveTimeStamp = timestamp;
                NextDiveWaitTime  = Utils.Rnd(500, maxwaittimebetweendives);
            }

            //if the bug intro wave is done, increment to the next wave]
            //or start diving and firing
            if ((bugs.Count(a => a.Started && !a.IsMoving && a.Wave == wave) > 0 || bugs.Count(a => a.Wave == wave) == 0) && wave <= 6 && bugs.Count() > 0 && Ship.Visible)
            {
                wave += 1;
                if (wave == 6)
                {
                    EnemyGridManager.EnemyGridBreathing = true;
                    NextDiveWaitTime = Utils.Rnd(500, maxwaittimebetweendives);
                }
                else
                {
                    GetBugs().Where(a => a.Wave == wave).ToList().ForEach(a => a.Started = true);
                }
            }

            //adjust score when bugs are destroyed
            if (bugs.Count != prevbugcount || bugs.Count == 0)
            {
                if (Score >= nextextralifescore)
                {
                    Lives += 1;
                    nextextralifescore += 30000;
                    SoundManager.PlaySound(SoundManager.SoundManagerSounds.extralife);
                    await ConsoleManager.ClearConsole(spriteService);

                    await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore);
                }
                if (Score > HighScore)
                {
                    HighScore = Score;
                }
                await ConsoleManager.DrawScore(spriteService, Score, HighScore);

                prevbugcount = bugs.Count();
            }

            //all bugs destroyed, increment to next level
            await DoLevelIncrementAsync(bugs, timestamp);

            //animate explosions
            if (timestamp - EnemyGridManager.LastEnemyGridMoveTimeStamp > 35)
            {
                EnemyExplosionManager.DoEnemyExplosions(bugs, animationService, this);

                if (Ship.IsExploding)
                {
                    if (!Ship.IsDoubleShip)
                    {
                        Ship.Disabled = true;
                    }
                    ShipManager.DoShipExplosion(Ship, animationService, this);
                }
            }

            //animate child bugs
            ChildBugsManager.MoveChildBugs(bugs, animationService);

            //animated the moving enemy grid
            if (timestamp - EnemyGridManager.LastEnemyGridMoveTimeStamp > 100 || EnemyGridManager.LastEnemyGridMoveTimeStamp == 0)
            {
                EnemyGridManager.MoveEnemyGrid(bugs, animationService, Ship, gameover);
                EnemyGridManager.LastEnemyGridMoveTimeStamp = timestamp;

                //fire enemy missiles
                foreach (var bug in bugs.Where(a => (a.MissileCountDowns.Count > 0 && a.Started) &&
                                               ((a.IsDiving && a.Location.Y <= Constants.CanvasSize.Height - 400 && a.IsMovingDown && !a.IsMorphedBug) ||                                                                             //for diving bugs
                                                (a.IsInIntro && a.Wave == wave && a.Location.Y > 100 && a.Location.X > 150 & a.Location.X < Constants.CanvasSize.Width - 150 && a.Location.Y <= Constants.CanvasSize.Height - 500)))) //for intro bugs
                {
                    for (int i = 0; i <= bug.MissileCountDowns.Count - 1; i++)
                    {
                        bug.MissileCountDowns[i] -= 1;
                        if (bug.MissileCountDowns[i] <= 0)
                        {
                            EnemyDiveManager.DoEnemyFire(bug, animationService, Ship);
                            bug.MissileCountDowns.RemoveAll(a => a <= 0);
                        }
                    }
                }
            }

            //animate the flapping wings
            if (timestamp - FlapWingsManager.LastWingFlapTimeStamp > 500 || FlapWingsManager.LastWingFlapTimeStamp == 0)
            {
                FlapWingsManager.FlapWings(bugs);
                FlapWingsManager.LastWingFlapTimeStamp = timestamp;
            }

            //animate ship missiles
            if (Ship.IsFiring && !Ship.Disabled && Ship.Visible)
            {
                SoundManager.PlaySound(SoundManager.SoundManagerSounds.fire);
                Ship.IsFiring = false;
                ShipManager.Fire(Ship, animationService);
            }

            //center the ship if it's disabled
            //happens after a galaga capture
            if ((Ship.Disabled && !Ship.IsDoubleShip) || (Ship.HasExploded && !Ship.IsDoubleShip))
            {
                if (Ship.Location.X > 320)
                {
                    Ship.Speed = Constants.ShipMoveSpeed * -1;
                }
                else if (Ship.Location.X < 310)
                {
                    Ship.Speed = Constants.ShipMoveSpeed;
                }
                else
                {
                    Ship.Speed = 0;
                }
            }

            //ship missile detection
            if (!Ship.Disabled)
            {
                //ship mission collision with bug
                hits += ShipManager.CheckMissileCollisions(bugs, animationService);

                //bug or missile collision with ship
                if (!shipinvincable)
                {
                    if (!Ship.IsExploding && Ship.Visible && ShipManager.CheckShipCollisions(bugs, animationService, Ship))
                    {
                        SoundManager.StopAllSounds();
                        Ship.IsExploding = true;
                    }
                }
            }

            //draw fighter captured text if a fighter is captured
            if (bugs.Any(a => a.FighterCapturedMessageShowing))
            {
                await ConsoleManager.DrawConsoleFighterCaptured(spriteService);
            }


            //hide fighter captured text if a fighter is captured
            //and bug had flown back home
            if (bugs.Any(a => a.ClearFighterCapturedMessage))
            {
                await ConsoleManager.ClearConsoleLevelText(spriteService);

                bugs.FirstOrDefault(a => a.ClearFighterCapturedMessage).ClearFighterCapturedMessage = false;
                Lives -= 1;
                if (Lives < 0)
                {
                    gameover = true;
                }
                await ConsoleManager.ClearConsole(spriteService);

                await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore);
            }

            //if morphed bugs go offscreen, destroy them immediately
            bugs.Where(a => a.IsMorphedBug && a.Location.Y >= Constants.CanvasSize.Height).ToList().ForEach(a => a.DestroyImmediately = true);

            //ship exploded
            if (Ship.HasExploded)
            {
                if (Ship.IsDoubleShip)
                {
                    Ship.IsDoubleShip = false;
                    Ship.HasExploded  = false;
                    Ship.IsExploding  = false;
                    Ship.Visible      = true;
                    Ship.Disabled     = false;
                    Ship.LeftShipHit  = false;
                    Ship.RightShipHit = false;
                    return;
                }
                WaitManager.DoOnce(async() =>
                {
                    if (infinitelives)
                    {
                        Lives += 1;
                    }

                    if (Lives >= 1)
                    {   //display ready for next life
                        await ConsoleManager.DrawConsoleReady(spriteService);
                        Ship.Disabled = true;
                    }
                    else
                    { //game over
                        await ConsoleManager.DrawConsoleGameOver(spriteService);
                        gameover = true;
                        SoundManager.MuteAllSounds = false;
                        SoundManager.PlaySound(SoundManager.SoundManagerSounds.gameoversong, true);
                    }
                }, WaitManager.WaitStep.enStep.ShowReady);

                if (WaitManager.WaitFor(3000, timestamp, WaitManager.WaitStep.enStep.WaitReady))
                {
                    if (!animationService.Animatables.Any(a => a.Sprite.SpriteType == Sprite.SpriteTypes.BugMissle) &&
                        !bugs.Any(a => a.CaptureState == Bug.enCaptureState.Started) && !bugs.Any(a => a.IsDiving))
                    {
                        if (infinitelives)
                        {
                            Lives -= 1;
                        }
                        Ship.HasExploded = false;
                        Ship.IsExploding = false;
                        if (Lives >= 0)
                        { //load next life
                            Ship.Visible  = true;
                            Ship.Disabled = false;
                            await ConsoleManager.ClearConsole(spriteService);

                            await ConsoleManager.DrawConsole(Lives, spriteService, Ship, true, Level + LevelOffset, Score, HighScore);

                            await ConsoleManager.ClearConsoleLevelText(spriteService);
                        }
                        WaitManager.ClearSteps();
                    }
                }
            }

            //this should never happen
            if (infinitelives && gameover)
            {
                throw new Exception("game over");
            }

            if (showdebugdetails)
            {
                Utils.dOut("hits", hits);
                Utils.dOut("Ship.IsExploding", Ship.IsExploding);
                Utils.dOut("Ship.HasExploded", Ship.HasExploded);
                Utils.dOut("Ship.Disabled", Ship.Disabled);
                Utils.dOut("gameover", gameover);
                Utils.dOut("Lives", Lives);
                Utils.dOut("Level", Level);
                Utils.dOut("LevelOffset", LevelOffset);
                Utils.dOut("Score", Score);
                Utils.dOut("nextextralifescore", nextextralifescore);
            }

            DebugManager.DoDebugLogic(glo, bugs, animationService, Ship);
        }