【发布时间】:2014-05-27 07:40:30
【问题描述】:
我有一个棋盘游戏,它的大小是500 (w) x 420 (h),我还有一个球,它的初始位置是w/2 and h,相对于棋盘中间底部的x 和y 轴。但是,当我运行程序时,球总是放在窗外。这对我来说毫无意义,因为我只将球的 y 位置设置为等于高度。这是一个小故障还是我在这里做错了什么?
这是我的代码片段:
private double ballrealcoordinatex; //Ball's x coordinate measured in real numbers
private double ballrealcoordinatey; //Ball's y coordinate measured in real numbers
private int ballintx; //The integer x-coordinate of the ball
private int ballinty; //The integer y-coordinate of the ball
public Form1()
{
InitializeComponent();
//Set start position of the ball
ballrealcoordinatex = (double)(Width / 2 - ballradius);
ballrealcoordinatey = Height; // (double)(Height / 2 - ballradius);
ballintx = (int)System.Math.Round(ballrealcoordinatex);
ballinty = (int)System.Math.Round(ballrealcoordinatey);
}
【问题讨论】:
-
张贴截图和更完整的代码来复制问题...顺便说一句,winforms 不适合这个老实说...
-
@walther:我刚刚编辑了我的原始帖子。这是我班上的作业,需要使用winforms。我已经想通了一切,只是尺寸没有按我预期的那样工作。
-
您在球的哪个部分设置 y 坐标?如果它是顶部,则设置
ballrealcoordinatey = Height;在窗口之外。如果将其设置为 100 会发生什么?