-
Notifications
You must be signed in to change notification settings - Fork 0
Maze
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;
}
При повик на оваа функција се црта на формата 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());
}