Beispiel #1
0
 public void initSnake()
 {
    dir = snakeDir.DROITE;
     GameElement head = new GameElement(GameElement.ElementName.SNAKEHEAD, 50, 10);
     //GameElement corps = new GameElement(GameElement.ElementName.SNAKEBODY, 40, 10);
     MySnake.Add(head);
     //MySnake.Add(corps);
     this.Controls.Add(head);
    // this.Controls.Add(corps);
     addSnake(4);
     addStuff(true);
     addStuff(false);
     gameStop = false;
     score = 0;
 }
Beispiel #2
0
 public void addSnake(int x) //x: nb de morceau
 {
     int i;
     for (i = 0; i < x; i++)
     {
         GameElement corps = new GameElement(GameElement.ElementName.SNAKEBODY, MySnake.ElementAt(MySnake.Count-1).PosX -  10, MySnake.ElementAt(MySnake.Count-1).PosY);
         MySnake.Add(corps);
         this.Controls.Add(corps);
     }
 }
Beispiel #3
0
        public void collision( GameElement type)
        {
            if (type.Nom1 == GameElement.ElementName.FRUIT)
            {
                addSnake(1);
                this.Controls.Remove(type);
                MyFruit.Remove(type);
                addStuff(true);
                addStuff(false);
                countScore();

            }

            if (type.Nom1 == GameElement.ElementName.WALL || type.Nom1 == GameElement.ElementName.SNAKEBODY) 
            {
              
                gameStop = true;

                //Issu de Demo ECE SE
                //MessageBox.Show("Score= "+score, "colision mur", MessageBoxButtons.OK);
                //DemoUserControl.UserEntryForm.UcScore = "" + Project_Snake.GameView.Score;
                //Appel de la fenêtre pour enregistrer les scores
                DemoUserControl.UserEntryForm uef = new DemoUserControl.UserEntryForm();
                DialogResult dr = uef.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    MessageBox.Show(uef.TheValue);
                    //Affichage d'une fenêtre récapitulative
                    
                }
                else
                {
                    //Rien
                }
            }

            

        }
Beispiel #4
0
        public GameElement testCollision()
        {
            
            bool superposition = true;
            int x = MySnake.ElementAt(0).PosX;
            int y = MySnake.ElementAt(0).PosY;
            int i;
            GameElement obstacle = new GameElement();


            for (i = 1; i < MySnake.Count; i++)
            {
                if ((MySnake.ElementAt(i).PosX == x) && (MySnake.ElementAt(i).PosY == y)) { superposition = true; obstacle = MySnake.ElementAt(i); }
                else { }
            }
                foreach (GameElement part in MyMur)
                {
                    if ((part.PosX == x) && (part.PosY == y)) {superposition = true; obstacle = part; }
                    else { }
                }

                foreach (GameElement part in MyFruit)
                {
                    if ((part.PosX == x) && (part.PosY == y)){ superposition = true; obstacle = part; }
                    else {}
                }

                if (superposition) return obstacle;
                else return null;
                

            
            

        }
Beispiel #5
0
 public void collisionAll()
 {
     GameElement obstacle = new GameElement();
     obstacle = testCollision();
     if (obstacle != null) collision(obstacle);
     else { }
 }
Beispiel #6
0
        public void addStuff(bool Fruit) // si 1 ajoute un fruit si 0 ajoute un mur
        {
            int x = 0, y = 0;
            bool superpositionS=false;
            bool superpositionW = false;
            bool superpositionF = false;
            bool superposition = true;
            while(superposition)
            {
                superpositionS = false;
                superpositionW = false;
                superpositionF = false;
                Random rnd = new Random();
                x = rnd.Next(0, 30 * Exemple.Width);
                y = rnd.Next(0, 10 * Exemple.Height);
                x = x - (x % 10);
                y = y - (y % 10);
                

            foreach(GameElement part in MySnake)
            {
                if ((part.PosX == x) && (part.PosY == y)) superpositionS = true;
                else { }
            }
            
            foreach(GameElement part in MyMur)
            {
                if ((part.PosX == x) && (part.PosY == y)) superpositionW = true;
                else { }
            }

            foreach(GameElement part in MyFruit)
            {
                if ((part.PosX == x) && (part.PosY == y)) superpositionF = true;
                else { }
            }
            if (superpositionF || superpositionS || superpositionW) superposition = true;
            else superposition = false;

            }

            if (!Fruit)
            {
                GameElement newBrique = new GameElement(GameElement.ElementName.WALL, x, y);
                MyMur.Add(newBrique);
                this.Controls.Add(newBrique);
            }
            else
            {
                GameElement newFruit = new GameElement(GameElement.ElementName.FRUIT, x, y);
                MyFruit.Add(newFruit);
                this.Controls.Add(newFruit);
            }
        }
Beispiel #7
0
         public void limiteSnake( GameElement corps)
         {
             if (corps.PosX == this.Size.Width ) { corps.PosX = 0; }
             if (corps.PosX < 0) { corps.PosX = this.Size.Width-10; }
             if (corps.PosY < 0) { corps.PosY = this.Size.Height- 10; }
             if (corps.PosY == this.Size.Height) { corps.PosY = 0; }

         }