本文介绍了吉格尔不会攻击树木生命的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Sprite gigel = new Sprite(WindowsFormsApplication2.Properties.Resources.Gigel_img); Sprite tree = new Sprite(WindowsFormsApplication2.Properties.Resources.tree_img); void Screen_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.E) { gigel.Atack(tree.life); tree.LifeUpdate(); } gigel.Reposition(); Refresh(); }...inside Sprite class public void Atack(int targetLife) { targetLife -= damage; } 'targetLife'正在减少符合'损害' 但是没有将值OUT传递给tree.life来自gigel.Atack(tree.life); tree.life没有从流程中获得价值!为什么?或者我做错了什么? 谢谢。 我尝试了什么: 'targetLife' is decrementing conform 'damage' but is not passing the value OUT to tree.life from "gigel.Atack(tree.life);"tree.life is not getting the value from process ! Why? Or what i am doing wrong?Thank you.What I have tried://I hope now is more clear: if (e.KeyCode == Keys.E) { int num = 20; gigel.Atack(num); tree.life = num; // num is 20 and not 7 tree.LifeUpdate(); }...inside Sprite class public void Atack(int targetLife) //targetLife = 20 { targetLife -= damage; // 20-13 targetLife=7 //from this point (num) must take targetLife value of 7 //but (num) remains at 20. } 推荐答案 public void Attack(Sprite target) => target.life -= damage;然后,让 gigel 攻击树,你会做以下事情: Then, to have a gigel attack a tree, you would do the following:gigel.Attack(tree); 这篇关于吉格尔不会攻击树木生命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 20:45