Beispiel #1
0
        public static void loadLevel1(Canvas canvas, Window window, Player player)
        {
            String           fileName = "GalagaSavedGame.bin";
            BinaryFormatter  reader   = null;
            Stream           stream   = null;
            SerializeGameObj game     = null;


            try
            {
                reader = new BinaryFormatter();
                stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);

                game = (SerializeGameObj)reader.Deserialize(stream);

                //   if(game.GetLevel == 4)
                // {
                //   LoadLevels load = new LoadLevels(game.GetCoins, game.GetLives, game.GetLevel);
                //}
                //else
                ///{
                LoadLevels loadlvl1 = new LoadLevels(game.GetShipInt, game.GetShipPoint, game.GetShipPath, game.GetCommanderInt,
                                                     game.GetCommanderPoint, game.GetCommanderPath, game.GetBugInt, game.GetBugPoint, game.GetBugPath,
                                                     canvas, window, game.GetShipMin, game.GetShipMax, game.GetComMin, game.GetComMax, game.GetBugMin, game.GetBugMax
                                                     , game.GetCoins, game.GetLives, game.GetLevel);
                player = loadlvl1.getPlayer();
                //}
            }
            catch (SerializationException e)
            {
                MessageBox.Show("An error occured and the current game was not able to be LOADED.");
                MessageBox.Show(e.Message);
            }
        }
Beispiel #2
0
        public static void loadLevel4(Canvas canvas, Window window, Player player)
        {
            String           fileName = "GalagaSavedGame.bin";
            BinaryFormatter  reader   = null;
            Stream           stream   = null;
            SerializeGameObj game     = null;


            try
            {
                reader = new BinaryFormatter();
                stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);

                game = (SerializeGameObj)reader.Deserialize(stream);


                LoadLevels loadlvl1 = new LoadLevels(game.GetCoins, game.GetLives, game.GetLevel);
                player = loadlvl1.getPlayer();
            }
            catch (SerializationException e)
            {
                MessageBox.Show("An error occured and the current game was not able to be LOADED.");
                MessageBox.Show(e.Message);
            }
        }
Beispiel #3
0
 private void saveBtn_Click(object sender, RoutedEventArgs e)
 {
     // MessageBox.Show(""+LoadLevels.getStaticPlayer().getCurrentLevel());
     //MessageBox.Show("" + player.getCurrentLevel());
     if (loaded)
     {
         if (LoadLevels.getStaticPlayer().getCurrentLevel() == 1)
         {
             lv1.saveLevel1();
         }
         else if (LoadLevels.getStaticPlayer().getCurrentLevel() == 2)
         {
             Level2.saveLevel2(this.player, true);
         }
         else if (LoadLevels.getStaticPlayer().getCurrentLevel() == 3)
         {
             Level3.saveLevel3(this.player, true);
         }
         else if (LoadLevels.getStaticPlayer().getCurrentLevel() == 4)
         {
             Level4.saveLevel4(this.player, true);
         }
     }
     else
     {
         if (player.getCurrentLevel() == 1)
         {
             lv1.saveLevel1();
         }
         else if (player.getCurrentLevel() == 2)
         {
             Level2.saveLevel2(this.player, false);
         }
         else if (player.getCurrentLevel() == 3)
         {
             Level3.saveLevel3(this.player, false);
         }
         else if (player.getCurrentLevel() == 4)
         {
             Level4.saveLevel4(this.player, false);
         }
     }
 }
