Skip to content

Commit 9948953

Browse files
committed
Cambios y ultima version
1 parent 897bd06 commit 9948953

File tree

86 files changed

+2087
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2087
-16
lines changed

Hackaton.xcodeproj/project.pbxproj

+398
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
<Breakpoints>
6+
<BreakpointProxy
7+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8+
<BreakpointContent
9+
shouldBeEnabled = "No"
10+
ignoreCount = "0"
11+
continueAfterRunningActions = "No"
12+
filePath = "Hackaton/View/GameViewController.m"
13+
timestampString = "417786169.368688"
14+
startingColumnNumber = "9223372036854775807"
15+
endingColumnNumber = "9223372036854775807"
16+
startingLineNumber = "41"
17+
endingLineNumber = "41"
18+
landmarkName = "-viewDidLoad"
19+
landmarkType = "5">
20+
</BreakpointContent>
21+
</BreakpointProxy>
22+
<BreakpointProxy
23+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
24+
<BreakpointContent
25+
shouldBeEnabled = "No"
26+
ignoreCount = "0"
27+
continueAfterRunningActions = "No"
28+
filePath = "Hackaton/View/GameViewController.m"
29+
timestampString = "417786230.927426"
30+
startingColumnNumber = "9223372036854775807"
31+
endingColumnNumber = "9223372036854775807"
32+
startingLineNumber = "60"
33+
endingLineNumber = "60"
34+
landmarkName = "-viewDidLoad"
35+
landmarkType = "5">
36+
</BreakpointContent>
37+
</BreakpointProxy>
38+
<BreakpointProxy
39+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
40+
<BreakpointContent
41+
shouldBeEnabled = "Yes"
42+
ignoreCount = "0"
43+
continueAfterRunningActions = "No"
44+
filePath = "Hackaton/Classes/Connection.m"
45+
timestampString = "417821103.81747"
46+
startingColumnNumber = "9223372036854775807"
47+
endingColumnNumber = "9223372036854775807"
48+
startingLineNumber = "132"
49+
endingLineNumber = "132"
50+
landmarkName = "-insertScore::"
51+
landmarkType = "5">
52+
</BreakpointContent>
53+
</BreakpointProxy>
54+
</Breakpoints>
55+
</Bucket>
Loading

Hackaton/Base.lproj/Main_iPhone.storyboard

+450-3
Large diffs are not rendered by default.

Hackaton/Classes/Answer.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Answer.h
3+
// Hackaton
4+
//
5+
// Created by Jorge Raul Ovalle Zuleta on 3/29/14.
6+
// Copyright (c) 2014 jomobile.co. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface Answer : NSObject
12+
{
13+
int idAnswer;
14+
NSString *txtAnswer;
15+
NSString *isTrue;
16+
}
17+
18+
//GETS
19+
-(int)getIdAnswer;
20+
-(NSString*)getTxtAnswer;
21+
-(NSString*)getIsTrue;
22+
//SETS
23+
-(void)setIdAnswer:(int)idAnswerN;
24+
-(void)setTxtAnswer:(NSString*)txtAnswerN;
25+
-(void)setIsTrue:(NSString*)isTrueN;
26+
27+
@end

Hackaton/Classes/Answer.m

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Answer.m
3+
// Hackaton
4+
//
5+
// Created by Jorge Raul Ovalle Zuleta on 3/29/14.
6+
// Copyright (c) 2014 jomobile.co. All rights reserved.
7+
//
8+
9+
#import "Answer.h"
10+
11+
@implementation Answer
12+
13+
-(id)init
14+
{
15+
self = [super init];
16+
if (self) {
17+
idAnswer = 0;
18+
txtAnswer = @"";
19+
isTrue = @"";
20+
}
21+
return self;
22+
}
23+
24+
//GETS
25+
-(int)getIdAnswer{
26+
return idAnswer;
27+
}
28+
-(NSString*)getTxtAnswer{
29+
return txtAnswer;
30+
}
31+
-(NSString*)getIsTrue{
32+
return isTrue;
33+
}
34+
//SETS
35+
-(void)setIdAnswer:(int)idAnswerN{
36+
idAnswer = idAnswerN;
37+
}
38+
-(void)setTxtAnswer:(NSString*)txtAnswerN{
39+
txtAnswer = txtAnswerN;
40+
}
41+
-(void)setIsTrue:(NSString*)isTrueN{
42+
isTrue = isTrueN;
43+
}
44+
45+
@end

Hackaton/Classes/Connection.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Connection.h
3+
// Hackaton
4+
//
5+
// Created by Jorge Raul Ovalle Zuleta on 3/29/14.
6+
// Copyright (c) 2014 jomobile.co. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "sqlite3.h"
11+
12+
@interface Connection : NSObject{
13+
sqlite3 *db;
14+
}
15+
16+
@property (nonatomic, retain) NSMutableArray *returnList;
17+
18+
-(NSString *) filePath;
19+
-(void) openDB;
20+
-(NSMutableArray*)getRandomQuestions;
21+
-(NSMutableArray*)getRandomAnswers:(int)id_question;
22+
-(NSMutableArray*)getAllRanking;
23+
-(void)insertScore:(NSString*)namUser :(int)scoreTotal;
24+
-(int)selectMaxScore;
25+
-(NSString*)getAdvice:(int)id_question;
26+
27+
@end
28+

