-
Notifications
You must be signed in to change notification settings - Fork 24
/
GameViewController.m
90 lines (75 loc) · 2.23 KB
/
GameViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// GameViewController.m
// Puzzles
//
// Created by Greg Hewgill on 8/03/13.
// Copyright (c) 2013 Greg Hewgill. All rights reserved.
//
#import "GameViewController.h"
#import "GameView.h"
#import "GameHelpController.h"
@interface GameViewController ()
@end
@implementation GameViewController {
const game *thegame;
NSString *name;
NSString *saved;
BOOL init_inprogress;
id<GameViewControllerSaver> saver;
GameView *gameview;
}
- (id)initWithGame:(const game *)g saved:(NSString *)sav inprogress:(BOOL)inprog saver:(id<GameViewControllerSaver>)savr;
{
self = [super init];
if (self) {
thegame = g;
name = [NSString stringWithUTF8String:thegame->name];
self.title = name;
saved = sav;
init_inprogress = inprog;
saver = savr;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveGame) name:@"applicationDidEnterBackground" object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)loadView
{
self.view = gameview = [[GameView alloc] initWithFrame:[UIScreen mainScreen].bounds nc:self.navigationController game:thegame saved:saved inprogress:init_inprogress];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Help" style:UIBarButtonItemStylePlain target:self action:@selector(showHelp)];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self saveGame];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
- (void)saveGame
{
BOOL inprogress;
NSString *save = [gameview saveGameState_inprogress:&inprogress];
if (save != nil) {
[saver saveGame:name state:save inprogress:inprogress];
}
}
- (void)showHelp
{
[self.navigationController pushViewController:[[GameHelpController alloc] initWithFile:[NSString stringWithFormat:@"%s.html", thegame->htmlhelp_topic]] animated:YES];
}
@end