This section of the tutorial assumes that either you have completed the easier sections or are an accomplished windows programmer. This section will display the code from the full Hilo game. It will not discuss individual sections of the code not related to the features of the Java language. This section assumes you have programmed before and can figure out the general programming techniques used.
import java.awt.*; import java.util.Random; import java.lang.Math;
1: void shuffle(int num_times) {
2: /* This method will shuffle the deck */
3: double first_rand, second_rand;
4: Random rand_num = new Random();
5: int first_number;
6: int second_number;
7: int temp;
8:
9: cards_remaining = 52;
10: for (int i = 0; i < num_times; i++) {
11: first_rand = rand_num.nextDouble();
12: second_rand = rand_num.nextDouble();
13:
14: first_number = (int) Math.round((51*first_rand));
15: second_number = (int) Math.round((51*second_rand));
16:
17: temp = index_array[first_number];
18: index_array[first_number] = index_array[second_number];
19: index_array[second_number] = temp;
20: }
21: }
Now look at lines 11 and 12. Lines 11 and 12 contain the code to get the random double values from the random number generator, which are values between 0.0 and 1.0. The next line (14), converts the first_rand number to an integer between 0 and 51. We want 52 numbers to represent the 52 cards in a deck. The Math.round() method is called to round the double value to an integer value. The right hand side also has to be cast to an int.
You should now have a fully functioning Hilo window game that you can put on
your web page.