프로그래밍/C,C++
예제) 크리티컬 확률과 몬스터 사냥하기 feat 줄 정렬
gameObject
2023. 6. 2. 16:05
728x90
반응형
느낀점
줄 정렬이라는것을 처음 신경써서 해보았다.
아직 주석이라는 부분을 신경쓰지 못해서 아쉬운데 다음 예제부터는 주석도 신경쓰고자 한다.
/*
지난번에 만들었던 크리티컬 데미지 주는 함수 수정해서 60% 확률로
크리티컬 데미지 주는 함수로 만들기
- Loop 사용해서 종료 입력 전까지 반복
- 플레이어가 어떤 상태인지 출력해서 보여줄 것(왜 크리티컬인지, 아닌지 알 수 있어야 함)
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h> // 윈도우에서는 <windows.h>이다.
int main(){
int criticalPercent;
int damage, cridamage;
int monster = 100;
srand(time(NULL));
printf("[몬스터 등장]\n");
while(monster > 0 ){
criticalPercent = (rand()%100)+1;
printf("데미지 입력 해주세요: ");
scanf("%d",&damage);
if(criticalPercent <= 60){
cridamage = damage * 1.5;
monster = monster - cridamage;
printf("크리티컬이 발생했습니다. %d !!!\n",cridamage);
printf("%d 가 나왔습니다. (0~60 숫자 발생시 크리티컬)\n",criticalPercent);
printf("남은 몬스터의 체력은. %d입니다.\n",monster);
printf("========================================\n\n\n");
continue;
}
printf("적중했습니다.\n");
printf("%d가 나와서 크리티컬이 안나왔습니다. (0~60 숫자 발생시 크리티컬)\n",criticalPercent);
monster = monster - damage;
printf("남은 몬스터의 체력은. %d입니다.\n",monster);
printf("========================================\n\n\n");
}
printf("몬스터가 죽었습니다.");
}
728x90
반응형