Beispiel #4
0
 void GameOver()
 {
     if (loaded)
     {
         if (LoadLevels.getStaticPlayer().GetLives() == 0)
         {
             Image gameOverPic = new Image();
             gameOverPic.Height = 200;
             gameOverPic.Width  = 250;
             this.canvas.Children.Add(gameOverPic);
             Canvas.SetTop(gameOverPic, 200);
             Canvas.SetLeft(gameOverPic, 300);
             gameOverPic.Source = UtilityMethods.LoadImage("pics/gameOver.png");
             mediaElement.Stop();
             mediaElement.Source = null;
             LoadLevels.getStaticPlayer().shootSoundEffect.StopSound();
             LoadLevels.getStaticPlayer().shootSoundEffect.Dispose();
             sound.playSoundLooping();
             sound.Dispose();
             BackToMainWindow();
         }
     }
     else
     {
         if (player.GetLives() == 0)
         {
             Image gameOverPic = new Image();
             gameOverPic.Height = 200;
             gameOverPic.Width  = 250;
             this.canvas.Children.Add(gameOverPic);
             Canvas.SetTop(gameOverPic, 200);
             Canvas.SetLeft(gameOverPic, 300);
             gameOverPic.Source = UtilityMethods.LoadImage("pics/gameOver.png");
             mediaElement.Stop();
             mediaElement.Source = null;
             player.shootSoundEffect.StopSound();
             player.shootSoundEffect.Dispose();
             sound.playSoundLooping();
             sound.Dispose();
             BackToMainWindow();
         }
     }
 }
Beispiel #5
0
        public static void saveLevel4(Player player, bool load)
        {
            String           fileName  = "GalagaSavedGame.bin";
            BinaryFormatter  formatter = null;
            Stream           stream    = null;
            SerializeGameObj game      = null;


            int coins;
            int lives;
            int level;

            if (load)
            {
                coins = LoadLevels.getStaticPlayer().getCoins();
                lives = LoadLevels.getStaticPlayer().GetLives();
                level = LoadLevels.getStaticPlayer().getCurrentLevel();
            }
            else
            {
                coins = player.getCoins();
                lives = player.GetLives();
                level = player.getCurrentLevel();
            }

            game = new SerializeGameObj(coins, lives, level);

            try
            {
                formatter = new BinaryFormatter();
                stream    = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
                formatter.Serialize(stream, game);
                stream.Close();
                MessageBox.Show("Game has been saved");
            }
            catch (SerializationException e)
            {
                MessageBox.Show("An error occured and the current game was not able to be saved.");
                MessageBox.Show(e.Message);
            }
        }
Beispiel #6
0
        public static void loadLevel2(Canvas canvas, Window window, Player player)
        {
            String           fileName  = "GalagaSavedGame.bin";
            BinaryFormatter  reader    = null;
            Stream           stream    = null;
            SerializeGameObj game      = null;
            List <int>       enemieInt = new List <int>();
            List <Point>     pointArr  = new List <Point>();
            List <String>    pathArr   = new List <string>();
            List <double>    minXShip  = new List <double>();
            List <double>    maxXShip  = new List <double>();
            List <double>    minXCom   = new List <double>();
            List <double>    maxXCom   = new List <double>();
            List <double>    minXBug   = new List <double>();
            List <double>    maxXBug   = new List <double>();
            int coins = player.getCoins();
            int lives = player.GetLives();
            int level = player.getCurrentLevel();

            try
            {
                reader = new BinaryFormatter();
                stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);

                game = (SerializeGameObj)reader.Deserialize(stream);


                LoadLevels loadlvl1 = new LoadLevels(game.GetShipInt, game.GetShipPoint, game.GetShipPath, game.GetCommanderInt,
                                                     game.GetCommanderPoint, game.GetCommanderPath, game.GetBugInt, game.GetBugPoint, game.GetBugPath,
                                                     canvas, window, game.GetShipMin, game.GetShipMax, game.GetComMin, game.GetComMax, game.GetBugMin, game.GetBugMax
                                                     , game.GetCoins, game.GetLives, game.GetLevel);
                player = loadlvl1.getPlayer();
            }
            catch (SerializationException e)
            {
                MessageBox.Show("An error occured and the current game was not able to be LOADED.");
                MessageBox.Show(e.Message);
            }
        }
Beispiel #7
0
        public void MyGrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.isPause == false)
            {
                if (loaded)
                {
                    LoadLevels.getStaticPlayer().Move();
                }
                else
                {
                    player.Move();
                }
            }

            if (Player.ColdDown < progressBar.Maximum)
            {
                if (loaded)
                {
                    if (LoadLevels.getStaticPlayer().getEnemiesSize() != 0 && this.isPause == false)
                    {
                        LoadLevels.getStaticPlayer().Shoot();
                    }
                }
                else
                {
                    if (player.getEnemiesSize() != 0 && this.isPause == false)
                    {
                        player.Shoot();
                    }
                }
            }
            else
            {
                Player.ColdDown = 10;
            }
        }
