Android Java的玩家得分

时间:2014-03-13 04:07:37

标签: java android

我正在使用android java进行游戏评分。我的问题是玩家1的得分没有显示,但玩家2的得分确实显示出来。另一个问题是玩家1的得分是为玩家2增加得分。

这是我的代码:

private static int player = 1;
int Pscore1;
int Pscore2;

String win;

if (dice1 == dice2)
            {

                text.setText("Player " + (new Integer(player)).toString() + " wins !");

                if (win == "Player " + (new Integer(player)).toString())
                {
                    Pscore1++;
                    TextView result = (TextView) findViewById (R.id.textView2);
                    result.setText("Player 1 Score :" + Pscore1 + " || Player 2 Score :" + Pscore2);
                }

                else 
                {
                    Pscore2++;
                    TextView result = (TextView) findViewById (R.id.textView2);
                    result.setText("Player 1 Score :" + Pscore1 + " || Player 2 Score :" + Pscore2);
                }

            }

1 个答案:

答案 0 :(得分:0)

使用win.equals("Player" + new Integer(player).toString())代替if (win == "Player " + (new Integer(player)).toString())

希望这有帮助。