/// <summary>
        /// this is the builder of the Enemi with the level
        /// </summary>
        /// <param name="lvl"></param>
        /// <returns></returns>
        public static EnnemiBlock BUILDER_EnnemiBlock(Level lvl)
        {
            EnnemiBlock en = null;
            try {

               string file =lvl.nameFile;

                string[] fileSplit = lvl.nameFile.Split('\r');
                string[] tab = fileSplit[0].Split(' ');

                 en = new EnnemiBlock(new Vecteur2D(int.Parse(tab[0]), int.Parse(tab[1])), new Vecteur2D(30, 10));
                string line;

                for (int i = 1; i < fileSplit.Length ; i++)
                {
                    line = fileSplit[i];
                    tab = line.Split(' ');
                    en.addLine(
                       int.Parse(tab[0]),
                       int.Parse(tab[1]),
                       new BasicShip(
                           new Vecteur2D(),
                           int.Parse(tab[2]),
                           stringtoBitmap(tab[3])
                           ,150+lvl.num*50//speed
                           )
                       );

                }
            }
            catch (Exception a)
            {
                System.Console.WriteLine("fileerror"+a.StackTrace);

            }
            return en;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Private constructor
        /// </summary>
        /// <param name="gameSize">Size of the game area</param>
        private Game(Size gameSize)
        {
            Game.gameSize = gameSize;

            sound = new SoundPlayer(SpaceInvaders.Properties.Resources.soundGame);
            music = true;

            sound.PlayLooping();

            this.menuM = new MenuManager();
            this.menuM.add(new MenuItem("Jouer", "Lance une partie",
                delegate() {
                    this.currentState = gameState.startlevel ;
                    return true; }
            ));

            this.menuM.add(new MenuItem("Music on/off", "Active et désactive le son",
                delegate () {
                    if (this.music) {
                        this.sound.Stop();
                        this.music = false;
                    }
                    else
                    {
                        this.sound.PlayLooping();
                        this.music = true;
                    }
                    return true;
                }
            ));

            this.menuM.add(new MenuItem("Chargé", "Charge un fichier de niveaux", delegate () {

                OpenFileDialog openFileDialog1 = new OpenFileDialog();

                openFileDialog1.InitialDirectory = "c:\\";
                openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                openFileDialog1.FilterIndex = 2;
                openFileDialog1.RestoreDirectory = true;

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        Console.WriteLine(openFileDialog1.FileName);
                        this.lvl = new Level("CUSTON LEVEL", File.ReadAllText(openFileDialog1.FileName), 0);
                        this.ennemis = EnnemiBlock.BUILDER_EnnemiBlock(this.lvl);
                        if (this.ennemis == null)
                        {
                           MessageBox.Show("le fichier n'est pas valide, utilisé les files dans resource/level* comme exemple");
                           return false;
                        }
                        this.counterTime = 3;
                        this.currentState = gameState.startlevel;
                        BasicInit();

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }

                return true; }));
            this.menuM.add(new MenuItem("Quitter", "quitte le Jeux ", delegate () { Application.Exit(); return true; }));
            this.currentState = gameState.menu;
            this.counterTime=0;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update game
        /// you can
        ///     change the possition the state of the game 
        /// you can't
        ///     draw somthing thanx to do it in draw()
        /// </summary>
        public void Update(double deltaT)
        {
            bool init = false;
            switch (currentState)
            {
                case gameState.menu:
                    this.menuM.move(deltaT,keyPressed);
                    break;
                case gameState.startlevel:

                    if (this.lvl == null) {
                        this.counterTime = 3;
                        this.lvl = Level.Builder_getLevel(1); init = true;
                        BasicInit();
                        this.ennemis = EnnemiBlock.BUILDER_EnnemiBlock(this.lvl);
                    }

                    this.counterTime -= deltaT;

                    if (this.counterTime < 0) {
                        this.currentState = gameState.start;
                    }

                    break;

                case gameState.start:

                    Missile.misileList.RemoveAll(a => !a.alive);
                    ennemis.move(deltaT);
                    this.playerShip.move(deltaT, keyPressed);
                    listBunger.ForEach(a =>
                    {
                        Missile.misileList.ForEach(b =>
                       {
                           a.collision(b);
                       });

                    }
                    );
                    Bonus.bonusList.ForEach(a =>
                    {
                        a.bonusFor = this.playerShip;
                        a.move(deltaT);

                    });

                    Bonus.bonusList.RemoveAll(pi => !pi.alive);
                    Missile.misileList.ForEach(a =>
                   {

                       a.move(deltaT);
                   });

                    this.ennemis.colitionPlayer(this.playerShip);
                    this.conditionLevelWin();
                    this.conditionLevelLoose();

                    if (keyPressed.Contains(Keys.P) && timePRESS < 0)
                    {
                            currentState = gameState.pause;
                            timePRESS = 0.3;

                    }

                    timePRESS -= deltaT;

                    break;

                case gameState.pause:

                    if (keyPressed.Contains(Keys.P) && timePRESS < 0)
                        {
                            currentState = gameState.start;
                            timePRESS = 0.3;
                        }

            timePRESS -= deltaT;
            break;

                case gameState.lost:

                    if (keyPressed.Contains(Keys.R))
                    {
                        this.currentState = gameState.startlevel;
                        this.lvl = null;
                        Missile.misileList.RemoveAll( pi => true);
                        Bonus.bonusList.RemoveAll(bo => true);

                    }

                    break;

                case gameState.win:

                    if (keyPressed.Contains(Keys.N))
                    {
                        Missile.misileList.ForEach(pi => pi.live = -1);
                        Missile.misileList.RemoveAll(pi =>true);
                        this.currentState = gameState.startlevel;
                        if (this.lvl.num == 0) {
                            this.currentState = gameState.menu;
                            return;
                        }

                        this.lvl = Level.Builder_getLevel(this.lvl.num+1);
                        this.ennemis = EnnemiBlock.BUILDER_EnnemiBlock(this.lvl);
                        this.counterTime = 3;
                    }
                    break;/*
                case gameState.restart:
                    break;
                case gameState.nextLevel:
                    break;
                case gameState.menu:
                    break;*/
            }
        }