Beispiel #8
0
        public static void saveLevel2(Player player, bool load)
        {
            String           fileName  = "GalagaSavedGame.bin";
            BinaryFormatter  formatter = null;
            Stream           stream    = null;
            SerializeGameObj game      = null;

            List <int> shipInt      = new List <int>();
            List <int> commanderInt = new List <int>();
            List <int> bugInt       = new List <int>();

            List <Point> shipPoint      = new List <Point>();
            List <Point> commanderPoint = new List <Point>();
            List <Point> bugPoint       = new List <Point>();

            List <String> shipPath      = new List <string>();
            List <String> commanderPath = new List <string>();
            List <String> bugPath       = new List <string>();
            List <double> minXShip      = new List <double>();
            List <double> maxXShip      = new List <double>();
            List <double> minXCom       = new List <double>();
            List <double> maxXCom       = new List <double>();
            List <double> minXBug       = new List <double>();
            List <double> maxXBug       = new List <double>();
            int           coins;
            int           lives;
            int           level;

            if (load)
            {
                coins = LoadLevels.getStaticPlayer().getCoins();
                lives = LoadLevels.getStaticPlayer().GetLives();
                level = LoadLevels.getStaticPlayer().getCurrentLevel();
            }
            else
            {
                coins = player.getCoins();
                lives = player.GetLives();
                level = player.getCurrentLevel();
            }



            if (load == false)
            {
                for (int i = 0; i < player.getEnemiesList().Count; i++)
                {
                    if (player.getEnemiesList()[i].GetType() == typeof(SpaceShip))
                    {
                        shipInt.Add(0);
                        shipPoint.Add(player.getEnemiesList()[i].GetPoint());
                        shipPath.Add(player.getEnemiesList()[i].GetImage().Source.ToString());
                        maxXShip.Add(player.getEnemiesList()[i].getMaxX());
                        minXShip.Add(player.getEnemiesList()[i].getMinX());
                    }
                    else if (player.getEnemiesList()[i].GetType() == typeof(Commander))
                    {
                        commanderInt.Add(1);
                        commanderPoint.Add(player.getEnemiesList()[i].GetPoint());
                        commanderPath.Add(player.getEnemiesList()[i].GetImage().Source.ToString());
                        maxXCom.Add(player.getEnemiesList()[i].getMaxX());
                        minXCom.Add(player.getEnemiesList()[i].getMinX());
                    }
                    else if (player.getEnemiesList()[i].GetType() == typeof(Bug))
                    {
                        bugInt.Add(2);
                        bugPoint.Add(player.getEnemiesList()[i].GetPoint());
                        bugPath.Add(player.getEnemiesList()[i].GetImage().Source.ToString());
                        maxXBug.Add(player.getEnemiesList()[i].getMaxX());
                        minXBug.Add(player.getEnemiesList()[i].getMinX());
                    }
                }
            }
            else if (load)
            {
                for (int i = 0; i < LoadLevels.getStaticPlayer().getEnemiesList().Count; i++)
                {
                    if (LoadLevels.getStaticPlayer().getEnemiesList()[i].GetType() == typeof(SpaceShip))
                    {
                        shipInt.Add(0);
                        shipPoint.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetPoint());
                        shipPath.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetImage().Source.ToString());
                        maxXShip.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMaxX());
                        minXShip.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMinX());
                    }
                    else if (LoadLevels.getStaticPlayer().getEnemiesList()[i].GetType() == typeof(Commander))
                    {
                        commanderInt.Add(1);
                        commanderPoint.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetPoint());
                        commanderPath.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetImage().Source.ToString());
                        maxXCom.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMaxX());
                        minXCom.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMinX());
                    }

                    else if (LoadLevels.getStaticPlayer().getEnemiesList()[i].GetType() == typeof(Bug))
                    {
                        bugInt.Add(2);
                        bugPoint.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetPoint());
                        bugPath.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].GetImage().Source.ToString());
                        maxXBug.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMaxX());
                        minXBug.Add(LoadLevels.getStaticPlayer().getEnemiesList()[i].getMinX());
                    }
                }
            }


            game = new SerializeGameObj(shipInt, shipPoint, shipPath, commanderInt, commanderPoint, commanderPath,
                                        bugInt, bugPoint, bugPath, minXShip, maxXShip, minXCom, maxXCom, minXBug, maxXBug, coins, lives, level);

            try
            {
                formatter = new BinaryFormatter();
                stream    = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
                formatter.Serialize(stream, game);
                stream.Close();
                MessageBox.Show("Game has been saved");
            }
            catch (SerializationException e)
            {
                MessageBox.Show("An error occured and the current game was not able to be saved.");
                MessageBox.Show(e.Message);
            }
        }
