Skip to content
Permalink
Browse files

iOS version

  • Loading branch information...
c99koder committed Oct 20, 2014
1 parent 472ce10 commit 74c9bee9eb8fc1a2b6a9f7e6b3e54d4bb33a4473
Showing with 7,685 additions and 0 deletions.
  1. +19 −0 ios/Classes/Account.h
  2. +14 −0 ios/Classes/Account.m
  3. +39 −0 ios/Classes/DCSquaresMobileAppDelegate.h
  4. +219 −0 ios/Classes/DCSquaresMobileAppDelegate.m
  5. +8 −0 ios/Classes/DCSquaresViewController.h
  6. +5 −0 ios/Classes/DCSquaresViewController.m
  7. +21 −0 ios/Classes/GameOverViewController.h
  8. +5 −0 ios/Classes/GameOverViewController.m
  9. +34 −0 ios/Classes/GameViewController.h
  10. +315 −0 ios/Classes/GameViewController.m
  11. +18 −0 ios/Classes/HUDView.h
  12. +22 −0 ios/Classes/HUDView.m
  13. +13 −0 ios/Classes/MenuViewController.h
  14. +64 −0 ios/Classes/MenuViewController.m
  15. +24 −0 ios/Classes/NSString+MD5.h
  16. +33 −0 ios/Classes/NSString+MD5.m
  17. +24 −0 ios/Classes/ScoresViewController.h
  18. +136 −0 ios/Classes/ScoresViewController.m
  19. +43 −0 ios/Classes/Square.h
  20. +148 −0 ios/Classes/Square.m
  21. +16 −0 ios/Classes/SquaresView.h
  22. +47 −0 ios/Classes/SquaresView.m
  23. +465 −0 ios/DCSquaresMobile.xcodeproj/project.pbxproj
  24. +7 −0 ios/DCSquaresMobile.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  25. BIN ...resMobile.xcodeproj/project.xcworkspace/xcuserdata/sam.xcuserdatad/UserInterfaceState.xcuserstate
  26. +735 −0 ios/DCSquaresMobile.xcodeproj/sam.pbxuser
  27. +1,595 −0 ios/DCSquaresMobile.xcodeproj/sam.perspectivev3
  28. +84 −0 ios/DCSquaresMobile.xcodeproj/xcuserdata/sam.xcuserdatad/xcschemes/DCSquaresMobile.xcscheme
  29. +22 −0 ios/DCSquaresMobile.xcodeproj/xcuserdata/sam.xcuserdatad/xcschemes/xcschememanagement.plist
  30. +8 −0 ios/DCSquaresMobile_Prefix.pch
  31. BIN ios/Default.png
  32. +32 −0 ios/Info.plist
  33. +3,384 −0 ios/MainWindow.xib
  34. +69 −0 ios/Settings.bundle/Root.plist
  35. BIN ios/Settings.bundle/en.lproj/Root.strings
  36. BIN ios/logo.png
  37. +17 −0 ios/main.m
  38. BIN ios/resources/Default.png
  39. BIN ios/resources/bg.png
  40. BIN ios/resources/bigsquare.png
  41. BIN ios/resources/collect.wav
  42. BIN ios/resources/enemy.png
  43. BIN ios/resources/evil.png
  44. BIN ios/resources/frame.png
  45. BIN ios/resources/game_bg.png
  46. BIN ios/resources/gameover.wav
  47. BIN ios/resources/greysquares.png
  48. BIN ios/resources/icon-large.png
  49. BIN ios/resources/icon.png
  50. BIN ios/resources/invincible.png
  51. BIN ios/resources/logo.png
  52. BIN ios/resources/minus1000.png
  53. BIN ios/resources/player.png
  54. BIN ios/resources/plus1000.png
  55. BIN ios/resources/powerdown.wav
  56. BIN ios/resources/powerup.wav
  57. BIN ios/resources/score.png
  58. BIN ios/resources/slowdown.png
  59. BIN ios/resources/smallsquare.png
  60. BIN ios/resources/speedup.png
  61. BIN ios/resources/stat_bg.png
@@ -0,0 +1,19 @@
//
// Account.h
// DCSquaresMobile
//
// Created by Sam Steele on 1/24/09.
// Copyright 2009 Last.fm. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface Account : UIViewController {
IBOutlet UITextField *username;
IBOutlet UITextField *password;
}
@property (nonatomic, retain) UITextField *username;
@property (nonatomic, retain) UITextField *password;