Hackaton/Classes/Connection.m

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
//
2+
// Connection.m
3+
// Hackaton
4+
//
5+
// Created by Jorge Raul Ovalle Zuleta on 3/29/14.
6+
// Copyright (c) 2014 jomobile.co. All rights reserved.
7+
//
8+
9+
#import "Connection.h"
10+
#import "Answer.h"
11+
#import "Question.h"
12+
#import "Score.h"
13+
14+
@implementation Connection
15+
@synthesize returnList;
16+
17+
-(id)init{
18+
self = [super init];
19+
if (self) {
20+
returnList = [[NSMutableArray alloc] init];
21+
}
22+
return self;
23+
}
24+
25+
-(NSString *) filePath{
26+
return [[NSBundle bundleForClass:[self class]] pathForResource:@"Hackaton" ofType:@"sqlite"];
27+
}
28+
29+
//open the db
30+
-(void)openDB {
31+
if(sqlite3_open([[self filePath] UTF8String], &db)!= SQLITE_OK){
32+
sqlite3_close(db);
33+
NSAssert(0,@"Database failed to open");
34+
}else{
35+
// NSLog(@"database opened");
36+
}
37+
}
38+
39+
//Method to get All Answers by random
40+
-(NSMutableArray*) getRandomQuestions{
41+
returnList = [[NSMutableArray alloc] init];
42+
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM QUESTION ORDER BY RANDOM();"];
43+
sqlite3_stmt *statement;
44+
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)==SQLITE_OK)
45+
{
46+
while (sqlite3_step(statement)==SQLITE_ROW) {
47+
Question *queObj = [[Question alloc] init];
48+
char *field1 = (char *) sqlite3_column_text(statement, 0);
49+
NSString *field1str = [[NSString alloc]initWithUTF8String:field1];
50+
[queObj setIdQuestion: field1str.intValue];
51+
field1 = (char *) sqlite3_column_text(statement, 1);
52+
[queObj setTxtQuestion: [[NSString alloc]initWithUTF8String:field1]];
53+
field1 = (char *) sqlite3_column_text(statement, 2);
54+
[queObj setImgQuestion:[[NSString alloc]initWithUTF8String:field1]];
55+
[returnList addObject:queObj];
56+
}
57+
}
58+
return returnList;
59+
}
60+
//Get 4 Answers randomly
61+
-(NSMutableArray*)getRandomAnswers:(int)id_question{
62+
returnList = [[NSMutableArray alloc] init];
63+
NSString *sql = [NSString stringWithFormat:@"SELECT id_answer,text_answer,is_answer FROM ANSWER WHERE id_question = %d ORDER BY RANDOM();", id_question];
64+
sqlite3_stmt *statement;
65+
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)==SQLITE_OK)
66+
{
67+
while (sqlite3_step(statement)==SQLITE_ROW) {
68+
Answer *ansObj = [[Answer alloc] init];
69+
char *field1 = (char *) sqlite3_column_text(statement, 0);
70+
NSString *field1str = [[NSString alloc]initWithUTF8String:field1];
71+
[ansObj setIdAnswer: field1str.intValue];
72+
field1 = (char *) sqlite3_column_text(statement, 1);
73+
[ansObj setTxtAnswer:[[NSString alloc]initWithUTF8String:field1]];
74+
field1 = (char *) sqlite3_column_text(statement, 2);
75+
[ansObj setIsTrue:[[NSString alloc]initWithUTF8String:field1]];
76+
[returnList addObject:ansObj];
77+
}
78+
}
79+
return returnList;
80+
}
81+
82+
83+
84+
//Get All Scores
85+
-(NSMutableArray*)getAllRanking{
86+
returnList = [[NSMutableArray alloc] init];
87+
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM SCORE ORDER BY total_score DESC; "];
88+
sqlite3_stmt *statement;
89+
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)==SQLITE_OK)
90+
{
91+
while (sqlite3_step(statement)==SQLITE_ROW) {
92+
Score *scoObj = [[Score alloc] init];
93+
char *field1 = (char *) sqlite3_column_text(statement, 0);
94+
NSString *field1str = [[NSString alloc]initWithUTF8String:field1];
95+
[scoObj setIdScore:field1str.intValue];
96+
field1 = (char *) sqlite3_column_text(statement, 1);
97+
[scoObj setNomUser:[[NSString alloc]initWithUTF8String:field1]];
98+
field1 = (char *) sqlite3_column_text(statement, 2);
99+
field1str = [[NSString alloc]initWithUTF8String:field1];
100+
[scoObj setFinalScore:field1str.intValue];
101+
[returnList addObject:scoObj];
102+
}
103+
}
104+
return returnList;
105+
}
106+
107+
108+
//Save new score
109+
-(void)insertScore:(NSString*)namUser :(int)scoreTotal {
110+
/* NSString *sql = [NSString stringWithFormat:@"INSERT INTO SCORE (nom_user, total_score) VALUES ('%@',%d);",namUser,scoreTotal];
111+
NSLog(@"%@",sql);
112+
sqlite3_stmt *statement;
113+
114+
if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK) {
115+
116+
sqlite3_step(statement); //Aquí se ejecuta tu consulta
117+
NSLog(@"Se ejecuto");
118+
119+
}else{
120+
NSLog(@"Error en la consulta a la base de datos");
121+
}
122+
123+
sqlite3_finalize(statement);
124+
*/
125+
sqlite3_stmt *statement;
126+
/*const char *sql = [[NSString stringWithFormat:@"INSERT INTO SCORE (nom_user, total_score) VALUES ('%@',%d);",namUser,scoreTotal] UTF8String];*/
127+
128+
129+
if (statement == nil) {
130+
// [NSString stringWithFormat:@"INSERT INTO SCORE (nom_user, total_score) VALUES VALUES(%@,%@)", namUser,scoreTotal];
131+
const char *sql = [[NSString stringWithFormat:@"INSERT INTO SCORE (nom_user, total_score) VALUES ('%@',%d);",namUser,scoreTotal] UTF8String];
132+
if (sqlite3_prepare_v2(db, sql, -1, &statement, NULL) != SQLITE_OK) {
133+
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(db));
134+
}
135+
136+
// sqlite3_bind_text(statement, 2, [namUser UTF8String], -1, SQLITE_TRANSIENT );
137+
// sqlite3_bind_text(statement, 3, [[NSString stringWithFormat:@"%d",scoreTotal] UTF8String], -1, SQLITE_TRANSIENT );
138+
}
139+
sqlite3_step(statement);
140+
141+
sqlite3_reset(statement);
142+
/*if (success != SQLITE_ERROR) {
143+
NSLog(@"error");
144+
}*/
145+
sqlite3_finalize(statement);
146+
sqlite3_close(db);
147+
148+
149+
150+
}
151+
152+
//Select Max Score
153+
-(int)selectMaxScore{
154+
NSString *sql = [NSString stringWithFormat:@"SELECT MAX(total_score) FROM SCORE;"];
155+
sqlite3_stmt *statement;
156+
int max;
157+
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)==SQLITE_OK)
158+
{
159+
while (sqlite3_step(statement)==SQLITE_ROW) {
160+
char *field1 = (char *) sqlite3_column_text(statement, 0);
161+
NSString *field1str = [[NSString alloc]initWithUTF8String:field1];
162+
max = field1str.intValue;
163+
}
164+
}else{
165+
NSLog(@"Holy crap, an Error!");
166+
}
167+
return max;
168+
}
169+
170+
//Select Advice
171+
172+
-(NSString*)getAdvice:(int)id_question{
173+
174+
NSString *sql = [NSString stringWithFormat:@"SELECT txt_advice FROM ADVICE WHERE id_question = %d;",id_question];
175+
sqlite3_stmt *statement;
176+
NSString *advice = [[NSString alloc]init];
177+
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)==SQLITE_OK)
178+
{
179+
while (sqlite3_step(statement)==SQLITE_ROW) {
180+
char *field1 = (char *) sqlite3_column_text(statement, 0);
181+
NSString *field1str = [[NSString alloc]initWithUTF8String:field1];
182+
advice = field1str;
183+
}
184+
}else{
185+
NSLog(@"Holy crap, an Error!");
186+
}
187+
return advice;
188+
}
189+
190+
@end
191+
192+
193+

