【发布时间】:2017-09-16 12:41:18
【问题描述】:
我正在 Visual Studio 中创建一个口袋妖怪类型的游戏。我现在正在处理库存表格。
我的问题是我可以使用公共计数变量来跟踪库存吗?
设置:
public int healthPotionCount = 0;
如果玩家遇到健康药水会增加它的价值
if(picPlayer.Bounds.IntersectsWith(hPotion.Bounds)
{
healthPotionCount++;
}
最终使用同一个公共变量来确定是否在清单中显示:
if(healthPotionCount > 0)
{
picBox.BackgroundImage = (the health potion image);
lblQuantity.Text = ""+healthPotionCount;
}
有了这个,我的问题是我的解决方案中有很多表单,我希望所有表单都可以访问这个变量。这个逻辑是不是太笨拙了?
【问题讨论】:
标签: c# variables logic counter public