@end
@@ -0,0 +1,14 @@
//
// Account.m
// DCSquaresMobile
//
// Created by Sam Steele on 1/24/09.
// Copyright 2009 Last.fm. All rights reserved.
//

#import "Account.h"


@implementation Account
@synthesize username,password;
@end
@@ -0,0 +1,39 @@
//
// DCSquaresMobileAppDelegate.h
// DCSquaresMobile
//
// Created by Sam Steele on 6/11/08.
// Copyright __MyCompanyName__ 2008. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "MenuViewController.h"
#import "GameViewController.h"
#import "GameOverViewController.h"
#import "ScoresViewController.h"
#import "Account.h"

@interface DCSquaresMobileAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet MenuViewController *_titleViewController;
IBOutlet MenuViewController *_howToPlay1ViewController;
IBOutlet MenuViewController *_howToPlay2ViewController;
IBOutlet GameViewController *_gameViewController;
IBOutlet GameOverViewController *_gameOverViewController;
IBOutlet ScoresViewController *_scoresViewController;
IBOutlet Account *_accountViewController;
}
@property (nonatomic, retain) UIWindow *window;
- (IBAction)newGame:(id)sender;
- (IBAction)gameOver:(id)sender;
- (IBAction)howToPlay:(id)sender;
- (IBAction)howToPlay2:(id)sender;
- (IBAction)scores:(id)sender;
- (IBAction)returnToTitle:(id)sender;
- (IBAction)setupAccount:(id)sender;
- (IBAction)registerAccount:(id)sender;
- (IBAction)loginAccount:(id)sender;
- (NSString *)formatNumber:(int)number;
- (NSString *)formatTime:(int)seconds;
@end

@@ -0,0 +1,219 @@
//
// DCSquaresMobileAppDelegate.m
// DCSquaresMobile
//
// Created by Sam Steele on 6/11/08.
// Copyright __MyCompanyName__ 2008. All rights reserved.
//

#import "DCSquaresMobileAppDelegate.h"
#import "NSString+MD5.h"

@implementation DCSquaresMobileAppDelegate

@synthesize window;
int invalid_code(char *text) {
for(int x=0;x<strlen(text);x++) {
if(text[x]=='?' || text[x]=='@') return 1;
}
return 0;
}

void encode(int score, int size, char *text) {
int val,x;

for(x=0;x<size;x++) {
val=(int)(score/pow(22,size-x));
text[x]=(val+'C');
score-=val*(int)pow(22,size-x);
}

text[x]=(score)+'A';
text[x+1] = '\0';
}

void dcsencrypt(int seed, char *text, unsigned char *out) {
int new_seed=0;
int x=0,y=0;

out[x++]=seed+'A';
for(y=0;y<strlen((char *)text);y++) {
out[x]=text[y] - 'A';
new_seed=out[x];
out[x]+=seed;
out[x]%=26;
seed=new_seed;
out[x]+='A';
if(x==4 || x == 10) {
out[++x] = '-';
}
x++;
}
out[x]='\0';
}

