我有我的第一个Android应用程序,我很难在玩家点击图像视图时如何将单词/单词加倍。基本上,我希望它的功能如下:如果播放器没有单击图像视图,则指向系统保持不变。如果玩家点击了图像视图,则会弹出一条消息(一个吐司或许告诉玩家下一个3个单词的分数将翻倍)。我怎样才能做到这一点?如何将3个连续单词的分数加倍而不超过?
这是我的搜索和计算代码
//CALCULATE SCORE
private int optionTxtView = 0 ; //which textview to use for addition purposes
private int addClick = 0 ; //No. of clicks for search for calculation
private void calculate(){
x = Integer.parseInt(tv3.getText().toString().replaceAll("\\s",""));
y = Integer.parseInt(tv2.getText().toString().replaceAll("\\s",""));
z = x + y;
score.setText(Integer.toString(z));
}
//SEARCH WORD, DISPLAYING SCORE
public void viewWord(View view)
{
String s1= search.getText().toString(); //What word to search
String s2= dbHelper.getData(s1); // If in db, display equivalent score
if(optionTxtView == 0){
//display the score on textview1
tv2.setText(s2);
optionTxtView = 1;
}
else{
if(optionTxtView == 1){
//display the score on textview2
tv3.setText(s2);
optionTxtView = 0;
}
}
//Display search word/s
adapter.add(text.getText().toString());
adapter.notifyDataSetChanged();
if(addClick ==0){
calculate();
addClick = 1;
text.setText("");
generatedString="";
}
else{
if(addClick == 1){
calculate();
addClick = 2;
text.setText("");
generatedString="";
}}
答案 0 :(得分:0)
boolean sDouble = false
imgView.setOnClickListener(new View.OnClickListener() {
//@Override
public void onClick(View v) {
// Show your Toast message
// double = true;
}
});
并且您在运行游戏代码的位置检查sDouble
的值,如果其true
然后将for
循环内的评分系统加倍,或将整数值设置为{{ 1}}并为下一个0
字增加它,之后将3
的值设置回sDouble
。
您可能还需要确保用户在点击一次后点击图片以进行下一次false
尝试。
<强>更新强>:
由于您的得分为3
,因此您需要在执行任何数学运算之前将其解析为String
,请使用Integer
。