Silver + Gold Challenge Solution + Extra


#1

Hi There,
[size=150]Silver[/size]
Silver is kinda easy. Just add the following lines in TouchDrawView.m’s drawRect: method:

[...]
for (Line *line in completeLines) {
        
        //Silver Challenge
        
        float angle = ([line begin].y - [line end].y) / ([line begin].x - [line end].x);
        if (angle > 1) {
            [[UIColor greenColor] set];
        } else if ((angle > -1) && (angle < 1)) {
            [[UIColor blueColor] set];
        } else if (angle < -1) {
            [[UIColor yellowColor] set];
        }
        
        //End Silver Challenge
        
        CGContextMoveToPoint(context, [line begin].x, [line begin].y);
[...]

[size=150]Gold[/size]

For Gold I added a new class called circle. Putting all the code here in the post would make it a little cluttered. So you can download the code for both solutions from my dropbox: dl.dropbox.com/u/99449487/Chapte … lenges.zip

But here are the basics:
Handle 2 touches at the same time not like the other touches. Bind in a if statement in the touch recognizing methods:
if ([touches count] == 2)
Then you need - as Joe said - another Dictionary + Array (You don’t “need” the array - but it makes your code a little clearer I think).
Then implement the Circle class - that’s it.

[size=150]The Extra[/size]
Download and run the Gold challenge file from my dropbox (link above). You will find a switch in the top right corner that let you decide whether you want to allow the user to draw ellipses or not.

Greetings
Joerg