0

我之前发布了一个关于数组的问题,这些回复让我改变了我的游戏设计。我正在从瓷砖(细胞)构建一个 2D 游戏地图。我需要在一些单元格中添加一条笔线,代表你无法穿过的墙。这条笔线由布尔类型的 Cell.TopWall、Cell.BottomWall 等表示,如我的代码所示。到目前为止,这是我的整个应用程序。它绘制没有墙壁笔线的网格。注意注释掉的代码,我尝试过不同的事情,比如用 0(无墙)和 1(墙)的数组说明墙的位置。我的问题是,我能得到关于如何在我想要的地方实施墙壁的提示吗?我希望我已经分享了有关我的应用程序的足够信息。谢谢

细胞.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 the map when window is 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 the map
        /// </summary>
        public void BuildMap()
        {
            for (int row = 0; row < 3; row++)
            {
                for (int column = 0; column < 3; column++)
                {
                    DrawBox(row, column);
                }
            }
            //draw the exit box
            DrawBox(1, 3);
        }
        #endregion

        #region Draw
        /// <summary>
        /// Draw one 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
    }


}
4

0 回答 0