[英]Hello android sudoku to check if the game is complete to display a dialog box
I am trying to display a dialog box in the hello Android Sudoku example but when I run the app nothing happens. 我试图在您好Android Sudoku示例中显示一个对话框,但是当我运行该应用程序时,没有任何反应。 In the game.java I check if the puzzle is solved like this
在game.java中,我检查拼图是否像这样解决
/******Check to see if the game is complete**/
public boolean isSolved()
{
for (int element : puzzle) {
if (element == 0) return false;
}
return true;
}
Then in the PuzzleView in the onKeyDown method i try to detect if isSolved is true and if it is display the dialog 然后在onKeyDown方法中的PuzzleView中,我尝试检测isSolved是否为true,是否显示对话框。
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (game.isSolved() == true) {
Intent i = new Intent(mActivity, Congratulations.class);
getContext().startActivity(i);
} else {
Log.d(TAG, "onKeyDown: keycode=" + keyCode + ", event=" + event);
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
select(selX, selY - 1);
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
select(selX, selY + 1);
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
select(selX - 1, selY);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
select(selX + 1, selY);
break;
case KeyEvent.KEYCODE_0:
case KeyEvent.KEYCODE_SPACE:
setSelectedTile(0);
break;
case KeyEvent.KEYCODE_1:
setSelectedTile(1);
break;
case KeyEvent.KEYCODE_2:
setSelectedTile(2);
break;
case KeyEvent.KEYCODE_3:
setSelectedTile(3);
break;
case KeyEvent.KEYCODE_4:
setSelectedTile(4);
break;
case KeyEvent.KEYCODE_5:
setSelectedTile(5);
break;
case KeyEvent.KEYCODE_6:
setSelectedTile(6);
break;
case KeyEvent.KEYCODE_7:
setSelectedTile(7);
break;
case KeyEvent.KEYCODE_8:
setSelectedTile(8);
break;
case KeyEvent.KEYCODE_9:
setSelectedTile(9);
break;
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
game.showKeypadOrError(selX, selY);
break;
default:
return super.onKeyDown(keyCode, event);
}
return false;
}
return false;
}
I am learning java and Android development so please any help as to where I am going wrong will be much appreciated. 我正在学习Java和Android开发,因此请向我提供任何有关我出问题的地方的帮助。 If anyone needs more information please just ask and I will put it in an edit section for the question.
如果有人需要更多信息,请问,我将它放在问题的编辑部分中。
WillNZ this is not answer, just to show you how put the log WillNZ这不是答案,只是向您展示如何放置日志
/******Check to see if the game is complete**/
public boolean isSolved()
{
for (int element : puzzle) {
if (element == 0) return false;
}
Log.d("TAG", " isSolved() is true");
return true;
}
Run your application and see if you can see " isSolved() is true" in your logcat. 运行您的应用程序,看看您是否可以在logcat中看到“ isSolved()为true”。
In the end the way I checked to see if the game was complete was to have this in the game.class 最后,我检查游戏是否完成的方法是将其包含在game.class中
/****** Check to see if the game is complete **/
public boolean isSolved() {
for (int element : puzzle) {
if (element == 0)
return false;
}
return true;
}
And also 并且
public boolean checkIsSolved()
{
//check if the game is complete after each valid move
if (isSolved() == true) {
Intent i = new Intent(this, Congratulations.class);
startActivity(i);}
else
{
return false;
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.