Skip to content
Marija Gjorgjieva edited this page Jul 3, 2022 · 1 revision

Во Maze класата се содржат сите променливи, објекти и методи кои се потребни за креирање и цртање на лавиринтот.

  • myImage: нстанца од класа Image , слика која се користи за текстура на brush
  • brush: инстанца од класа TextureBrush , се користи за цртање на лавиринтот
  • g: инстанца од класа Graphics, се користи за цртање на лавиринтот
  • Obstacles: листа од објекти од тип Rectangle
  • Matriх: integer матрица која служи за креирање на лавиринтот, понатамошна навигација на карактерите и детектирање на нивна колизија, вредност 1 претставува ѕид, а 0 претставува патека
        private static Image myImage = Properties.Resources.BrickTile;
        private static TextureBrush brush = new TextureBrush(myImage);
        private Graphics g;
        private List<Rectangle> Obstacles { get; set; }
        public int[,] Matrix { set; get; } = new int[20, 20];
       
        public Maze(Graphics g)
        {
            Matrix = new int[,] {
                { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
                { 1,1,1,0,1,0,1,1,1,1,0,0,1,1,0,1,0,1,1,1 },
                { 1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,1,1 },
                { 1,0,0,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,0,1 },
                { 1,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,1,0,0,1 },
                { 1,1,0,1,0,1,0,0,0,1,1,0,0,0,1,0,1,0,1,1 },
                { 1,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1 },
                { 1,0,0,0,0,0,0,1,1,3,0,1,1,0,0,1,0,0,0,1 },
                { 1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1 },
                { 1,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,0,1 },
                { 1,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,0,1 },
                { 1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1 },
                { 1,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,0,0,0,1 },
                { 1,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1 },
                { 1,1,0,1,0,1,0,0,0,1,1,0,0,0,1,0,1,0,1,1 },
                { 1,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,1,0,0,1 },
                { 1,0,0,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,0,1 },
                { 1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,1,1 },
                { 1,1,1,0,1,0,1,1,1,1,0,0,1,1,0,1,0,1,1,1 },
                { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
            };
            Obstacles = new List<Rectangle>();
            this.g = g;
        }

SetUpMaze

При повик на оваа функција се црта на формата gameScreen листата од правоаголници Obstacles, односно се креира лавиринтот на играта.

         public void SetUpMaze()
        {
            brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
            int startX = 0;
            int startY = 0;
            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    if (Matrix[i, j] == 1)
                    {
                        Rectangle rectangle = new Rectangle(startX, startY, 40, 40);
                        Obstacles.Add(rectangle);
                    }
                    startX += 40;
                }
                startX = 0;
                startY += 40;
            }
            g.FillRectangles(brush, Obstacles.ToArray());

        }
Clone this wiki locally