如何在测验中隐藏两个错误的答案?

时间:2013-03-15 14:13:03

标签: java android android-sqlite

喜欢“谁想成为百万富翁”。当用户按下50/50帮助按钮时,我想要隐藏两个错误的答案,因此将两个按钮的setText设置为“”,但不是“答案”一个。但我不知道该怎么做。我正在使用带有问题和答案的sqlite预填充数据库。我的50/50帮助按钮是bPolaPola。这是我的游戏课程:

public class NeogranicenoPetGresaka extends SwarmActivity implements OnClickListener{

    MyCount brojacVremena = new MyCount(16000, 1000);

LinkedList<Long> mAnsweredQuestions = new LinkedList<Long>();

    private String generateWhereClause(){
        StringBuilder result = new StringBuilder();
        for (Long l : mAnsweredQuestions){
            result.append(" AND _ID <> " + l);
        }
        return result.toString();
    }

    Button bIzlazIzKviza, bOdgovor1, bOdgovor2, bOdgovor3, bOdgovor4, bPolaPola;
    TextView question, netacniOdg, score, countdown;
    int brojacPogresnihOdgovora = 0;
    int brojacTacnihOdgovora = 0;
    public static String tacanOdg;

    Runnable mLaunchTask = new Runnable() {
        public void run() {
            nextQuestion();
            brojacVremena.start();
        }
     };
    Runnable mLaunchTaskFinish = new Runnable() {
         public void run() {
            brojacVremena.cancel();
            finish();
         }
      };


    private class Answer {
        public Answer(String opt, boolean correct) {
            option = opt;
            isCorrect = correct;
        }

        String option;
        boolean isCorrect;
    }
    Handler mHandler = new Handler();

    final OnClickListener clickListener = new OnClickListener() {
        public void onClick(View v) {

            Answer ans = (Answer) v.getTag();
            if (ans.isCorrect) {
                brojacVremena.cancel();
                brojacTacnihOdgovora = brojacTacnihOdgovora + 5;
                Intent i = new Intent("rs.androidaplikacijekvizopstekulture.TACANODGOVOR");
                startActivity(i);
                mHandler.postDelayed(mLaunchTask,1200);
            }
        else{
            brojacVremena.cancel();
            brojacPogresnihOdgovora++;
            Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class);
            i.putExtra("tacanOdgovor", tacanOdg);
            startActivity(i);
            mHandler.postDelayed(mLaunchTask,2200);
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.neograniceno);

        Typeface dugmad = Typeface.createFromAsset(getAssets(), "Bebas.ttf");
        Typeface pitanje = Typeface.createFromAsset(getAssets(), "myriad.ttf");
        bIzlazIzKviza = (Button) findViewById(R.id.bIzlazIzKvizaN);
        netacniOdg = (TextView) findViewById(R.id.tvBrojPitanjaN);
        question = (TextView) findViewById(R.id.tvPitanjeN);
        bOdgovor1 = (Button) findViewById(R.id.bOdgovorN1);
        bOdgovor2 = (Button) findViewById(R.id.bOdgovorN2);
        bOdgovor3 = (Button) findViewById(R.id.bOdgovorN3);
        bOdgovor4 = (Button) findViewById(R.id.bOdgovorN4);
        bPolaPola = (Button) findViewById(R.id.bPolaPolaN);
        score = (TextView) findViewById(R.id.tvSkor2N);
        countdown = (TextView) findViewById(R.id.tvCountdownN);
        bOdgovor1.setTypeface(dugmad);
        bOdgovor2.setTypeface(dugmad);
        bOdgovor3.setTypeface(dugmad);
        bOdgovor4.setTypeface(dugmad);
        bPolaPola.setTypeface(dugmad);
        bIzlazIzKviza.setTypeface(dugmad);
        netacniOdg.setTypeface(dugmad);
        question.setTypeface(pitanje);
        score.setTypeface(dugmad);
        countdown.setTypeface(dugmad);

        nextQuestion(); //startuje prvo pitanje!
        brojacVremena.start();  //startuje brojac vremena
    }


    public class MyCount extends CountDownTimer {

        public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onFinish() {
            Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class);
            i.putExtra("tacanOdgovor", tacanOdg);
            startActivity(i);
            mHandler.postDelayed(mLaunchTask,2200);

            brojacPogresnihOdgovora++;
        }

        @Override
        public void onTick(long millisUntilFinished) {
            countdown.setText("" + millisUntilFinished / 1000);
        }
    }

        public void onClick(View v) {
        // TODO Auto-generated method stub


    }

        @Override public void onStop() {
            super.onStop();
            brojacVremena.cancel();
        }

    @Override
        protected void onPause() {
            // TODO Auto-generated method stub
            super.onPause();
        }

    public void nextQuestion() {

        TestAdapter mDbHelper = new TestAdapter(this);
        mDbHelper.createDatabase();

        try{    //Pokusava da otvori db

            mDbHelper.open();  //baza otvorena

            Cursor c = mDbHelper.getTestData(generateWhereClause());
            mAnsweredQuestions.add(c.getLong(0));

            List<Answer> labels = new ArrayList<Answer>();

            labels.add(new Answer(c.getString(2), true));
            labels.add(new Answer(c.getString(3), false));
            labels.add(new Answer(c.getString(4), false));
            labels.add(new Answer(c.getString(5), false));

            Collections.shuffle(labels);

            tacanOdg = c.getString(2);

            if(brojacPogresnihOdgovora < 5){


        question.setText(c.getString(1));

        bOdgovor1.setText(labels.get(0).option);
        bOdgovor1.setTag(labels.get(0));
        bOdgovor1.setOnClickListener(clickListener);

        bOdgovor2.setText(labels.get(1).option);
        bOdgovor2.setTag(labels.get(1));
        bOdgovor2.setOnClickListener(clickListener);

        bOdgovor3.setText(labels.get(2).option);
        bOdgovor3.setTag(labels.get(2));
        bOdgovor3.setOnClickListener(clickListener);

        bOdgovor4.setText(labels.get(3).option);
        bOdgovor4.setTag(labels.get(3));
        bOdgovor4.setOnClickListener(clickListener);

        netacniOdg.setText("" + brojacPogresnihOdgovora);
        score.setText("Score: " + brojacTacnihOdgovora);
            }
            else{
                brojacVremena.cancel();
                Intent i = new Intent(getApplicationContext(), Rezultat.class);
                i.putExtra("noviRezultat", brojacTacnihOdgovora);
                startActivity(i);
                mHandler.postDelayed(mLaunchTaskFinish,4000);
                SwarmLeaderboard.submitScore(6863, brojacTacnihOdgovora);
            }
        }
        finally{    // kada zavrsi sa koriscenjem baze podataka, zatvara db
            mDbHelper.close();
        }

    bIzlazIzKviza.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            finish();   
        }
    });
    }
}

好的,正如jazzbassrob指出的那样,我需要更加具体。我需要将setText设置为我的bPolaPola按钮为“”,空字符串,但我的主要问题是我不知道收集后shuffle我的答案将会结束,所以我不知道setText的哪些按钮。如何知道我的答案在洗牌后最终会在哪里结束?

我实际上没有尝试任何原因,在这种特殊情况下,我真的不知道从哪里开始。

1 个答案:

答案 0 :(得分:0)

如果运行一个查询,即使在用户点击一个查询之前找到了正确的选项,那么您可以从四个选项中找到正确的按钮。在此之后,在任何指向正确答案的按钮之外的任意随机两个按钮上使用setText=""