如果第一次按下按钮,我想设置我的游戏。或者另一种选择是,如果积分高于0则设置游戏。但是,我想这样做,但我不知道如何。你能救我一下吗?
BTW:我刚刚开始使用这个应用程序编程,如果你已经可以在我的代码中集成解决方案,我会很喜欢它。 XCode项目 - > http://techstern.de/app/KlickMich.zip
截图 - > http://techstern.de/app/screenshot2.png
德语单词的翻译:
Zeit - >时间
Punktestand - >分数
KlickMich - > TapMe
Die Zeit ist um - >时间到了
Du hast 12 Punkte erzielt - >你得了12分
Auf Facebook teilen - >在Facebook上分享
Auf Twitter teilen - >在Twitter上分享
#import <UIKit/UIKit.h>
#import "ViewController.m"
@interface ViewController : UIViewController<UIAlertViewDelegate> {
IBOutlet UILabel *scoreLabel;
IBOutlet UILabel *timerLabel;
NSInteger count;
NSInteger seconds;
NSTimer *timer;
}
- (IBAction)buttonPressed;
- (void)setupGame;
- (void)subtractTime;
- (void)postToTwitter;
- (void)postToFacebook;
@end
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setupGame];
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonPressed{
count++;
scoreLabel.text = [NSString stringWithFormat:@"Punktestand: %li",(long)count];
}
- (void)setupGame{
seconds = 15;
count = 0;
timerLabel.text = [NSString stringWithFormat:@"Zeit: %li",(long)seconds];
scoreLabel.text = [NSString stringWithFormat:@"Punktestand: %li",(long)count];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(subtractTime)
userInfo:nil
repeats:YES];
}
- (void)subtractTime{
seconds--;
timerLabel.text = [NSString stringWithFormat:@"Zeit: %li",(long)seconds];
if (seconds == 0) {
[timer invalidate];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Die Zeit ist um"
message:[NSString stringWithFormat:@"Du hast %li Punkte erzielt",(long)count]
delegate:self
cancelButtonTitle:@"Nochmal spielen"
otherButtonTitles:@"Auf Facebook teilen", @"Auf Twitter teilen", nil];
[alert show];
}
}
[…]
忠实的你 罗宾
答案 0 :(得分:1)
试试这个。
声明你的[self setupGame]; buttonPressed
行动中的方法,而不是下面的- (void)viewDidLoad
。
- (IBAction)buttonPressed
{
if (count == 0)
{
[self setupGame];
}
count++;
scoreLabel.text = [NSString stringWithFormat:@"Punktestand: %li",(long)count];
}
如果您的alertview
即将到来并取消提醒视图或在Twitter上分享后,您的游戏将重置,而不是等待按钮点击。如果你想要你也可以改变。没问题:)