I wanna make image guessing android game, there are 150 images, I want the image to be generated randomly, and the user should type the name of character if it is correct the next button will display another image till the 150 are finished
This the code for avoiding image repition
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(R.drawable.myImage);
int position = new Random().nextInt(list.size());
imageViewObject.setImageResource(Integer.intValue(list.get(position)));
list.remove(position);
but how should I compare the user input with character name, should I use image path, or make array for answers and compare it to user input?
CodePudding user response:
There are many ways to do it, depending on your project. An effective one would be storing them in an object (let's call it Card
), and card will contain as properties (imageURL
as String / characterName
as String/ ifCorrect
as Boolean).
Store these objects inside an array and if the user guesses the right answer, change the object's ifCorrect
field to true
, so you know the image has been played.