2014-02-20 27 views
0

我正在創建一個pong遊戲,並試圖在比分的最後一位以5結尾時結束遊戲,但我不確定如何完成此操作。這是我的代碼到目前爲止:測試以GML結尾的數字是什麼數字

if score >= 50 {show_message('ObiWan Wins'); game_end();} 
if score <= 50 && score(ENDS IN DIGIT 5 NOT SURE WHAT CODE TO PLACE HERE) {show_message('Vader Wins'); game_end();} 

回答

1

對於「重複」你有模操作。你真正需要的是在要執行的代碼:

score = 5 
score = 15 
score = 25 
.... 

因此,在「10」的時期大小,當你做模運算以「10」作爲第二個參數你得到這樣一個時期。

0 % 10 = 0 
1 % 10 = 1 
2 % 10 = 2 
3 % 10 = 3 
4 % 10 = 4 
5 % 10 = 5 
6 % 10 = 6 
7 % 10 = 7 
8 % 10 = 8 
9 % 10 = 9 
10 % 10 = 0 
11 % 10 = 1 
12 % 10 = 2 
... 

從這應該是顯而易見的。

if score >= 50 { 
    show_message('ObiWan Wins'); 
    game_end(); 
} else if (score % 10 = 5) { 
    show_message('Vader Wins'); 
    game_end(); 
} 

正如我改變了側節點if score <= 50else if - 同時使在這種情況下沒有區別,當你們兩個選項之間做出選擇,你不希望他們兩個在同一時間

1

執行另一種方法:

if score >= 50 { 
    show_message('ObiWan Wins'); 
    game_end(); 
} else if (score mod 5 = 0) && (score mod 10 != 0) { 
    show_message('Vader Wins'); 
    game_end(); 
} 
相關問題