c# - Implementing a 2D Map -


i posted q. earlier arrays , replies lead me change game design. i'm building 2d game map tiles (cells). need add pen line cells, representing wall cannot pass through. pen line represented cell.topwall, cell.bottomwall etc etc of type boolean shown in code. whole app far. draws grid without pen lines walls. take note of commented out code have tried different things stating walls go array of 0's (no wall) , 1's (walls). question is, can hint on how implement walls like? hope have shared enough information app. thanks

cell.cs

    using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms;  namespace map {     public class cell : picturebox     {         bool leftwall;          bool topwall;          bool rightwall;         bool bottomwall;     } } 

form1.cs

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms;  namespace map {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }         /// <summary>         /// array of tiles         /// </summary>         //picturebox[,] boxes = new picturebox[4,4];         cell[,] map = new cell[4,4];          /*int [][] boxes = new int[][] {       new int[] {0,0}, new int[] {1,0,0,1},       new int[] {1,0}, new int[] {1,0,1,0},       new int[] {0,1}, new int[] {0,0,0,1},        new int[] {1,1}, new int[] {1,1,1,0},        new int[] {2,0}, new int[] {1,1,0,0},       new int[] {2,1}, new int[] {0,0,0,1},        new int[] {3,1}, new int[] {1,0,1,0},        new int[] {0,2}, new int[] {0,0,1,1},        new int[] {1,2}, new int[] {1,0,1,0},        new int[] {2,2}, new int[] {0,1,1,0}};*/          #region runtime load         /// <summary>         /// build map when window loaded         /// </summary>         /// <param name="sender"></param>         /// <param name="e"></param>         private void form1_load(object sender, eventargs e)         {             buildmap();         }         #endregion          #region build grid         /// <summary>         /// draw every tile on map         /// </summary>         public void buildmap()         {             (int row = 0; row < 3; row++)             {                 (int column = 0; column < 3; column++)                 {                     drawbox(row, column);                 }             }             //draw exit box             drawbox(1, 3);         }         #endregion          #region draw         /// <summary>         /// draw 1 tile         /// </summary>         /// <param name="row"></param>         /// <param name="column"></param>         public void drawbox(int row, int column)         {             map[row, column] = new cell();             map[row, column].height = 100;             map[row, column].width = 100;             map[row, column].borderstyle = borderstyle.fixedsingle;             map[row, column].backcolor = color.burlywood;             map[row, column].location = new point((map[row, column].width * column), (map[row, column].height * row));             this.controls.add(map[row, column]);              system.drawing.pen mypen;             mypen = new system.drawing.pen(system.drawing.color.red);             system.drawing.graphics formgraphics = this.creategraphics();               //formgraphics.drawline(mypen, 0, 0, 200, 200);             //mypen.dispose();             //formgraphics.dispose();         }         #endregion     }   } 


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -