源码,vs2010开发。部分代码:
private void Form1_Load(object sender, EventArgs e)
{
Source = (Bitmap)Image.FromFile("..\\..\\res\\animal.bmp");
this.pictureBox1.Height = W * (m_nRow + 2);
this.pictureBox1.Width = W * (m_nCol+2);
this.pictureBox1.Top = 0;
this.pictureBox1.Left = 0;
//当前窗体标题栏高度
int d = (this.Height - this.ClientRectangle.Height);
this.Height = this.pictureBox1.Height + this.pictureBox1.Top+ d;
this.Width = this.pictureBox1.Width + this.pictureBox1.Left ;
//for (int i = 0; i < 10 * 10; i++)
//{
// m_map[i] = i % 6;
//}
StartNewGame();
Init_Graphic();
}
private void StartNewGame()
{
//初始化地图,将地图中所有方块区域位置置为空方块状态
for(int iNum=0;iNum<(m_nCol*m_nRow);iNum++)
{
m_map[iNum] = BLANK_STATE;
}
Random r = new Random();
//生成随机地图
//将所有的动物物种放进一个临时的地图tmpMap中
ArrayList tmpMap=new ArrayList ();
for(int i=0;i<(m_nCol*m_nRow)/4;i++)
for(int j=0;j<4;j++)
tmpMap.Add(i);
//每次从上面的临时地图tmpMap中取走(获取后并在临时地图删除)
//一个动物放到地图的空方块上
for (int i = 0; i < m_nRow * m_nCol; i++)
{
//随机挑选一个位置
int nIndex = r.Next() % tmpMap.Count ;
//获取该选定物件放到地图的空方块
m_map[i]=(int)tmpMap[nIndex];
//在临时地图tmpMap除去该动物
tmpMap.RemoveAt(nIndex);
}
}
private void Init_Graphic()
{
Graphics g = get_Graphic(); //生成Graphics对象
for (int i = 0; i< 10 * 10; i++)
{
g.DrawImage(create_image(m_map[i]), W * (i % GameSize)+W,
W * (i / GameSize)+W, W, W);
}
}
评论4
最新资源