コード例 #1
0
        public void KillNetterPillar(Netterpillar netterpillar)
        {
            netterpillar.IsDead = true;
            // Clears the game field
            arrGameField[netterpillar.Location.X, netterpillar.Location.Y] = GameObjects.Empty;
            netterpillar.Erase(ScreenWinHandle);

            for (int i = 0; i < netterpillar.NetterBodyLength; i++)
            {
                arrGameField[netterpillar.NetterBody[i].Location.X, netterpillar.NetterBody[i].Location.Y] = GameObjects.Empty;
                netterpillar.NetterBody[i].Erase(ScreenWinHandle);
            }
        }
コード例 #2
0
        public void KillNetterPillar(Netterpillar netterpillar)
        {
            netterpillar.IsDead = true;
            // Clears the game field
            arrGameField[netterpillar.Location.X, netterpillar.Location.Y] = GameObjects.Empty;
            netterpillar.Erase(ScreenWinHandle);

            for(int i=0; i<netterpillar.NetterBodyLength; i++) {
                arrGameField[netterpillar.NetterBody[i].Location.X, netterpillar.NetterBody[i].Location.Y] = GameObjects.Empty;
                netterpillar.NetterBody[i].Erase(ScreenWinHandle);
            }
        }
コード例 #3
0
        public void CreateGameField(System.IntPtr winHandle)
        {
            branches = new Branch[5];

            arrGameField = new GameObjects[Width+1, Height+1];

            // Reset the game variables
            GameOver = false;
            Paused = false;
            // Reset the mushroomNumber, forcing a call to the property procedure
            Mushrooms = Mushrooms;

            ScreenWinHandle = winHandle;

            // Initialize the game array (for collision detection)
            for(int x=0; x<Width; x++) {
                for(int y=0; y<Height; y++) {
                    arrGameField[x, y] = GameObjects.Empty;
                }
            }

            // Create the Netterpillars
            for(int i=0; i<NetterpillarNumber; i++) {
                netterPillars[i] = null;
            }
            switch(NetterpillarNumber) {
                case 1:
                    netterPillars[0] = new Netterpillar((int)(this.Width/2), (int)(this.Height)/2, Sprite.CompassDirections.South, false);
                    break;
                case 2:
                    netterPillars[0] = new Netterpillar((int)(this.Width/3), (int)(this.Height)/2, Sprite.CompassDirections.South, false);
                    netterPillars[1] = new Netterpillar((int)(this.Width/3)*2, (int)(this.Height)/2, Sprite.CompassDirections.North, true);
                    break;
                case 3:
                    netterPillars[0] = new Netterpillar((int)(this.Width/4), (int)(this.Height)/2, Sprite.CompassDirections.South, false);
                    netterPillars[1] = new Netterpillar((int)(this.Width/4)*2, (int)(this.Height)/2, Sprite.CompassDirections.North, true);
                    netterPillars[2] = new Netterpillar((int)(this.Width/4)*3, (int)(this.Height)/2, Sprite.CompassDirections.South, true);
                    break;
                case 4:
                    netterPillars[0] = new Netterpillar((int)(this.Width/3), (int)(this.Height)/3, Sprite.CompassDirections.South, false);
                    netterPillars[1] = new Netterpillar((int)(this.Width/3), (int)(this.Height)/3*2, Sprite.CompassDirections.East, true);
                    netterPillars[2] = new Netterpillar((int)(this.Width/3)*2, (int)(this.Height)/3*2, Sprite.CompassDirections.North, true);
                    netterPillars[3] = new Netterpillar((int)(this.Width/3)*2, (int)(this.Height)/3, Sprite.CompassDirections.West, true);
                    break;
            }
            Player1 = netterPillars[0];

            // Populates the array with the netterpillars
            for(int i=0; i<NetterpillarNumber; i++) {
                arrGameField[netterPillars[i].Location.X, netterPillars[i].Location.Y] = GameObjects.Netterpillar;
                for(int j=0; j<netterPillars[i].NetterBodyLength; j++) {
                    arrGameField[netterPillars[i].NetterBody[j].Location.X, netterPillars[i].NetterBody[j].Location.Y] = GameObjects.Netterpillar;
                }
            }

            // Create the branches
            //    We'll create four branches here just to generate a cleaner code,
            //    we could use the same approach used on the mushrooms below
            branches[0] = new Branch(Sprite.CompassDirections.North, this.Height);
            branches[1] = new Branch(Sprite.CompassDirections.North, this.Height);
            branches[2] = new Branch(Sprite.CompassDirections.East, this.Width-2);
            branches[3] = new Branch(Sprite.CompassDirections.East, this.Width-2);
            for(int x=0; x<Width; x++) {
                arrGameField[x, 0] = GameObjects.Branch;
                arrGameField[x, Height-1] = GameObjects.Branch;
            }
            for(int y=0; y<=Height; y++) {
                arrGameField[0, y] = GameObjects.Branch;
                arrGameField[Width-1, y] = GameObjects.Branch;
            }

            // Create the mushrooms
            //   Since all the mushroom control is on the array, we don't need to create one object per mushroom
            //   in the screen, we'll rather draw one single mushroom in many positions (on the redraw sub)
            objMushrooms = new Mushroom();
            int randx, randy;
            for(int i=0; i<MushroomNumber; i++) {
                // Check to seek if we are not creating the mushrooms over other objects
                do {
                    randx = rand.Next(0, this.Width-2)+1;
                    randy = rand.Next(0, this.Height-2)+1;
                } while(arrGameField[randx, randy]!=GameObjects.Empty);
                arrGameField[randx, randy] = GameObjects.Mushroom;
            }

            Redraw();
        }
