GAMES TWO: LESSON TWENTY-ONE: Simple Card Game

Take a look at these pages and try out the game:
Information about game
Cards Game
Source code for CARDS.java

The following two methods are the most crucial to the game. Study them and make sure you understand how they work.

public void setValues(){ answer = 0; setCards(); int[] v_array = new int[14]; //no value stored at zero for(int i = 0; i<v_array.length; i++) v_array[i]=0; int temp_ans = 0; for(int i = 0; i<values.length; i++){ v_array[values[i]]++; } for(int i = 0; i<v_array.length; i++){ if(v_array[i]<2) answer += i*v_array[i]; else answer += Math.pow(i,v_array[i]); } input=""; check=true; status = "Enter value."; } public void setCards(){ int val = 0; int currVal=0; for(int c=0; c<prevCards.length; c++) prevCards[c]=null; for(int i = 0; i<p.length; i++){ String card_value=""; do { Random r = new Random(); int suit= Math.abs(r.nextInt())%4; val= Math.abs(r.nextInt())%13; String st=""; String vl=""; //identify suit: switch(suit){ case 0: st="S"; break; case 1: st="C"; break; case 2: st="H"; break; case 3: st="D"; break; } //identify value switch(val){ case 0: vl="A"; currVal=1; break; case 1: vl="2"; currVal=2; break; case 2: vl="3"; currVal=3; break; case 3: vl="4"; currVal=4; break; case 4: vl="5"; currVal=5; break; case 5: vl="6"; currVal=6; break; case 6: vl="7"; currVal=7; break; case 7: vl="8"; currVal=8; break; case 8: vl="9"; currVal=9; break; case 9: vl="T"; currVal=10; break; case 10: vl="J"; currVal=11; break; case 11: vl="Q"; currVal=12; break; case 12: vl="K"; currVal=13; break; } card_value="cards/"+vl+st+".gif"; rep=false; for(int c=0; c<prevCards.length; c++) { if(card_value.equals(prevCards[c])) rep=true; } } while(rep); prevCards[i]=card_value; p[i]=getImage(getDocumentBase(), card_value); values[i]=currVal; } }


ASSIGNMENT:

Do the following:

  1. Make a flashier ending (something using TimerTask to do a little animated production).
  2. Make TWOs wild so that they are automatically multiplied with highest card(s) dealt.