Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从for循环校准类_C#_Class_For Loop - Fatal编程技术网

C# 从for循环校准类

C# 从for循环校准类,c#,class,for-loop,C#,Class,For Loop,我正在使用Visual studio c#表单 我有一个具有以下属性的类: string Name; int NumberOfHitBoxes; Point Hit1; Point Hit2; Point Hit3; 我有一个mouseMove事件,可以检测鼠标是否在“hitbox”中,它的工作原理如下:(在else部分(p.Hit1.X)) 与此相反: int whatever = p.Hit1.X; 某个聪明聪明的人也许可以教我这样的笨蛋一个小把戏 你的班级 public class P

我正在使用Visual studio c#表单 我有一个具有以下属性的类:

string Name;
int NumberOfHitBoxes;
Point Hit1;
Point Hit2;
Point Hit3;
我有一个mouseMove事件,可以检测鼠标是否在“hitbox”中,它的工作原理如下:(在else部分(p.Hit1.X))

与此相反:

int whatever = p.Hit1.X;
某个聪明聪明的人也许可以教我这样的笨蛋一个小把戏

你的班级

public class Phit
{
  public List<Point> HitBoxes { get; private set; }

  public Phit(List<Point> hitboxes)
  {
    HitBoxes = hitboxes;
  }
}
公共类Phit
{
公共列表命中框{get;private set;}
公共Phit(列出复选框)
{
点击框=点击框;
}
}
使用hitbox初始化类

List<Point> hitboxes = new List<Point>
{
    new Point(1.2, 1.5),
    new Point(1.2, 3.0),
    new Point(1.2, 4.5)
};

Phit phit = new Phit(hitboxes);
List hitboxs=新列表
{
新的点(1.2,1.5),
新点(1.2,3.0),
新观点(1.2、4.5)
};
Phit Phit=新Phit(点击框);
MouseMove方法中的循环

foreach(Point p in phit.HitBoxes)
{
    if (e.X > p.X && e.X < p.X + hitw && e.Y > p.Y && e.Y < p.Y + hitw)
    {
        hitbox(c, p.X, p.Y, 8);
        h = true;
        tb.Text = $"X: {p.X} / Y: {p.Y}";
        hitok = p;
    }
}    
foreach(phit.HITBOKS中的点p)
{
如果(e.X>p.X&e.Xp.Y&e.Y
将你的hitbox放入一个列表中,然后在该列表上进行
foreach
循环。我只能给你我通常的免责声明:这看起来像是游戏开发。GUI桌面技术不是开发游戏的正确方法。如果不使用图形,纯TurneBSAD单或hotseat Multipartyer是首选。旧的Windows Solitair大约是其支持的上限。为了正确的游戏开发,你需要有游戏循环的东西:@dymanoid god idea,我会试试,但我需要获得“inputpoint 1,2等”的分数。我会看看是否可以从连接点创建hitbox。@Christopher这与游戏无关。我正在安排“在表单上设置逻辑门,然后我可以在输入/输出之间绘制连接线,但要准确地命中这一点非常困难,因此我想在所有输入/输出上创建Hitbox。但你是对的,这不是游戏开发的正确平台。好的解决方案,但我将有500多个门,每个门有3-10个命中框,使用这个解决方案,我必须在每次鼠标移动时运行所有点。我没有足够的经验来阻止男人,如果这不会造成滞后的话。我将尝试为每个组件创建一个hitbox类。
public class Phit
{
  public List<Point> HitBoxes { get; private set; }

  public Phit(List<Point> hitboxes)
  {
    HitBoxes = hitboxes;
  }
}
List<Point> hitboxes = new List<Point>
{
    new Point(1.2, 1.5),
    new Point(1.2, 3.0),
    new Point(1.2, 4.5)
};

Phit phit = new Phit(hitboxes);
foreach(Point p in phit.HitBoxes)
{
    if (e.X > p.X && e.X < p.X + hitw && e.Y > p.Y && e.Y < p.Y + hitw)
    {
        hitbox(c, p.X, p.Y, 8);
        h = true;
        tb.Text = $"X: {p.X} / Y: {p.Y}";
        hitok = p;
    }
}