본문 바로가기
프로그래밍/C 언어(코딩)

C언어] RPG게임만들기-2 (몬스터 설정)

by 곰나나 2024. 1. 1.

[RPG게임만들기]

RPG게임만들기 몬스터 설정

2. 적(몬스터) 정보 추가(등급,HP, MP, 물리공격력,마법공격력, 힘, 민첩, 행운, 마력, 방어력, 저항력, 스피드,크리티컬)
등급 = 1
물리 공격력 = (힘*1)/10.0
마법 공격력 = (마력*0.2)/8.0
힘 = (등급*5)
민첩 = (등급*5)
행운 = (등급*5)
마력 = (등급*2)
방어력 = (등급*3)+(힘/15)
저항력 = (등급*1)+(마력/20)
스피드 = 1*(민첩/5)
크리티컬 = 0*(행운/2)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
 
//& 적(몬스터) 구조체 정의
typedef struct {
    //& 멤버 변수 (몬스터 정보 설정)
    int grade;
    int HP;
    int MP;
    double physicalAttack;
    double magicalAttack;
    int strength;
    int agility;
    int luck;
    int magicPower;
    double defense;
    double resistance;
    double speed;
    double critical;
} Monster;
 
 
//& 속성 계산 함수
void calculateMonsterAttributes(Monster* monster)
{
    // 물리 공격력 = (힘 * 1) / 10.0
    monster->physicalAttack = (monster->strength * 1/ 10.0;
 
    // 마법 공격력 = (마력 * 0.2) / 8.0
    monster->magicalAttack = (monster->magicPower * 0.2/ 8.0;
 
    // 방어력 = (등급 * 3) + (힘 / 15)
    monster->defense = (monster->grade * 3+ (monster->strength / 15.0);
 
    // 저항력 = (등급 * 1) + (마력 / 20)
    monster->resistance = (monster->grade * 1+ (monster->magicPower / 20.0);
 
    // 스피드 = 1 * (민첩 / 5)
    monster->speed = 1 * (monster->agility / 5.0);
 
    // 크리티컬 = 0 * (행운 / 2)
    monster->critical = 0 * (monster->luck / 2.0);
}
 
int main() 
{
    //& 적(몬스터) 구조체 생성
    Monster monster;
 
    //& 기본 속성 초기화
    monster.grade = 1;
    monster.HP = 80;  // 적(몬스터)의 초기 HP
    monster.MP = 40;  // 적(몬스터)의 초기 MP
    monster.strength = monster.grade * 5;
    monster.agility = monster.grade * 5;
    monster.luck = monster.grade * 5;
    monster.magicPower = monster.grade * 2;
    //& 속성 계산
    calculateMonsterAttributes(&monster);
 
    //& 속성 출력
    printf("[몬스터 능력치 정보] \n");
    printf("물리 공격력: %lf\n", monster.physicalAttack);
    printf("마법 공격력: %lf\n", monster.magicalAttack);
    printf("방어력: %lf\n", monster.defense);
    printf("저항력: %lf\n", monster.resistance);
    printf("스피드: %lf\n", monster.speed);
    printf("크리티컬: %lf\n", monster.critical);
 
    return 0;
}//main
cs

728x90