【IOS】自分で書いたシュルト四角app
18002 ワード
これは私自身が手を練習するためのappで、基本的な機能を実現しました...感じは悪くなくて、分かち合って、批判の指摘を歓迎します(ダウンロードの住所を添付して、一番下)
完全なプロジェクトのダウンロードアドレス:http://download.csdn.net/detail/dongge_111/4206406
//
// ShuConfigView.h
// ShuRect
//
// Created by on 12-3-30.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import
#import
#import "GameView.h"
@interface ShuConfigView : UIViewController
{
UIView *backView;
UIView *btnView;
UIButton *modeBtn; //
UIButton *numberBtn; //
UIButton *beginBtn; //
UIImage *kidsImage; //
UIImage *memoryImage; //
UIImage *adultImage; //
UIImage *numThreeImage; //3*3
UIImage *numFourImage; //4*4
UIImage *numFiveImage; //5*5
UIImage *gameBeginImage; //
GameView *toGameView;
int modeInt;
int numInt;
}
@property (nonatomic, retain) UIButton *modeBtn;
@property (nonatomic, retain) UIButton *numberBtn;
@property (nonatomic, retain) UIButton *beginBtn;
@property (nonatomic, retain) UIView *backView;
@property (nonatomic, retain) UIView *btnView;
@property (nonatomic, retain) UIImage *kidsImage;
@property (nonatomic, retain) UIImage *memoryImage;
@property (nonatomic, retain) UIImage *adultImage;
@property (nonatomic, retain) UIImage *numThreeImage;
@property (nonatomic, retain) UIImage *numFourImage;
@property (nonatomic, retain) UIImage *numFiveImage;
@property (nonatomic, retain) UIImage *gameBeginImage;
@property (nonatomic, retain) GameView *toGameView;
@end
//
// ShuConfigView.m
// ShuRect
//
// Created by on 12-3-30.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ShuConfigView.h"
//#define kDuration 0.7 //
@implementation ShuConfigView
@synthesize modeBtn,numberBtn,beginBtn;
@synthesize backView,btnView;
@synthesize kidsImage,memoryImage,adultImage,numThreeImage,numFourImage,numFiveImage,gameBeginImage;
@synthesize toGameView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
modeInt = 0;
numInt = 3;
backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UIImage *backImage = [UIImage imageNamed:@"background.png"];
UIImageView *backImageView = [[UIImageView alloc] initWithImage:backImage];
[backView addSubview:backImageView];
kidsImage = [UIImage imageNamed:@"child_mode_n.png"];
memoryImage = [UIImage imageNamed:@"memory_mode_n.png"];
adultImage = [UIImage imageNamed:@"audlt_mode_n.png"];
numThreeImage = [UIImage imageNamed:@"level3_n.png"];
numFourImage = [UIImage imageNamed:@"level4_n.png"];
numFiveImage = [UIImage imageNamed:@"level5_n.png"];
gameBeginImage = [UIImage imageNamed:@"start_n.png"];
modeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[modeBtn setImage:kidsImage forState:UIControlStateNormal];
[modeBtn setFrame:CGRectMake(46, 200, 227, 50)];
[modeBtn addTarget:self action:@selector(modePressed:) forControlEvents:UIControlEventTouchUpInside];
[btnView addSubview:modeBtn];
numberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[numberBtn setImage:numThreeImage forState:UIControlStateNormal];
[numberBtn setFrame:CGRectMake(46, 270, 227, 50)];
[numberBtn addTarget:self action:@selector(numPressed:) forControlEvents:UIControlEventTouchUpInside];
[btnView addSubview:numberBtn];
beginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[beginBtn setImage:gameBeginImage forState:UIControlStateNormal];
[beginBtn setFrame:CGRectMake(46, 340, 227, 50)];
[beginBtn addTarget:self action:@selector(beginPressed:) forControlEvents:UIControlEventTouchUpInside];
[btnView addSubview:beginBtn];
}
return self;
}
/*
*********
*/
-(void)modePressed:(id)sender
{
UIButton *myBtn = (UIButton *)sender;
modeInt ++;
if (modeInt == 1) {
[myBtn setImage:memoryImage forState:UIControlStateNormal];
}
else if(modeInt == 2)
{
[myBtn setImage:adultImage forState:UIControlStateNormal];
}
else {
modeInt = 0;
[myBtn setImage:kidsImage forState:UIControlStateNormal];
}
NSLog(@" %d",modeInt);
}
/*
*********
*/
-(void)beginPressed:(id)sender
{
toGameView = [[GameView alloc] init];
toGameView.modNum = modeInt;
switch (numInt) {
case 3:
toGameView.rowNum = 3;
break;
case 4:
toGameView.rowNum = 4;
break;
case 5:
toGameView.rowNum = 5;
break;
default:
break;
}
/*
*
*/
/*CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = kDuration;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type = kCATransitionFade;
animation.subtype = kCATransitionFromLeft;*/
[toGameView resetGame:nil];
[self presentModalViewController:toGameView animated:YES];
}
/*
*********
*/
-(void)numPressed:(id)sender
{
UIButton *myBtn = (UIButton *)sender;
if (numInt == 3) {
numInt = 4;
[myBtn setImage:numFourImage forState:UIControlStateNormal];
}
else if (numInt == 4)
{
numInt = 5;
[myBtn setImage:numFiveImage forState:UIControlStateNormal];
}else {
numInt = 3;
[myBtn setImage:numThreeImage forState:UIControlStateNormal];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addSubview:backView];
[self.view addSubview:btnView];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
//
// GameView.m
// ShuRect
//
// Created by on 12-3-30.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "GameView.h"
@interface GameView ()
-(void)initNumArray;
-(void)numBtnPressed:(id)sender;
@end
@implementation GameView
@synthesize gameBtnView,gameBackView;
@synthesize gameNumArray;
@synthesize gameNumBtn,redBtnImage,greenBtnImage;
@synthesize resetGameBtn,resetBtnNormalImage,resetBtnPressedImage,backGameBtn,backBtnNormalImage,backBtnPressedImage,stillTime,beginTime;
@synthesize rowNum,modNum;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
rowNum = 3;
modNum = 0;
currentNum = 1;
timeInt = 3;
timeFloat = 0.00;
stillTime = [[UILabel alloc] initWithFrame:CGRectMake(110, 30, 100, 40)];
[stillTime setText:@"3"];
[stillTime setBackgroundColor:[UIColor colorWithWhite:0 alpha:0]];
[stillTime setTextAlignment:UITextAlignmentCenter];
beginTime = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
[self initNumArray];
gameBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
gameBtnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UIImage *backImage = [UIImage imageNamed:@"background.png"];
UIImageView *backImageView = [[UIImageView alloc] initWithImage:backImage];
[gameBackView addSubview:backImageView];
redBtnImage = [UIImage imageNamed:@"orange.png"];
greenBtnImage = [UIImage imageNamed:@"green.png"];
resetBtnNormalImage = [UIImage imageNamed:@"btn_replay_normal.png"];
resetBtnPressedImage = [UIImage imageNamed:@"btn_replay_pressed.png"];
resetGameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[resetGameBtn setImage:resetBtnNormalImage forState:UIControlStateNormal];
[resetGameBtn setImage:resetBtnPressedImage forState:UIControlEventTouchDown];
[resetGameBtn setFrame:CGRectMake(240, 10, 60, 60)];
[resetGameBtn addTarget:self action:@selector(resetGame:) forControlEvents:UIControlEventTouchUpInside];
[gameBtnView addSubview:resetGameBtn];
backBtnNormalImage = [UIImage imageNamed:@"btn_back_normal.png"];
backBtnPressedImage = [UIImage imageNamed:@"btn_back_pressed.png"];
backGameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backGameBtn setImage:backBtnNormalImage forState:UIControlStateNormal];
[backGameBtn setImage:backBtnPressedImage forState:UIControlEventTouchDown];
[backGameBtn setFrame:CGRectMake(10, 10, 60, 60)];
[backGameBtn addTarget:self action:@selector(backGame:) forControlEvents:UIControlEventTouchUpInside];
[gameBackView addSubview:stillTime];
[gameBtnView addSubview:backGameBtn];
}
return self;
}
/*
******* 3
*/
-(void)timerFireMethod:(NSTimer *)theTimer
{
if (timeInt == 1) {
[beginTime invalidate];
if (modNum == 1) {
[self initBtnRectMemory];
}
NSLog(@"jieshu");
beginTime = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerFireMethodBegin:) userInfo:nil repeats:YES];
return;
}
timeInt--;
[stillTime setText:[NSString stringWithFormat:@"%d",timeInt]];
}
/*
*******
*/
-(void)timerFireMethodBegin:(NSTimer *)theTimer
{
timeFloat+=0.01;
[stillTime setText:[NSString stringWithFormat:@"%.2f",timeFloat]];
}
/*
*******
*/
-(void)backGame:(id)sender
{
/*ShuConfigView *backHome = [[ShuConfigView alloc] init];
backHome.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:backHome animated:YES];*/
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self dismissModalViewControllerAnimated:YES];
}
/*
*******
*/
-(void)resetGame:(id)sender
{
if (gameNumBtn!=nil) {
gameNumBtn = nil;
[gameBtnView removeFromSuperview];
}
currentNum = 1;
NSLog(@"%d",rowNum);
[self initNumArray];
[self initBtnRect];
[self.view addSubview:gameBtnView];
timeFloat = 0.00;
timeInt = 3;
[beginTime invalidate];
[stillTime setText:[NSString stringWithFormat:@"%d",timeInt]];
beginTime = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
}
/*
*******
*/
-(void)initBtnRect
{
float btnWidth = (290-10*(rowNum-1))/rowNum;
float btnHeight = (380-10*(rowNum-1))/rowNum;
for (int i = 0, countNum = 1; i= 0.01) {
if (myBtn.tag == currentNum) {
if (modNum == 0) {
[myBtn setBackgroundImage:greenBtnImage forState:UIControlStateNormal];
}
if (modNum == 1) {
[myBtn setTitle:[NSString stringWithFormat:@"%d",myBtn.tag] forState:UIControlStateNormal];
}
if (myBtn.tag == rowNum*rowNum) {
[beginTime invalidate];
GameAlertC *alert = [[GameAlertC alloc] initGameAlert:@"alertBack.jpg" rect:CGRectMake(0, 0, 300, 300) title:[NSString stringWithFormat:@" :%.2f ",timeFloat]];
alert._delegate = self;
[self.view addSubview:alert];
return;
}
currentNum ++;
}
}
}
/*
*******
*/
-(void) AfterClickBtn:(id)sender
{
UIButton * sc = (UIButton *)sender;
if (sc.tag == 1) {
[self dismissModalViewControllerAnimated:YES];
}else {
[self resetGame:nil];
}
}
/*
*******
*/
-(void)initNumArray
{
int array_insert;
gameNumArray = [NSMutableArray arrayWithCapacity:rowNum*rowNum];
array_insert=(int)(arc4random() % (rowNum*rowNum))+1;
[gameNumArray addObject:[NSNumber numberWithInt:array_insert]];
for (int i=0; i
//
// GameAlertC.m
// ShuRect
//
// Created by on 12-4-4.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "GameAlertC.h"
@implementation GameAlertC
@synthesize _delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(id)initGameAlert:(NSString *)backImageStr rect:(CGRect)backRect title:(NSString *)alertTitleStr
{
self = [super initWithFrame:CGRectMake(0, 0, 320, 480)];
if (self) {
self.userInteractionEnabled = YES;
NSLog(@"RectHeight:%f",backRect.size.height*2/3);
UIImageView *alertBackImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:backImageStr]];
alertBackImageView.userInteractionEnabled = YES;
[alertBackImageView setFrame:backRect];
UILabel *alertLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, backRect.size.width, backRect.size.height*2/3)];
[alertLabel setText:alertTitleStr];
[alertLabel setBackgroundColor:[UIColor colorWithWhite:0 alpha:0]];
[alertLabel setTextAlignment:UITextAlignmentCenter];
alertLabel.center = alertBackImageView.center;
[alertBackImageView addSubview:alertLabel];
alertBackImageView.center = self.center;
// border
alertBackImageView.layer.cornerRadius = 8;
alertBackImageView.layer.borderWidth = 2;
alertBackImageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
alertBackImageView.layer.masksToBounds = YES;
//
CAKeyframeAnimation *animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 0.3;
animation.delegate = self;
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeForwards;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
[alertBackImageView.layer addAnimation:animation forKey:nil];
UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
okBtn.tag = 1;
okBtn.frame = CGRectMake(alertBackImageView.frame.size.width/2-55, 6*alertBackImageView.frame.size.height/7-25, 50, 30);
/*[okBtn setBackgroundColor:[UIColor yellowColor]];
okBtn.layer.cornerRadius = 8;
okBtn.layer.masksToBounds = YES;*/
[okBtn setTitle:@"Menu" forState:UIControlStateNormal];
[okBtn addTarget:self action:@selector(popAlert:) forControlEvents:UIControlEventTouchUpInside];
[alertBackImageView addSubview:okBtn];
UIButton *againBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
againBtn.frame = CGRectMake(alertBackImageView.frame.size.width/2+45, 6*alertBackImageView.frame.size.height/7-25, 50, 30);
/*[okBtn setBackgroundColor:[UIColor yellowColor]];
okBtn.layer.cornerRadius = 8;
okBtn.layer.masksToBounds = YES;*/
[againBtn setTitle:@"Again" forState:UIControlStateNormal];
againBtn.tag = 2;
[againBtn addTarget:self action:@selector(popAlert:) forControlEvents:UIControlEventTouchUpInside];
[alertBackImageView addSubview:againBtn];
[self addSubview:alertBackImageView];
}
return self;
}
//
-(void)popAlert:(id)sender
{
UIButton *switchBtn = (UIButton *)sender;
[_delegate AfterClickBtn:switchBtn];
[self removeFromSuperview];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
完全なプロジェクトのダウンロードアドレス:http://download.csdn.net/detail/dongge_111/4206406