Game Development Reference
In-Depth Information
(d) Write a special version of the IndexLargest method which doesn't look
through the entire array, but only the first n elements, where n is passed as a
parameter to the method.
(e) Write a method Sort , which has as a parameter an array of doubles. The
return value type is void . After the method is called, the elements in the array
should be sorted in increasing order.
Hint: first find the index of the largest value in the array (using the
IndexLargest method). Then, swap this value with the value at the last in-
dex. After doing that, the largest value is already and the end of the array
where it belongs. Then, find the largest value in the rest of the array and
swap that value with the penultimate value in the array. And so on, until the
entire array has been sorted.
(f) Write a method which has as parameters an array of integers and one single
integer that returns as a result the index at which the single integer occurs first
in the array. If the integer doesn't occur anywhere in the array, the method
should return
1.
(g) ( more difficult ) If you know that the array is sorted, it is possible to search
in a smarter way: look at the middle element in the array if it contains the
value that you're looking for. If so, great! If not, you'll know if the element
you're looking for is in the left part or in the right part of the array. This way,
looking through the array becomes very efficient because at each iteration the
part of the array you have to search through becomes half as big. Write this
improved search method. Use two integers to keep track of the boundaries
of the piece of array that you're searching in.
Challenges
1. Weather control
In this challenge, we will extend the Snowflakes program from Chap. 12 .
(a) Extend the program by allowing for more or less snowflakes depending on
user input (up arrow means more snow, down arrow means less snow). Set
a maximum number of snowflakes (for example 1000). Make sure that the
program is robust (never more than 1000 snowflakes, and no crash when you
reach 0 snowflakes).
(b) Extend the program so that there is varying wind. You can implement 'wind'
by not letting the snowflakes fall down straight but according to an angle.
Vary the angle with which the flakes fall down over time using random num-
bers. Try to find a range of random values and a rate of change that looks
realistic.
2. More jewels
This challenge is an extension of the Jewel Jam game.
Search WWH ::




Custom Search