Beispiel #9
0
        private void pauseBtn_Click()
        {
            //this.lifeTimer.Stop();
            //this.checkLife.Stop();
            if (loaded == true)
            {
                if (LoadLevels.getStaticPlayer().getCurrentLevel() == 1)
                {
                    if (Level1.timerRandom != null)
                    {
                        Level1.timerRandom.Stop();
                    }
                }
                if (LoadLevels.getStaticPlayer().getCurrentLevel() == 2)
                {
                    if (Level2.timerRandom != null)
                    {
                        Level2.timerRandom.Stop();
                    }
                }
                if (LoadLevels.getStaticPlayer().getCurrentLevel() == 3)
                {
                    if (Level3.timerRandom != null)
                    {
                        Level3.timerRandom.Stop();
                    }
                }
                if (LoadLevels.getStaticPlayer().getCurrentLevel() == 4)
                {
                    if (Level4.timerRandom != null)
                    {
                        Level4.timerRandom.Stop();
                    }
                }
            }
            else
            {
                if (this.player.getCurrentLevel() == 1)
                {
                    if (Level1.timerRandom != null)
                    {
                        Level1.timerRandom.Stop();
                    }
                }
                if (this.player.getCurrentLevel() == 2)
                {
                    if (Level2.timerRandom != null)
                    {
                        Level2.timerRandom.Stop();
                    }
                }
                if (this.player.getCurrentLevel() == 3)
                {
                    if (Level3.timerRandom != null)
                    {
                        Level3.timerRandom.Stop();
                    }
                }
                if (this.player.getCurrentLevel() == 4)
                {
                    if (Level4.timerRandom != null)
                    {
                        Level4.timerRandom.Stop();
                    }
                }
            }
            List <Enemies> allEnemies = new List <Enemies>();

            if (loaded)
            {
                allEnemies = LoadLevels.getStaticPlayer().getEnemiesList();
            }
            else
            {
                allEnemies = this.player.getEnemiesList();
            }
            if (allEnemies != null)
            {
                for (int i = 0; i < allEnemies.Count; i++)
                {
                    if (allEnemies[i].GetType() == typeof(Bug))
                    {
                        ((Bug)allEnemies[i]).stopMove();
                    }
                    else if (allEnemies[i].GetType() == typeof(SpaceShip))
                    {
                        ((SpaceShip)allEnemies[i]).stopMove();
                        ((SpaceShip)allEnemies[i]).StopShoot();
                    }
                    else if (allEnemies[i].GetType() == typeof(Commander))
                    {
                        ((Commander)allEnemies[i]).stopMove();
                        ((Commander)allEnemies[i]).stopShoot();
                    }
                    else
                    {
                    }
                }
            }

            List <Bullet> allBullets = Bullet.getBulletList;

            if (allBullets.Count != 0)
            {
                for (int i = 0; i < allBullets.Count; i++)
                {
                    allBullets[i].StopShootDown();
                    allBullets[i].StopShootLeft();
                    allBullets[i].StopShootRight();
                    allBullets[i].StopShootUp();
                }
            }
            Menu("display");
        }