teaching machines

CS 491 Lecture 2 – iPopper

September 5, 2013 by . Filed under cs491 mobile, fall 2013, lectures.

Agenda

TODO

Code

AppDelegate.m

//
//  AppDelegate.m
//  iPopper
//
//  Created by Christopher R. Johnson on 9/5/13.
//  Copyright (c) 2013 UWEC. All rights reserved.
//

#import "PopperViewController.h"
#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    
    
    PopperViewController *controller = [[PopperViewController alloc] init];
    [self.window setRootViewController:controller];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

PopperView.h

//
//  PopperView.h
//  iPopper
//
//  Created by Christopher R. Johnson on 9/5/13.
//  Copyright (c) 2013 UWEC. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface PopperView : UIView

@end

PopperView.m

//
//  PopperView.m
//  iPopper
//
//  Created by Christopher R. Johnson on 9/5/13.
//  Copyright (c) 2013 UWEC. All rights reserved.
//

#import "PopperView.h"

@interface PopperView () {
    UIImage *images[2];
}
@end

@implementation PopperView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // do initialization of instance variables
        [self setBackgroundColor:[UIColor redColor]];
        images[0] = [UIImage imageNamed:@"unpopped"];
        images[1] = [UIImage imageNamed:@"popped"];
    }
    return self;
}

- (void)drawRect:(CGRect)dirtyRect {
    CGContextRef canvas = UIGraphicsGetCurrentContext();
    
    CGRect drawIntoRect = CGRectMake(0.0f, 0.0f, 400.0f, 400.0f);
    CGContextDrawImage(canvas, drawIntoRect, [images[0] CGImage]);
}

@end

PopperViewController.h

//
//  PopperViewController.h
//  iPopper
//
//  Created by Christopher R. Johnson on 9/5/13.
//  Copyright (c) 2013 UWEC. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface PopperViewController : UIViewController

@end

PopperViewController.m

//
//  PopperViewController.m
//  iPopper
//
//  Created by Christopher R. Johnson on 9/5/13.
//  Copyright (c) 2013 UWEC. All rights reserved.
//

#import "PopperView.h"
#import "PopperViewController.h"

@implementation PopperViewController

- (void)loadView {
    // How big is that view?
    // UIScreen.mainScreen().bounds()
    CGRect frame = [[UIScreen mainScreen] bounds];
    
    // Make a view instance.
    PopperView *view = [[PopperView alloc] initWithFrame:frame];
    
    // Set controller's one view to the popper view.
    // self.setView(view)
    [self setView:view];
}

@end

Haiku

Games don’t need playing
That’s likely why we play them
To be more than needs