【发布时间】:2016-08-02 07:31:36
【问题描述】:
我正在做一些学校作业,我想知道你是否能解决这个问题。 我得到了我的 form.cs 代码和我的类 apple.cs(一些蛇果生成) 我选择我的苹果是在表单宽度/高度上随机生成的,但是当我调整该表单的大小时,它会一直在表单的旧“边界”内生成。
我可以重新加载它吗?
class Apple {
Random nc = new Random();
Form1 hl;
//Properties
public Color Color { get; set; }
public Size Size { get; set; }
public Point Pt { get; set; }
//constructors
public Apple()
{
hl = new Form1();
int s = 10;
this.Color = Color.Red;
this.Size = new Size(s,s);
this.Pt = new Point(nc.Next(s,hl.panel1.Width-(2*s-1)),nc.Next(s,hl.panel1.Height-(2*s-1)));
}
//methods
public void drawOutPoint(Graphics kp)
{
kp.FillRectangle(new SolidBrush(Color), new Rectangle(Bod, Size));
}
}
非常感谢!
【问题讨论】: