我目前在visual studio 2015(C#)上使用xamarin进行了一个项目。 在调试过程中,我注意到了一些奇怪的行为。与按钮绑定的变量的分配值与单击按钮时的值相同。
int choose;
int chooseBuff = 0;
private int clickCounter = 0;
private int clickBuffer = 0;
private int timerInterval = 1000;
Timer timer;
Button btnRed, btnBlue, btnYellow;
Vibrator vibrate;
List<int> patternList = new List<int>();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
vibrate = (Vibrator)GetSystemService(Context.VibratorService);
btnRed = FindViewById<Button>(Resource.Id.btnRed);
btnBlue = FindViewById<Button>(Resource.Id.btnBlue);
btnYellow = FindViewById<Button>(Resource.Id.btnYellow);
//AlertDialog.Builder alert = new AlertDialog.Builder(this);
//alert.SetTitle("");
//alert.SetMessage("You Lose!!");
timer = new Timer();
timer.Interval = timerInterval;
timer.Elapsed += Timer_Elapsed;
timer.Start();
btnRed.Click += BtnRed_Click;
btnBlue.Click += BtnBlue_Click;
btnYellow.Click += BtnYellow_Click;
}
private void BtnYellow_Click(object sender, EventArgs e)
{
vibrate.Vibrate(100);
clickBuffer = 3;
checkClick();
intervalIncrease();
}
private void BtnBlue_Click(object sender, EventArgs e)
{
vibrate.Vibrate(100);
clickBuffer = 2;
checkClick();
intervalIncrease();
}
private void BtnRed_Click(object sender, EventArgs e)
{
vibrate.Vibrate(100);
clickBuffer = 1;
checkClick();
intervalIncrease();
}
当点击btnRed时,clickBuffer变量被赋值为3而不是1.Same转到其他按钮。 bntBlue会将值2赋予clickBuffer,而bntYellow会将值1分配给clickBuffer。我不知道这个价值来自哪里。即使我指定其他值比thoose 3更像clickBuffer = 5甚至&#34; string&#34;它仍然为btnRed赋值3。我真的很困惑。有人能指出我的代码有什么问题吗?
整个项目如果有帮助LightGame。我刚刚开始学习2个月前编程,所以请确保你已经准备好看看我丑陋的代码了。它真的很乱。只需编写代码即可完成任务。很确定它有更好的解决方案..干杯:)..