亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

來自 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 關注
  • 131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號