Ios 如何将xcode中的视图控制器重置为启动应用程序时的状态

Ios 如何将xcode中的视图控制器重置为启动应用程序时的状态,ios,iphone,xcode,Ios,Iphone,Xcode,如何将xcode中的视图控制器重置为启动应用程序时的状态 @interface Game () @end @implementation Game -(void)Restart{ Mx = 0; Mx2 = 0; My = 0; My2 = 0; WizX = 1; WizY = 0; } -(void)MonsterMovment2{ float screen_width2; float screen_height2; float vers = [[[UIDevice current

如何将xcode中的视图控制器重置为启动应用程序时的状态

@interface Game ()

@end

@implementation Game

-(void)Restart{
Mx = 0;
Mx2 = 0;
My = 0;
My2 = 0;
WizX = 1;
WizY = 0;


}
-(void)MonsterMovment2{
float screen_width2;
float screen_height2;
float vers = [[[UIDevice currentDevice] systemVersion] floatValue];
UIInterfaceOrientation orient = [UIApplication                             sharedApplication].statusBarOrientation;
if (vers < 8 && UIInterfaceOrientationIsLandscape(orient))
 {
    screen_width2 = [[UIScreen mainScreen] bounds].size.width;
    screen_height2 = [[UIScreen mainScreen] bounds].size.height;
}
else
{
    screen_width2 = [[UIScreen mainScreen] bounds].size.width;
    screen_height2 = [[UIScreen mainScreen] bounds].size.height;
}


Monster2.center = CGPointMake(Monster2.center.x + Mx2,             Monster2.center.y + My2);

if (CGRectIntersectsRect(Monster2.frame, Wiz.frame)) {
  [self GameOver];

  }

if (Monster2.center.x < 10) {
    Mx2 = 1;
}

if (Monster2.center.x > screen_width2) {
    Mx2 = -1;
}

if (Monster2.center.y > screen_height2) {
    My2 = -1;

}

if (Monster2.center.y < 10) {

    My2 = 1;

}




}


-(void)MonsterMovment{
 float screen_width;
float screen_height;
float vers = [[[UIDevice currentDevice] systemVersion] floatValue];
UIInterfaceOrientation orient = [UIApplication     sharedApplication].statusBarOrientation;
if (vers < 8 && UIInterfaceOrientationIsLandscape(orient))
{
    screen_width = [[UIScreen mainScreen] bounds].size.width;
    screen_height = [[UIScreen mainScreen] bounds].size.height;
}
else
{
    screen_width = [[UIScreen mainScreen] bounds].size.width;
    screen_height = [[UIScreen mainScreen] bounds].size.height;
}


Monster.center = CGPointMake(Monster.center.x + Mx, Monster.center.y +     My);

if (CGRectIntersectsRect(Monster2.frame, Monster.frame)) {
    Mx = Mx;
    My=My;

}

if (CGRectIntersectsRect(Monster.frame, Wiz.frame)) {
    [self GameOver];

}


if (Monster.center.x < 10) {
    Mx = 1;
}

if (Monster.center.x > screen_width) {
    Mx = -1;
}

if (Monster.center.y > screen_height) {
    My = -1;

}

if (Monster.center.y < 10) {

    My = 1;

}


 }

-(void)GameOver{
StartGame.hidden = YES;
[WizMovment invalidate ];
Wiz.hidden = YES;
Exit.hidden = NO;
 StartGame.hidden = NO;


if (ScoreNumber > HighScoreNumber) {
    [[NSUserDefaults standardUserDefaults] setInteger:ScoreNumber   forKey:@"HighScoreSaved"];
    HighScore.text = [NSString stringWithFormat:@"High Score: %i",   ScoreNumber];
}

[self viewDidLoad];


 }

 -(void)Score{
ScoreNumber = ScoreNumber + 1;
ScoreLabel.text = [NSString stringWithFormat:@"Score: %i", ScoreNumber];

  }

-(void)PlaceFood{
float screen_width;
float screen_height;
float vers = [[[UIDevice currentDevice] systemVersion] floatValue];
UIInterfaceOrientation orient = [UIApplication     sharedApplication].statusBarOrientation;
 if (vers < 8 && UIInterfaceOrientationIsLandscape(orient))
{
    screen_height = [[UIScreen mainScreen] bounds].size.width;
    screen_width = [[UIScreen mainScreen] bounds].size.height;
}
else
{
    screen_width = [[UIScreen mainScreen] bounds].size.width;
    screen_height = [[UIScreen mainScreen] bounds].size.height;
}
int height = (int) screen_height;
int widht = (int) screen_width;

FoodX = arc4random() %height;
FoodX = FoodX - 25;
if (25 < FoodX) {
    FoodX = 25;
}
FoodY = arc4random() %widht;
FoodY = FoodY -25;
if (25 < FoodY) {
    FoodY = 25;
}

Food.center = CGPointMake(FoodX, FoodY);

[Food setFrame:CGRectMake(FoodX, FoodY, Food.frame.size.width,     Food.frame.size.height)];

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib
}

-(void)MoveLeft{
if (WizSideMovment == NO) {
    WizX = -1;
    WizY = 0;
    WizSideMovment = YES;
}
}

-(void)MoveRight{
if (WizSideMovment == NO) {
    WizX = 1;
    WizY = 0;
    WizSideMovment = YES;
}
}

-(void)MoveUp{
if (WizSideMovment == YES) {
    WizX = 0;
    WizY = -1;
    WizSideMovment = NO;
}
}

-(void)MoveDown{
if (WizSideMovment == YES) {
    WizX = 0;
    WizY = 1;
    WizSideMovment = NO;
}
}
-(void)WizMovment{
float screen_width;
float screen_height;
float vers = [[[UIDevice currentDevice] systemVersion] floatValue];
UIInterfaceOrientation orient = [UIApplication sharedApplication].statusBarOrientation;
if (vers < 8 && UIInterfaceOrientationIsLandscape(orient))
{
    screen_height = [[UIScreen mainScreen] bounds].size.width;
    screen_width = [[UIScreen mainScreen] bounds].size.height;
}
else
{
    screen_width = [[UIScreen mainScreen] bounds].size.width;
    screen_height = [[UIScreen mainScreen] bounds].size.height;
}



            Wiz.center = CGPointMake(Wiz.center.x + WizX, Wiz.center.y     + WizY);

            if (CGRectIntersectsRect(Wiz.frame, Food.frame)) {
                [self PlaceFood];
                [self Score];



}

if (Wiz.center.x < 1) {
    [WizMovment invalidate];
    [self performSelector:@selector(GameOver) withObject:self    afterDelay:0.5];
}

if (Wiz.center.x > screen_width - 25) {
    [WizMovment invalidate];
    [self performSelector:@selector(GameOver) withObject:self   afterDelay:0.5];
}

if (Wiz.center.y > screen_height - 25) {
    [WizMovment invalidate];
    [self performSelector:@selector(GameOver) withObject:self afterDelay:0.5];
}

if (Wiz.center.y < 25) {
    [WizMovment invalidate];
    [self performSelector:@selector(GameOver) withObject:self afterDelay:0.5];
}
}

-(IBAction)Exit:(id)sender{

[self reloadInputViews];
[self Restart];

}
-(IBAction)Start:(id)sender{
 int i = rand()%2+1;
NSLog(@"Random Number: %i", i);
if ( (i = 2)) {
    i = -1;
}
int w = rand()%2+1;
NSLog(@"Random Number: %i", w);
if ( (w = 2)) {
    w = -1;
}
int e = rand()%2+1;
NSLog(@"Random Number: %i", e);
if ( (e = 2)) {
    e = -1;
}
int r = rand()%2+1;
NSLog(@"Random Number: %i", r);
if ( (r = 2)) {
    r = -1;
}

Mx=i;
Mx2 =w;
My=e;
My2=r;
StartGame.hidden = YES;

Wiz.hidden= NO;
WizX = 1;
WizY = 0;

 Food.hidden = NO;

 WizMovment = [NSTimer scheduledTimerWithTimeInterval:0.007 target:self    selector:@selector(WizMovment) userInfo:nil repeats:YES];

MonsterMovment = [NSTimer scheduledTimerWithTimeInterval:0.007 target:self selector:@selector(MonsterMovment) userInfo:nil repeats:YES];

 MonsterMovment2 = [NSTimer scheduledTimerWithTimeInterval:0.007    target:self selector:@selector(MonsterMovment2) userInfo:nil repeats:YES];

[self PlaceFood];

/* int i = rand()%2+1;
NSLog(@"Random Number: %i", i);
if ( (i = 2)) {
    i = -1;
}
int w = rand()%2+1;
NSLog(@"Random Number: %i", w);
if ( (w = 2)) {
    w = -1;
}
int e = rand()%2+1;
NSLog(@"Random Number: %i", e);
if ( (e = 2)) {
    e = -1;
}
int r = rand()%2+1;
NSLog(@"Random Number: %i", r);
if ( (r = 2)) {
    r = -1;
}

Mx=i;
Mx2 =w;
My=e;
My2=r;

*/


}

- (void)viewDidLoad {

//[[UIScreen mainScreen] bounds];
Exit.hidden = YES;
HighScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey:@"HighScoreSaved"];
HighScore.text = [NSString stringWithFormat:@"High Score: %li", (long)HighScoreNumber];
[super viewDidLoad];
// Do any additional setup after loading the view.
Food.hidden = YES;
WizX = 1;
WizY = 0;
WizSideMovment = YES;


UISwipeGestureRecognizer *SwipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(MoveLeft)];
[SwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:SwipeLeft];

UISwipeGestureRecognizer *SwipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(MoveRight)];
[SwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:SwipeRight];

UISwipeGestureRecognizer *SwipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(MoveUp)];
[SwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[self.view addGestureRecognizer:SwipeUp];

UISwipeGestureRecognizer *SwipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(MoveDown)];
[SwipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
[self.view addGestureRecognizer:SwipeDown];
@界面游戏()
@结束
@实施游戏
-(无效)重新启动{
Mx=0;
Mx2=0;
My=0;
My2=0;
WizX=1;
WizY=0;
}
-(无效)移动2{
浮动筛2;
浮动筛高2;
浮点值=[[UIDevice currentDevice]系统版本]浮点值];
UIInterfaceOrientation=[UIApplication sharedApplication].StatusBaroOrientation;
if(vers<8&&UIInterfaceOrientationIsLandscape(orient))
{
屏幕宽度2=[[UIScreen mainScreen]边界].size.width;
屏幕高度2=[[UIScreen mainScreen]界限].size.height;
}
其他的
{
屏幕宽度2=[[UIScreen mainScreen]边界].size.width;
屏幕高度2=[[UIScreen mainScreen]界限].size.height;
}
Monster2.center=CGPointMake(Monster2.center.x+Mx2,Monster2.center.y+My2);
if(CGRectIntersectsRect(Monster2.frame,Wiz.frame)){
[自我放逐];
}
如果(2.center.x<10){
Mx2=1;
}
如果(怪物2.center.x>屏幕宽度2){
Mx2=-1;
}
如果(怪物2.center.y>屏幕高度2){
My2=-1;
}
如果(2.中心y<10){
My2=1;
}
}
-(无效)移动{
浮动屏幕宽度;
浮网高度;
浮点值=[[UIDevice currentDevice]系统版本]浮点值];
UIInterfaceOrientation=[UIApplication sharedApplication].StatusBaroOrientation;
if(vers<8&&UIInterfaceOrientationIsLandscape(orient))
{
屏幕宽度=[[UIScreen mainScreen]边界].size.width;
屏幕高度=[[UIScreen mainScreen]界限].size.height;
}
其他的
{
屏幕宽度=[[UIScreen mainScreen]边界].size.width;
屏幕高度=[[UIScreen mainScreen]界限].size.height;
}
Monster.center=CGPointMake(Monster.center.x+Mx,Monster.center.y+My);
如果(CGRectIntersectsRect(怪物2.frame,怪物.frame)){
Mx=Mx;
我的=我的;
}
if(CGRectIntersectsRect(Monster.frame,Wiz.frame)){
[自我放逐];
}
if(怪物中心x<10){
Mx=1;
}
if(Monster.center.x>屏幕宽度){
Mx=-1;
}
如果(怪物中心y>屏幕高度){
My=-1;
}
如果(怪物中心y<10){
My=1;
}
}
-(无效)游戏结束{
StartGame.hidden=是;
[WizMovment失效];
Wiz.hidden=是;
Exit.hidden=否;
StartGame.hidden=否;
如果(ScoreNumber>HighScoreNumber){
[[NSUserDefaults standardUserDefaults]setInteger:ScoreNumber-forKey:@“HighScoreSaved”];
HighScore.text=[NSString stringWithFormat:@“高分:%i”,分数编号];
}
[自视下载];
}
-(无效)分数{
ScoreNumber=ScoreNumber+1;
ScoreLabel.text=[NSString stringWithFormat:@“分数:%i”,分数编号];
}
-(空)食物{
浮动屏幕宽度;
浮网高度;
浮点值=[[UIDevice currentDevice]系统版本]浮点值];
UIInterfaceOrientation=[UIApplication sharedApplication].StatusBaroOrientation;
if(vers<8&&UIInterfaceOrientationIsLandscape(orient))
{
屏幕高度=[[UIScreen mainScreen]边界].size.width;
屏幕宽度=[[UIScreen mainScreen]边界].size.height;
}
其他的
{
屏幕宽度=[[UIScreen mainScreen]边界].size.width;
屏幕高度=[[UIScreen mainScreen]界限].size.height;
}
整数高度=(整数)屏幕高度;
int widt=(int)屏幕宽度;
FoodX=arc4random()%高度;
FoodX=FoodX-25;
如果(25屏幕宽度-25){
[WizMovment失效];
[自执行选择器:@selector(GameOver)with object:self afterDelay:0.5];
}
如果(Wiz.center.y>屏幕高度-25){
[WizMovment失效];
[自执行选择器:@selector(GameOver)with object:self afterDelay:0.5];
}
if(中心宽度y<25){
[WizMovment失效];
[自执行选择器:@selector(GameOver)with object:self afterDelay:0.5];
}
}
-(iAction)退出:(id)发送方{
[自重新加载输入视图];
[自重启];
}
-(iAction)开始:(id)发送方{
int i=rand()%2+1;
NSLog(@“随机数:%i”,i);
如果((i=2)){
i=-1;
}
int w=rand()%2+1;
NSLog(@“随机数:%i”,w);
如果((w=2)){
w=-1;
}
int e=rand()%2+1;
NSLog(@“随机数:%i”,e);
如果((e=2)){
e=-1;
}
int r=rand()%2+1;
NSLog(@“随机数:%i”,r);
如果((r=2)){
r=-1;
}
Mx=i;
Mx2=w;
My=e;
My2=r;
StartGame.hidden=是;
Wiz.隐藏=否;
WizX=1;
WizY=0;
食物