Fistly我相當新的編程一般。 Objective C和IOS編程非常新穎。這只是我正在寫作的一門練習編程。NSTimer或暫停操作?
什麼它基本上做到這一點是:
計算機選擇多次攻擊,然後隨機據法權產,以1至4或0和3(真的無所謂)的數字。每次它通過for循環時都會執行此操作。
什麼,我試圖完成的是:
如果計算機選取0,則凸顯了相應的按鈕並使其活躍用戶與互動,但他們只是有一定的時間來按下所述按鈕。定時器調用一個不按下按鈕並使其處於非活動狀態的功能。
所有這些工作,但它都發生在同一時間。如果計算機攻擊三次,則所有三個按鈕都會同時突出顯示並激活,然後同時處於不活動狀態。我想讓程序暫停一段時間,讓玩家有足夠的時間按下按鈕。我無法弄清楚這一部分。我想使用一個while循環,當一個按鈕被按下時,或者當定時器調用這個函數時,這個循環只會讓它停留在while循環中。我已經在第一個陳述中表明瞭這一點。
再次請保持簡單,因爲我對編程新手。由於
if(theEnemy.attackingOrBlocking == 1)
{
int whereAttack;
int numberOfAttacks = 3; //theEnemy.numOfAttacks;
for (int i = 0; i <= numberOfAttacks; i++)
{
whereAttack = theEnemy.attackButton;
if (whereAttack == 0)
{
while (buttonPushed == NO)
{
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(timerCallback) userInfo:nil repeats:NO];
lowAttackBlock.userInteractionEnabled = YES;
lowAttackBlock.highlighted = YES;
}
}
if (whereAttack == 1)
{
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(timerCallback) userInfo:nil repeats:NO];
leftAttackBlock.userInteractionEnabled = YES;
leftAttackBlock.highlighted = YES;
}
if (whereAttack == 2)
{
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(timerCallback) userInfo:nil repeats:NO];
rightAttackBlock.userInteractionEnabled = YES;
rightAttackBlock.highlighted = YES;
}
if (whereAttack == 3)
{
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(timerCallback) userInfo:nil repeats:NO];
highAttackBlock.userInteractionEnabled = YES;
highAttackBlock.highlighted = YES;
}
if (myCharacter.block != whereAttack)
{
myCharacter.health -= 10;
[yourHealth setText:[[NSString alloc] initWithFormat:@"%d",myCharacter.health]];
}
}
}
}
+1學習編程。 – 2011-12-22 15:43:30