I am designing a game in Android/Java and so far everything has gone well. The game shows a random card from a deck of 52 and the user has to determine whether the next card will be higher or lower. I put my switch & case in my main class, and im not sure how to re-run the switch and case statement to draw another card at random.
Below are my classes, I know I dont need this many, but I changed the code around alot since my original in attempt to get this to work. I know the problem is not with my app, its because of my inexperience in android... Check out the code and tell me what you think. Since its a pretty broad question and there may be more than one answer, I will upvote everyone who gives me a relevant answer, weather I use the solution or not.
Thanks,
-Steve
My Main Game Class:
public class Game extends SwarmActivity {
int cardNum;
Deck d = new Deck();
int x = d.shuffle();
String y = String.valueOf(x);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
Swarm.init(this, 1388, "1e02a1ecfa9483b7b62e7b32c7e055f3");
TextView t = (TextView) findViewById(R.id.score);
ImageView display = (ImageView) findViewById(R.id.display);
switch (x) {
case 0:
display.setImageResource(R.drawable.c_one);
cardNum = 1;
break;
case 1:
display.setImageResource(R.drawable.c_two);
cardNum = 2;
break;
case 2:
display.setImageResource(R.drawable.c_three);
cardNum = 3;
break;
case 3:
display.setImageResource(R.drawable.c_four);
cardNum = 4;
break;
case 4:
display.setImageResource(R.drawable.c_five);
cardNum = 5;
break;
---------- (5-49) ----------
case 50:
display.setImageResource(R.drawable.c_fiftyone);
cardNum = 51;
break;
case 51:
display.setImageResource(R.drawable.c_fiftytwo);
cardNum = 52;
break;
}
ImageView higher = (ImageView) findViewById(R.id.btn_higher);
ImageView lower = (ImageView) findViewById(R.id.btn_lower);
higher.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
lower.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
Deck Class: (originally this was in my game class)
public class Deck {
public int shuffle() {
Shuffle s = new Shuffle();
int[] shuffDeck = s.getShuffle();
int i = 0;
int x = shuffDeck[i];
String y = String.valueOf(x);
return x;
}
}
Shuffle Class: (Originally this was in my game class)
public class Shuffle {
public static int[] getShuffle() {
int[] cards = new int[52];
ArrayList<Integer> cards_objs = new ArrayList<Integer>();
for (int i = 0; i < cards.length; i++) {
cards_objs.add(i);
}
Collections.shuffle(cards_objs);
for (int i = 0; i < cards.length; i++) {
cards[i] = cards_objs.get(i);
}
return cards;
}
}