char *build_code(int score, int squares, int combo, int level) {
unsigned char tmp[10];
static unsigned char tmp2[40];
int x,check=0;

encode(score,5,(char *)tmp);
strcpy((char*)tmp2,(char *)tmp);
encode(squares,1,(char *)tmp);
strcat((char *)tmp2,(char *)tmp);
encode(combo,1,(char *)tmp);
strcat((char *)tmp2,(char *)tmp);
encode(level,1,(char *)tmp);
strcat((char *)tmp2,(char *)tmp);

if([[UIDevice currentDevice].model isEqualToString:@"iPod"])
strcat((char *)tmp2,"E");
else
strcat((char *)tmp2,"F");

for(x=0;x<strlen((char *)tmp2);x++) {
check += tmp2[x]-'A';
}
check %= 26;
tmp2[x]=check + 'A';
tmp2[x+1]='\0';

return (char *)tmp2;
}
- (NSString *)formatNumber:(int)number {
CFNumberFormatterRef numberFormatter = CFNumberFormatterCreate(NULL, CFLocaleCopyCurrent(), kCFNumberFormatterDecimalStyle);
NSString *o = (NSString *)CFNumberFormatterCreateStringWithNumber(NULL, numberFormatter, (CFNumberRef)[NSNumber numberWithInt:number]);
free(numberFormatter);
NSString *output = [NSString stringWithString:o];
[o release];
return output;
}
- (NSString *)formatTime:(int)seconds {
if(seconds <= 0)
return @"0:00";
int h = seconds / 3600;
int m = (seconds%3600) / 60;
int s = seconds%60;
if(h)
return [NSString stringWithFormat:@"%i:%02i:%02i", h, m, s];
else
return [NSString stringWithFormat:@"%i:%02i", m, s];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[UIApplication sharedApplication].idleTimerDisabled = YES;
[application setStatusBarHidden:YES];
srand(time(0));
[window addSubview:_titleViewController.view];
[application setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
}
- (void)dealloc {
[window release];
[super dealloc];
}
- (IBAction)newGame:(id)sender {
[[window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[window addSubview:_gameViewController.view];
}
- (void)submitCode {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
unsigned char code[40] = "\0";
if(_gameViewController.score > 1000) {
dcsencrypt(rand()%26, build_code(_gameViewController.score, _gameViewController.squares, _gameViewController.combo, 0), code);

NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:
@"http://dcsquares.c99.org/iphone/score_post_raw.php?s=%s&username=%@&passwordmd5=%@&time=%f",
code,
[[NSUserDefaults standardUserDefaults] objectForKey:@"c99org_user"],
[[[NSUserDefaults standardUserDefaults] objectForKey:@"c99org_password"] md5sum],
_gameViewController.time]]];
}
[pool release];
}
- (IBAction)gameOver:(id)sender {
unsigned char code[40] = "\0";
if(_gameViewController.score > 1000)
dcsencrypt(rand()%26, build_code(_gameViewController.score, _gameViewController.squares, _gameViewController.combo, 0), code);

[[window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[window addSubview:_gameOverViewController.view];
_gameOverViewController.scoreLabel.text = [NSString stringWithFormat:@"%i", _gameViewController.score];
_gameOverViewController.squaresLabel.text = [NSString stringWithFormat:@"%i", _gameViewController.squares];
_gameOverViewController.comboLabel.text = [NSString stringWithFormat:@"%i", _gameViewController.combo];
_gameOverViewController.timeLabel.text = [self formatTime:_gameViewController.time];
_gameOverViewController.codeView.hidden = (code[0] == '\0') || [[[NSUserDefaults standardUserDefaults] objectForKey:@"autosubmit"] isEqualToString:@"YES"];
_gameOverViewController.codeLabel.text = [NSString stringWithUTF8String:(char *)code];

if(code[0] != '\0' && [[[NSUserDefaults standardUserDefaults] objectForKey:@"autosubmit"] isEqualToString:@"YES"]) {
_gameOverViewController.setupAccountButton.hidden = YES;
[NSThread detachNewThreadSelector:@selector(submitCode) toTarget:self withObject:nil];
} else if(![[[NSUserDefaults standardUserDefaults] objectForKey:@"autosubmit"] isEqualToString:@"YES"]) {
_gameOverViewController.setupAccountButton.hidden = NO;
}
}
- (IBAction)setupAccount:(id)sender {
[_gameOverViewController presentModalViewController:_accountViewController animated:YES];
}
- (IBAction)registerAccount:(id)sender {
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:
@"http://dcsquares.c99.org/iphone/new_user.php?username=%@&password=%@&UDID=%@",
_accountViewController.username.text,
_accountViewController.password.text,
[[UIDevice currentDevice] uniqueIdentifier]]]];
NSLog(@"%@", result);
if([result isEqualToString:@"OK"]) {
[[NSUserDefaults standardUserDefaults] setObject:_accountViewController.username.text forKey:@"c99org_user"];
[[NSUserDefaults standardUserDefaults] setObject:_accountViewController.password.text forKey:@"c99org_password"];
[[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"autosubmit"];
[[NSUserDefaults standardUserDefaults] synchronize];
_gameOverViewController.setupAccountButton.hidden = YES;
[_gameOverViewController dismissModalViewControllerAnimated:YES];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Registration Successful" message:@"Your account has been created successfully!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
[NSThread detachNewThreadSelector:@selector(submitCode) toTarget:self withObject:nil];
} else if([result isEqualToString:@"FAIL"] || [result length] == 0) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Registration Failed" message:@"An error occured while creating your account. Please try again shortly." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
} else {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Registration Failed" message:result delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
}
}
- (IBAction)loginAccount:(id)sender {
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:
@"http://dcsquares.c99.org/iphone/auth_test.php?username=%@&password=%@&UDID=%@",
_accountViewController.username.text,
_accountViewController.password.text,
[[UIDevice currentDevice] uniqueIdentifier]]]];
NSLog(@"%@", result);
if([result isEqualToString:@"OK"]) {
[[NSUserDefaults standardUserDefaults] setObject:_accountViewController.username.text forKey:@"c99org_user"];
[[NSUserDefaults standardUserDefaults] setObject:_accountViewController.password.text forKey:@"c99org_password"];
[[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"autosubmit"];
[[NSUserDefaults standardUserDefaults] synchronize];
_gameOverViewController.setupAccountButton.hidden = YES;
[_gameOverViewController dismissModalViewControllerAnimated:YES];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Login Successful" message:@"You have successfully logged into DCSquares Online on this device." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
[NSThread detachNewThreadSelector:@selector(submitCode) toTarget:self withObject:nil];
} else {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Login Failed" message:@"Check your username and password and try again." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
}
}
- (IBAction)howToPlay:(id)sender {
[[window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[window addSubview:_howToPlay1ViewController.view];
}
- (IBAction)howToPlay2:(id)sender {
[[window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[window addSubview:_howToPlay2ViewController.view];
}
- (IBAction)returnToTitle:(id)sender {
[[window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[window addSubview:_titleViewController.view];
}
- (IBAction)scores:(id)sender {
[[window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[window addSubview:_scoresViewController.view];
}
@end
@@ -0,0 +1,8 @@
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface DCSquaresViewController : /* Specify a superclass (eg: NSObject or NSView) */ {

}

@end
@@ -0,0 +1,5 @@
#import "DCSquaresViewController.h"

@implementation DCSquaresViewController

@end
@@ -0,0 +1,21 @@
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "MenuViewController.h"

@interface GameOverViewController : MenuViewController {
IBOutlet UILabel *scoreLabel;
IBOutlet UILabel *squaresLabel;
IBOutlet UILabel *comboLabel;
IBOutlet UILabel *timeLabel;
IBOutlet UIView *codeView;
IBOutlet UILabel *codeLabel;
IBOutlet UIButton *setupAccountButton;
}
@property (nonatomic, retain) UILabel *scoreLabel;
@property (nonatomic, retain) UILabel *squaresLabel;
@property (nonatomic, retain) UILabel *comboLabel;
@property (nonatomic, retain) UILabel *timeLabel;
@property (nonatomic, retain) UIView *codeView;
@property (nonatomic, retain) UILabel *codeLabel;
@property (nonatomic, retain) UIButton *setupAccountButton;
@end
@@ -0,0 +1,5 @@
#import "GameOverViewController.h"

@implementation GameOverViewController
@synthesize scoreLabel, squaresLabel, comboLabel, timeLabel, codeView, codeLabel,setupAccountButton;
@end
@@ -0,0 +1,34 @@
//
// GameViewController.h
// DCSquaresMobile
//
// Created by Sam Steele on 6/11/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h>
#import "SquaresView.h"
#import "HUDView.h"

@interface GameViewController : UIViewController<UIAccelerometerDelegate> {
IBOutlet SquaresView *_squaresView;
IBOutlet HUDView *_scoreHUD;
IBOutlet HUDView *_squaresHUD;
IBOutlet HUDView *_timeHUD;
IBOutlet HUDView *_comboHUD;
IBOutlet UILabel *_powerLabel;
IBOutlet UIView *_powerBar;
int score, combo, squares, _scoreval, powerType;
float speed, size, time, _powerLevel;
float _spawnTimer, _introTimer;
float _ticker, _tickRate;
Square *player;
NSThread *_updatethd;
SystemSoundID _scoreSound, _gameOverSound, _powerUpSound, _powerDownSound;
}
@property(readwrite) int score, combo, squares, powerType;
@property(readwrite) float speed, size, time;
@property(readonly) Square *player;
-(void)collision:(Square *)square;
@end

0 comments on commit 74c9bee

Please sign in to comment.
You can’t perform that action at this time.