Hackaton/Classes/Question.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// Question.h
3+
// Hackaton
4+
//
5+
// Created by Jorge Raul Ovalle Zuleta on 3/29/14.
6+
// Copyright (c) 2014 jomobile.co. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "Answer.h"
11+
12+
@interface Question : NSObject{
13+
int idQuestion;
14+
NSString * txtQuestion;
15+
NSString * imgQuestion;
16+
Answer* ans1;
17+
Answer* ans2;
18+
Answer* ans3;
19+
Answer* ans4;
20+
}
21+
22+
//GETS
23+
-(int)getIdQuestion;
24+
-(NSString*)getTxtQuestion;
25+
-(NSString*)getImgQuestion;
26+
-(Answer*)getAns1;
27+
-(Answer*)getAns2;
28+
-(Answer*)getAns3;
29+
-(Answer*)getAns4;
30+
//SETS
31+
-(void)setIdQuestion:(int)idQuestionN;
32+
-(void)setTxtQuestion:(NSString*)txtQuestionN;
33+
-(void)setImgQuestion:(NSString*)imgQuestionN;
34+
-(void)setAns1:(Answer*)getAns1N;
35+
-(void)setAns2:(Answer*)getAns2N;
36+
-(void)setAns3:(Answer*)getAns3N;
37+
-(void)setAns4:(Answer*)getAns4N;
38+
39+
@end

0 commit comments

Comments
 (0)