一个字母猜谜游戏为孩子们的机器人

时间:2014-05-30 09:22:00

标签: android

我想知道我怎么能匹配我的两个数组,它是一个猜测字母的游戏,它的一个小写字母和4个大写字母,我想要一个大写字母应该与小写字母相同所以我可以点击匹配信!寻求答案!!!

 package com.example.alfabetet;
import java.util.*;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;

public class AlfaSpelet extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alfaspelet);

        String gemen[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "å", "ä", "ö" };

        String alfa[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Å", "Ä", "Ö" }; 



        TextView txt1 = (TextView) findViewById(R.id.textView2);
        TextView txt2 = (TextView) findViewById(R.id.textView3);
        TextView txt3 = (TextView) findViewById(R.id.textView4);
        TextView txt4 = (TextView) findViewById(R.id.textView5);

        TextView txt5 = (TextView) findViewById(R.id.textView6);        

        Random random = new Random();

            int rnd1 = random.nextInt(alfa.length);
            int rnd2 = random.nextInt(alfa.length);
            int rnd3 = random.nextInt(alfa.length);
            int rnd4 = random.nextInt(alfa.length);

            int rnd5 = random.nextInt(gemen.length);

            txt1.setText(alfa[rnd1]);
            txt2.setText(alfa[rnd2]);
            txt3.setText(alfa[rnd3]);
            txt4.setText(alfa[rnd4]);
            txt5.setText(gemen[rnd5]);`enter code here`

1 个答案:

答案 0 :(得分:0)

试试这个:

int rnd1 = random.nextInt(alfa.length);
int rnd2 = random.nextInt(alfa.length);
int rnd3 = random.nextInt(alfa.length);
int rnd4 = random.nextInt(alfa.length);

int rnd[] = {rnd1, rnd2, rnd3, rnd4};

int rnd5 = random.nextInt(rnd.length);

txt1.setText(alfa[rnd1]);
txt2.setText(alfa[rnd2]);
txt3.setText(alfa[rnd3]);
txt4.setText(alfa[rnd4]);
txt5.setText(gemen[rnd[rnd5]]);
相关问题