在defineMapCellPositions() 和defineMapCellWalls() 期间,map.cols 和map.rows 从4 和5 等值更改为0,仅用于方法的逐步执行。调试器的一个步骤证实了这一点。为什么是这样?
任何帮助表示赞赏,谢谢!
整个地图类
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;
public class Map
{
public Map()
{
}
public int rows { get; set; }
public int cols { get; set; }
public int boardXPos { get; set; }
public int boardYPos { get; set; }
public int squareSize { get; set; }
private List<List<int>> m_cellPositions = new List<List<int>>();
public List<List<int>> cellPositions
{
get
{
return m_cellPositions;
}
set
{
m_cellPositions = value;
}
}
private List<List<int>> m_cellWalls = new List<List<int>>();
public List<List<int>> cellWalls
{
get
{
return m_cellWalls;
}
set
{
m_cellWalls = value;
}
}
}
MapController 类的开始
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;
public class MapController
{
public MapController()
{
}
Map map = new Map();
设置 map.cellWalls 的方法
public void defineCellWallsList()
{
//map.cellWalls.Clear();
for (int row = 0; row < (map.rows * map.cols); row++)
{
map.cellWalls.Add(new List<int> { 0, 0 });
}
}
设置 map.cellPositions 的方法
public void defineCellPositionsList()
{
//map.cellPositions.Clear();
for (int row = 0; row < map.rows; row++)
{
for (int col = 0; col < map.cols; col++)
{
map.cellPositions.Add(new List<int> { col, row });
}
}
}