用于网球游戏app的Java破解条件

时间:2016-05-23 18:35:24

标签: java android

我正在开发Android网球应用程序,现在我需要在网球比赛中保持打破平局分数的条件。

例如,如果第1组得分为6-6,那么决胜局游戏将从1-1,2-2,3-3开始,依此类推。

或者在其他方面,我如何在网球比赛中实施以下代码的决胜局规则

我正在考虑如何在我的应用程序上保持这种状态,但却无法获得它。我是Java的新手,所以任何帮助都会受到赞赏。

/ *         * Player1的方法从下面开始         * * /

    assert countBtn1 != null;
    countBtn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CountA++;

            textViewScore.setText(CountA+"--"+textViewCount1.getText()+"--"+textViewCount2.getText());

            if (CountA == 1) {
                textViewCount1.setText("15");
            } else if (CountA == 2 ) {
                textViewCount1.setText("30");
            } else if (CountA == 3) {
                textViewCount1.setText("40");
            }

            /*
            * After the game is reached to the level of 40-0 for player 1, it checks all the rules of the tennis before finishing the Game
            * */

            else if (CountA == 4) {
                if (CountB == 3 && textViewCount2.getText().toString().equals("40")  && textViewCount1.getText().toString().equals("40")) {
                    textViewCount1.setText("AD");
                   CountA--;
                }
                if (CountB == 4 && textViewCount2.getText().toString().equals("40") && textViewCount1.getText().toString().equals("40")) {
                    textViewCount1.setText("AD");
                    CountA--;
                }
                if (CountA == 4 && textViewCount1.getText().toString().equals("40") && textViewCount2.getText().toString().equals("15")) {
                    textViewCount1.setText("0");
                    textViewCount2.setText("0");
                    CountA--;
                    if(set1 != 7) {
                        set1 = set1 + 1;
                        textView1.setText("" + set1);
                        CountA=0;
                    }
                }
                if (CountA == 4 && textViewCount1.getText().toString().equals("40") && textViewCount2.getText().toString().equals("30")) {
                    textViewCount1.setText("0");
                    textViewCount2.setText("0");
                    CountA--;
                    if(set1 != 7) {
                        set1 = set1 + 1;
                        textView1.setText("" + set1);
                        CountA=0;
                    }
                }
                else if (CountA == 4 && textViewCount1.getText().toString().equals("AD") && textViewCount2.getText().toString().equals("40")) {
                    textViewCount1.setText("0");
                    textViewCount2.setText("0");
                    CountA--;
                    if(set1 != 7) {
                        set1 = set1 + 1;
                        textView1.setText("" + set1);
                        CountA=0;
                        CountB=0;
                    }
                }
                else if (CountA == 4 && textViewCount1.getText().toString().equals("40") && textViewCount2.getText().toString().equals("AD")) {
                    textViewCount1.setText("40");
                    textViewCount2.setText("40");
                    CountA--;
                }
                else if (CountA == 4 && textViewCount1.getText().toString().equals("40") && textViewCount2.getText().toString().equals("0")) {
                    textViewCount1.setText("0");
                    textViewCount2.setText("0");
                    CountA--;

                    /*
                    * The below functions checks the incrementation clause of the game for the sets
                    * */

                    if((set1 <= 4 && set4 != 6 && set2 == 0 && set5 == 0)
                            || (set1 == 5 && set4 !=7 && set2 == 0 && set5 == 0)
                            || (set1 == 5 && set4 == 6 && set2 == 0 && set5 == 0)
                           // || (set1 == 6 && set4 == 6 && set2 == 0 && set5 == 0)
                            || (set1 == 6 && set4 == 5 && set2 == 0 && set5 == 0))

                    {
                        set1 = set1 + 1;
                       // tie1++;
                       // textViewCount1.setText(""+tie1);
                        textView1.setText("" + set1);
                        CountA=0;
                        if((set1 ==6 && set4 <=4 && set2 == 0 && set5 == 0)|| (set1 ==7 && set4 <= 6 && set2 ==0  && set5 == 0))
                        {
                             builder.setMessage("Player 1 wins the 1st set")
                                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {}
                                    });
                            AlertDialog theAlertDialog = builder.create();
                            theAlertDialog.show();
                        }

                    }

                   else if ( set1 == 6 && set4 == 6 && set2 == 0 && set5 == 0){



                        for (tie1=100; tie1 <= 1; tie1++){
                            textViewCount1.setText("" + tie1);

                            CountA=0;
                        }


                    }

                     else if((set2 <= 5 && set5 != 6 && set3 == 0 && set6 == 0)
                            || (set2 == 5 && set5 != 7 && set3 == 0 && set6 == 0)
                            || (set2 == 6 && set5 == 5 && set3 == 0 && set6 == 0)
                            || (set2 == 6 && set5 == 6 && set3 == 0 && set6 == 0))
                    {
                        set2 = set2 + 1;
                        textView2.setText("" + set2);
                        CountA=0;
                        if((set1 == 6 && set4 <=4 && set2 ==6 && set5 <=4 && set3 == 0 && set6 == 0) || (set2 ==7 && set5 <= 6 && set3 ==0  && set6 == 0))
                        {
                            //builder.setTitle("Game Over");
                            builder.setMessage("Player 1 won the Match by winning both the Sets")
                                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                            CountA = 0;
                                            CountB = 0;
                                            textView1.setText("0");
                                            textView2.setText("0");
                                            textView3.setText("0");
                                            textView4.setText("0");
                                            textView5.setText("0");
                                            textView6.setText("0");
                                            textViewCount1.setText("0");
                                            textViewCount2.setText("0");
                                            set1 = set2 = set3 = set4 = set5 = set6 = 0;
                                        }
                                    });
                            AlertDialog theAlertDialog = builder.create();
                            theAlertDialog.show();
                        }
                        else if((set4 ==6 && set1 <=4 && set2 ==6 && set5 <=4 && set3 == 0 && set6 == 0)|| (set2 ==7 && set5 <= 6 && set3 ==0  && set6 == 0))
                        {
                            builder.setMessage("Player 1 wins the 2nd Set")
                                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {


                                        }
                                    });
                            AlertDialog theAlertDialog = builder.create();
                            theAlertDialog.show();

                        }

                    }

                    else if((set3 <= 4 && set6 != 6)
                                    || (set3 == 5 && set6 !=7 )
                                    || (set3 == 5 && set6 == 6 )
                                    || (set3 == 6 && set6 == 6 )
                                    || (set3 == 6 && set6 == 5 ))

                    {
                        set3 = set3 + 1;
                        textView3.setText("" + set3);
                        CountA=0;
                        if((set3 ==6 && set6 <=4) || (set3 ==7 && set6 <= 6 ))
                        {
                            //builder.setTitle("Game Over");
                            builder.setMessage("Player 1 won the Match by winning both the Sets")
                                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                            CountA = 0;
                                            CountB = 0;
                                            textView1.setText("0");
                                            textView2.setText("0");
                                            textView3.setText("0");
                                            textView4.setText("0");
                                            textView5.setText("0");
                                            textView6.setText("0");
                                            textViewCount1.setText("0");
                                            textViewCount2.setText("0");
                                            set1 = set2 = set3 = set4 = set5 = set6 = 0;
                                        }
                                    });
                            AlertDialog theAlertDialog = builder.create();
                            theAlertDialog.show();
                        }

                    }
                    else{
                        CountA = 0;
                    }

                }
                else if (CountA == 5 && textViewCount1.getText().toString().equals("40") && textViewCount2.getText().toString().equals("40")) {
                    textViewCount1.setText("AD");
                    textViewCount2.setText("40");

                }
            }
        }
    }
    );

1 个答案:

答案 0 :(得分:0)

如果你有正确的分数实现,如40-0,15-15等,那么将它镜像到处理tiebreak的辅助方法应该是直截了当的。

由于你的代码非常详细,我无法告诉你如何逐行完成,只是将tiebreak视为另一个附加集,并以与实现集合相同的方式实现它:

即。有一个counterA和一个counterB如果玩家A赢得一个点增加他的计数器,否则增加B的计数器 - 并且一旦玩家的一个计数器达到让他赢得{{ 1}}(例如A获胜的条件是: tiebreakcounterA == 6 counterA - counterB >= 2(通过{{1 }},counterA == 7) - 如果我能正确记住网球规则的话)

然后只有在设定分数达到6-6时才调用您的if方法(但是您选择执行此检查很好)并将else if的获胜者返回到处理集合功能。