Masood Ahmad
Dear Zeeshan Sb.

AoA. Thank u very much for your time ur giving us. Im learning a lot from you. I haved developed number guess app and made few changes to it. my aim was to to create it like a game which have a attempts option, then level up and remaining lives options. I used while loop for it but it didnt work. So far I have used attempts option and write the following code, but I know there will be a better way to do this kindly let my inform the code is pasted below.

int randomNumber ;
Random randomGenerator = new Random();
//int vLevel = 1;
//int vLifes = 1;
int vattempts = 5;

public void randomNumberMethod (View view) {

// TextView myLevel = (TextView) findViewById(;
// TextView myLifes = (TextView) findViewById(;

TextView myattempts = (TextView) findViewById(;


EditText myText = (EditText) findViewById(;
int userNumber = Integer.parseInt(myText.getText().toString());

if (userNumber == randomNumber) {

Toast.makeText(getApplicationContext(), "Wao! You Guessed Right", Toast.LENGTH_LONG).show();
randomNumber = randomGenerator.nextInt(30) + 1;
vattempts = 5;

} else if (userNumber < randomNumber) {

Toast.makeText(getApplicationContext(), "Too Low", Toast.LENGTH_LONG).show();
myattempts.setText(String.valueOf((int) vattempts));

} else if (userNumber > randomNumber) {
Toast.makeText(getApplicationContext(), "Too High", Toast.LENGTH_LONG).show();
myattempts.setText(String.valueOf((int) vattempts));

if (vattempts < 1 ) {
Toast.makeText(getApplicationContext(), "You Loose", Toast.LENGTH_LONG).show();
vattempts = 5;

Quote 0 0
Write a reply...

Add a Website Forum to your website.