为了账号安全,请及时绑定邮箱和手机立即绑定

来自 for 循环的 Caling 类

来自 for 循环的 Caling 类

PHP
莫回无 2024-01-20 21:01:03
我正在使用 Visual Studio C# 表单,我有一个具有以下属性的类:string Name;int NumberOfHitBoxes;Point Hit1;Point Hit2;Point Hit3;我有一个 mouseMove 事件,可以检测鼠标是否在“hitbox”中,它可以正常工作,如下所示:(在其他部分( p.Hit1.X ))picture.MouseMove += (sender,  e) =>                            {                                var c = sender as PictureBox;                                bool h=false;                                if (null == c) return;                                if (_dragging)                                {                                c.Top = e.Y + c.Top - _yPos;                                c.Left = e.X + c.Left - _xPos;                                }                                else                                {                                       if ((e.X>p.Hit1.X)&&(e.X<p.Hit1.X+hitw)&&(e.Y>p.Hit1.Y)&&(e.Y<p.Hit1.Y+hitw)){hitbox(c,p.Hit1.X,p.Hit1.Y,8);h=true;tb.Text = p.Type;hitok = p.Input1Point;}                                      if ((e.X>p.Hit2.X)&&(e.X<p.Hit2.X+hitw)&&(e.Y>p.Hit2.Y)&&(e.Y<p.Hit2.Y+hitw)){hitbox(c,p.Hit2.X,p.Hit2.Y,8);h=true;tb.Text = p.Type;hitok = p.Input2Point;}                                     if ((e.X>p.Hit3.X)&&(e.X<p.Hit3.X+hitw)&&(e.Y>p.Hit3.Y)&&(e.Y<p.Hit3.Y+hitw)){hitbox(c,p.Hit3.X,p.Hit3.Y,8);h=true;tb.Text = p.Type;hitok = p.Output1Point;}                                 }                                if (!h){picture.Refresh();h=false;hitok = new Point(0,0);}                            };简化:int x = 1;int whatever = p["Hit"+x.ToString()].X;而不是这个:int whatever = p.Hit1.X;一些聪明的人也许可以教像我这样的笨蛋一些小技巧?
查看完整描述

1 回答

?
RISEBY

TA贡献1856条经验 获得超5个赞

你的班


public class Phit

{

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


  public Phit(List<Point> hitboxes)

  {

    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);

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;

    }

}    


查看完整回答
反对 回复 2024-01-20
  • 1 回答
  • 0 关注
  • 26 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信