-
Notifications
You must be signed in to change notification settings - Fork 2
/
HEALNight.m
79 lines (61 loc) · 2.66 KB
/
HEALNight.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
//
// HEALNight.m
// drinkingApp
//
// Created by Eivind Bakke on 3/5/14.
// Copyright (c) 2014 Halealei. All rights reserved.
//
#import "HEALNight.h"
@interface HEALNight (){
// Arrays holding the constant messages to be shown in DrunkStateViewController
NSArray* soberMessageArray;
NSArray* tipsyMessageArray;
NSArray* drunkMessageArray;
NSArray* dangerMessageArray;
// Helper structure to hold messages for a given night
NSArray* sessionMessages;
}
@end
@implementation HEALNight
//############################################ Initialize the StateMessageArrays, Messages for the Night, and whether an SMS has been sent that night ############################################
- (id)init
{
self = [super init];
if (self) {
self.sosSent = FALSE;
soberMessageArray = @[@"Call Your Grandma!", @"Walk Your Dog", @"Drive Your Car", @"Write Some Code", @"Live A Little", @"Fold Laundry", @"Pick Up Cantonese "];
tipsyMessageArray = @[@"Avoid Karaoke", @"Share A Childhood Story", @"Dance", @"Not drive"];
drunkMessageArray = @[@"Order Jimmy Johns", @"Ponder Meaning of Life", @"Drink Some Water", @"Eat Some Food", @"Kagin?", @"Not Text That Number"];
dangerMessageArray = @[@"Go home", @"Relax", @"Stop drinking", @"Call SafeWalk", @"Definitely not drive"];
[self generateMessages];
}
return self;
}
// Chooses a random message for each state from the message array for each state, and puts them in an array where the index corresponds to the state
- (void)generateMessages
{
NSString* soberMessage = soberMessageArray[[self randomNumberBetweenMin:0 Max:[soberMessageArray count] - 1]];
NSString* tipsyMessage = tipsyMessageArray[[self randomNumberBetweenMin:0 Max:[tipsyMessageArray count] - 1]];
NSString* drunkMessage = drunkMessageArray[[self randomNumberBetweenMin:0 Max:[drunkMessageArray count] - 1]];
NSString* dangerMessage = dangerMessageArray[[self randomNumberBetweenMin:0 Max:[dangerMessageArray count] - 1]];
sessionMessages = @[soberMessage, tipsyMessage, drunkMessage, dangerMessage];
}
// Generate random numbers within range min to max
- (long)randomNumberBetweenMin:(long)min Max:(long)max
{
return ( (arc4random() % (max-min+1)) + min );
}
// Returns a random message per night for a given state
- (NSString*)stateMessage:(int)state
{
return [sessionMessages objectAtIndex:state];
}
//############################################ Reset Every Property of the night ############################################
- (void)reset
{
self.drinks = 0;
self.startTime = 0;
self.sosSent = FALSE;
[self generateMessages];
}
@end