Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking an android game, not sure how to approach this
    primarykey
    data
    text
    <p>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 &amp; case in my main class, and im not sure how to re-run the switch and case statement to draw another card at random.</p> <p>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.</p> <p>Thanks,</p> <p>-Steve</p> <p>My Main Game Class:</p> <pre><code>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) { } }); } </code></pre> <p>}</p> <p>Deck Class: (originally this was in my game class)</p> <pre><code>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; } </code></pre> <p>}</p> <p>Shuffle Class: (Originally this was in my game class)</p> <pre><code>public class Shuffle { public static int[] getShuffle() { int[] cards = new int[52]; ArrayList&lt;Integer&gt; cards_objs = new ArrayList&lt;Integer&gt;(); for (int i = 0; i &lt; cards.length; i++) { cards_objs.add(i); } Collections.shuffle(cards_objs); for (int i = 0; i &lt; cards.length; i++) { cards[i] = cards_objs.get(i); } return cards; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload