0

以前に配列に関する Q. を投稿しましたが、その回答がきっかけでゲーム デザインを変更することになりました。タイル (セル) から 2D ゲーム マップを作成しています。通り抜けられない壁を表すペンの線をいくつかのセルに追加する必要があります。このペン線は、私のコードに示すように、ブール型の Cell.TopWall、Cell.BottomWall などで表されます。これはこれまでの私のアプリ全体です。壁のペン線なしでグリッドを描画します。0 (壁なし) と 1 (壁) の配列で壁の場所を示すなど、さまざまなことを試したコメントアウトされたコードに注意してください。私の質問は、私が望む壁を実装する方法についてのヒントを得ることができますか? アプリに関する十分な情報を共有できたことを願っています。ありがとう

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 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