コード例 #4
0
        public void CreateGameField(System.IntPtr winHandle)
        {
            branches = new Branch[5];

            arrGameField = new GameObjects[Width + 1, Height + 1];

            // Reset the game variables
            GameOver = false;
            Paused   = false;
            // Reset the mushroomNumber, forcing a call to the property procedure
            Mushrooms = Mushrooms;

            ScreenWinHandle = winHandle;

            // Initialize the game array (for collision detection)
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    arrGameField[x, y] = GameObjects.Empty;
                }
            }

            // Create the Netterpillars
            for (int i = 0; i < NetterpillarNumber; i++)
            {
                netterPillars[i] = null;
            }
            switch (NetterpillarNumber)
            {
            case 1:
                netterPillars[0] = new Netterpillar((int)(this.Width / 2), (int)(this.Height) / 2, Sprite.CompassDirections.South, false);
                break;

            case 2:
                netterPillars[0] = new Netterpillar((int)(this.Width / 3), (int)(this.Height) / 2, Sprite.CompassDirections.South, false);
                netterPillars[1] = new Netterpillar((int)(this.Width / 3) * 2, (int)(this.Height) / 2, Sprite.CompassDirections.North, true);
                break;

            case 3:
                netterPillars[0] = new Netterpillar((int)(this.Width / 4), (int)(this.Height) / 2, Sprite.CompassDirections.South, false);
                netterPillars[1] = new Netterpillar((int)(this.Width / 4) * 2, (int)(this.Height) / 2, Sprite.CompassDirections.North, true);
                netterPillars[2] = new Netterpillar((int)(this.Width / 4) * 3, (int)(this.Height) / 2, Sprite.CompassDirections.South, true);
                break;

            case 4:
                netterPillars[0] = new Netterpillar((int)(this.Width / 3), (int)(this.Height) / 3, Sprite.CompassDirections.South, false);
                netterPillars[1] = new Netterpillar((int)(this.Width / 3), (int)(this.Height) / 3 * 2, Sprite.CompassDirections.East, true);
                netterPillars[2] = new Netterpillar((int)(this.Width / 3) * 2, (int)(this.Height) / 3 * 2, Sprite.CompassDirections.North, true);
                netterPillars[3] = new Netterpillar((int)(this.Width / 3) * 2, (int)(this.Height) / 3, Sprite.CompassDirections.West, true);
                break;
            }
            Player1 = netterPillars[0];

            // Populates the array with the netterpillars
            for (int i = 0; i < NetterpillarNumber; i++)
            {
                arrGameField[netterPillars[i].Location.X, netterPillars[i].Location.Y] = GameObjects.Netterpillar;
                for (int j = 0; j < netterPillars[i].NetterBodyLength; j++)
                {
                    arrGameField[netterPillars[i].NetterBody[j].Location.X, netterPillars[i].NetterBody[j].Location.Y] = GameObjects.Netterpillar;
                }
            }

            // Create the branches
            //    We'll create four branches here just to generate a cleaner code,
            //    we could use the same approach used on the mushrooms below
            branches[0] = new Branch(Sprite.CompassDirections.North, this.Height);
            branches[1] = new Branch(Sprite.CompassDirections.North, this.Height);
            branches[2] = new Branch(Sprite.CompassDirections.East, this.Width - 2);
            branches[3] = new Branch(Sprite.CompassDirections.East, this.Width - 2);
            for (int x = 0; x < Width; x++)
            {
                arrGameField[x, 0]          = GameObjects.Branch;
                arrGameField[x, Height - 1] = GameObjects.Branch;
            }
            for (int y = 0; y <= Height; y++)
            {
                arrGameField[0, y]         = GameObjects.Branch;
                arrGameField[Width - 1, y] = GameObjects.Branch;
            }

            // Create the mushrooms
            //   Since all the mushroom control is on the array, we don't need to create one object per mushroom
            //   in the screen, we'll rather draw one single mushroom in many positions (on the redraw sub)
            objMushrooms = new Mushroom();
            int randx, randy;

            for (int i = 0; i < MushroomNumber; i++)
            {
                // Check to seek if we are not creating the mushrooms over other objects
                do
                {
                    randx = rand.Next(0, this.Width - 2) + 1;
                    randy = rand.Next(0, this.Height - 2) + 1;
                } while(arrGameField[randx, randy] != GameObjects.Empty);
                arrGameField[randx, randy] = GameObjects.Mushroom;
            }

            Redraw();
        }