對不起,如果問題不明確,英語不是我的主要語言,所以我不知道如何撰寫它。我的老師做了一個練習來計算誰會在決鬥中贏得他們的健康和攻擊。我想擴大一點,並增加護甲,關鍵機率和關鍵傷害作爲額外的統計數據,現在我試圖弄清楚如何在傷害中應用一個關鍵的機會。這是我到目前爲止的地方。如何計算應用獎勵的機率(即暴擊機率)?
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int HP;
int damage;
int armor;
float crit_damage;
float crit_chance;
} atributes;
//how to implement crit_chance?
//using a function?
//divide 100 for the crit_chance
//Ex: crit_chance = 25 ; 100/25 = 4
//generate a random number between 1 and 4
//if the number is 4 the crit_chance is sucessfull
//if not then the crit_chance fails
//aply then the result of the funcion to character[i].crit_damage
int main() {
int i, rounds = 0;
atributes character[2];
for(i = 0; i < 2; i++) {
printf("\tCharacter %d atributes\n", i+1);
printf(" Damage = ");
scanf("%d", &character[i].HP);
printf(" HP = ");
scanf("%d", &character[i].damage);
printf(" Armor = ");
scanf("%d", &character[i].armor);
printf(" Crit Damage = ");
scanf("%f", &character[i].crit_damage);
printf(" Crit Chance = ");
scanf("%f", &character[i].crit_chance);
printf("\n");
}
while ((character[0].HP > 0) || (character[1].HP > 0)) {
character[0].HP -= (character[1].damage * (character[1].crit_damage) - character[0].armor * 2);
character[1].HP -= (character[0].damage * (character[0].crit_damage) - character[1].armor * 2);
rounds++;
};
if (character[0].HP > character[1].HP) printf("\tCharacter 1 won after %d rounds!", rounds);
else if (character[0].HP < character[1].HP) printf("\tCharacter 2 won after %d rounds!", rounds);
else printf("\tThe duel ended in a tie after %d rounds", rounds);
return 0;
}
你需要更具體。 – Martin
你應該使用暴擊機率百分比來決定何時發生。在例子中:滾動一個0到100之間的隨機數,如果它小於你的暴擊機率造成暴擊傷害。如果沒有造成正常傷害。我很抱歉,我不能爲你編碼,但如果你需要更多的細節,當我回去工作時,我可以提供幫助 – koksalb
我不確定你的問題/問題是什麼,但這可能有所幫助:https:// www .tutorialspoint.com/c_standard_library/c_function_rand.htm - 我認爲你**將不得不使用此功能 – nounoursnoir