Making a crit strike?

so i have my program:

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
void FightStart()
{
#ifndef __combat_test__HuF__
#define __combat_test__HuF__

#include <iostream>
#include <cmath>
using namespace std;
class HuF
{
public:
    //all you and enemy fighter classes with stats
    
    // Human -> All Fighter Classes stats
    int yhp,ymp,ypatk,ypdef,yratk,yrdef,ymatk,ymdef,ylvl,ydb,yacc,ycr,yas;
    int ehp,emp,epatk,epdef,eratk,erdef,ematk,emdef,elvl,edb,eacc,ecr,eas;
    int epdamt,ypdamb,epdamb,ypdamt;
    
    double HumanFG[10][12];
    int HumanFS[12];
    
    double constant;
    
    HuF()
    {
    constexpr const static double dHumanFG[10][12] =
         //HP   MP     PA   MA   RA   PD    MD    RD    DB    ACC    CR     AS
    {   {.0701,.05997,.105,.092,.095,.061,.0590,.0490,.0571,.05107,.04512,.0177}, //F 0
        {.0741,.06021,.110,.094,.096,.075,.0670,.0540,.0602,.05137,.04551,.0175}, //SS 1
        {.0821,.06532,.125,.095,.097,.094,.0820,.0730,.0751,.05219,.04621,.0218}, //P 2
        {.0831,.06604,.120,.082,.093,.101,.0935,.0805,.0761,.05155,.04561,.0182}, //W 3
        {.0732,.06010,.124,.092,.095,.064,.0620,.0520,.0582,.05313,.05132,.0193}, //DW 4
        {.0781,.07204,.132,.093,.095,.072,.0680,.0550,.0601,.05352,.05324,.0224}, //GU 5
        {.0775,.06891,.141,.093,.095,.068,.0661,.0545,.0631,.05521,.05435,.0241}, //GL 6
        {.0751,.06013,.127,.093,.098,.067,.0611,.0621,.0573,.05120,.04822,.0179}, //2H 7
        {.0781,.06061,.131,.094,.098,.071,.0632,.0630,.0577,.05133,.05102,.0187}, //D 8
        {.0773,.06121,.137,.095,.099,.067,.0622,.0613,.0575,.05127,.05210,.0192}}; //R 9
    
    constexpr const static double dAndroidFG[10][12] =
          //HP   MP     PA  MA   RA    PD   MD    RD    DB    ACC    CR     AS
    {   {.0708,.05231,.109,.075,.101,.068,.0542,.0512,.0511,.04897,.04492,.0156}, //F 0
        {.0753,.05801,.131,.076,.104,.079,.0631,.0552,.0572,.04882,.04494,.0155}, //SS 1
        {.0842,.06212,.137,.077,.105,.102,.0772,.0753,.0710,.04971,.04590,.0192}, //P 2
        {.0863,.06311,.127,.071,.102,.109,.0851,.0813,.0701,.04885,.04483,.0163}, //W 3
        {.0754,.05819,.131,.075,.101,.073,.0582,.0540,.0532,.05029,.04845,.0173}, //DW 4
        {.0790,.07034,.141,.076,.101,.081,.0601,.0572,.0563,.05032,.05014,.0204}, //GU 5
        {.0781,.06621,.153,.078,.101,.075,.0583,.0563,.0591,.05213,.05103,.0221}, //GL 6
        {.0762,.05831,.132,.078,.108,.074,.0533,.0641,.0540,.04829,.04535,.0159}, //2H 7
        {.0793,.05864,.143,.079,.108,.079,.0545,.0652,.0552,.04838,.04830,.0167}, //D 8
        {.0783,.05913,.142,.079,.109,.077,.0538,.0632,.0561,.04835,.04939,.0172}}; //R 9
        
        
    constexpr const static int dHumanFS[12] =
    {137,58,6,4,5,72,45,66,19,25,12,2};
    
    constexpr const static int dAndroidFS[12] =
    {183,47,8,3,7,81,37,73,16,23,10,2};
    
    for(int i=0;i<10;++i)
    {
        for(int j=0;j<12;++j)
            HumanFG[i][j] = dHumanFG[i][j];
    }
    for(int i=0;i<12;++i)
        HumanFS[i] = dHumanFS[i];
    }
    
    void HuFS()
    {
        int *player[] = {&yhp,&ymp,&ypatk,&ymatk,&yratk,&ypdef,&ymdef,&yrdef,&ydb,&yacc,&ycr,&yas};
        std::cout << "what is your level?: ";
        std::cin >> ylvl;
        for(int i=0;i<12;++i)
        {
            constant = (1+HumanFG[0][i]);
            *player[i] = ((double)pow(constant, ylvl)) * HumanFS[i];
            cout<<*player[i]<<'\n';//Printing
        }
    }
    
    void EHuF()
    {
        int *enemy[] = {&ehp,&emp,&epatk,&ematk,&eratk,&epdef,&emdef,&erdef,&edb,&eacc,&ecr,&eas};
        std::cout << "what is your enemies level?: ";
        std::cin >> elvl;
        for(int i=0;i<12;++i)
        {
            constant = (1+HumanFG[0][i]);
            *enemy[i] = ((double)pow(constant, elvl))  * HumanFS[i];
            cout<<*enemy[i]<<'\n';//Printing
        }
    }

        ypdamt = ypatk;
        ypdamb = ypdef;
        epdamt = epatk;
        epdamb = epdef;
        int ypdamf = (ypdamt*70)/ypdamb;
        int epdamf = (epdamt*70)/epdamb;
        int yHpNew = yhp;
        int eHpNew = ehp;
        
        while (yhp >= 0 && ehp >= 0)
    {
        cout << "you hit your enemy for " << ypdamf << " damage." << endl;
            eHpNew -= ypdamf;
        cout << "your enemy now has " << eHpNew << " HP left" <<endl;
        if (eHpNew <= 0)
        {
            cout << "you have slain your enemy." << endl;
            break;
        }
        else
        {
    
        
        cout << "your enemy hit you for " << epdamf << " damage." << endl;
            yHpNew -= epdamf;
            cout << "you now have " << yHpNew << " HP left" << endl;
        if (yHpNew <= 0)
        {
            cout << "you are dead." << endl;
            break;
        }
        else
        {
        
        }
        }
    }
}


this does exactly what i wanted, it creates a standard fight program where i hit and enemy loses health then enemy hits and i lose health then first player to 0 health, it displays either "you are dead." or "you have slain your enemy."

my thoughts.

crit rate was a stat calculated in one of these voids. i was thinking of replacing 70 with a random number generator with ranges of 70-a, a depends on your crit rate.

and if (b < a) //b would be about 10 less than a maybe. so basically what i want to say here is there is a range where the player makes a critical strike and its 10 less than a.
{
cout << "you hit a critical strike" <<endl;
}
Here is an example:

1
2
3
4
5
6
7
8
9
10
#include <random>

random_device random;
int critRate = 50;


int main()
{
    random() % 100 - critRate;//So if you have crit rate of 50, it will be from 0-50
}
Last edited on
1
2
3
4
5
6
7
8
9
10
#include <random>

random_device random;
int critRate = 50;


int main()
{
    random() % 100 - critRate;//So if you have crit rate of 50, it will be from 0-50
}


so could i put random() % 100 - critRate + 70? to make it from 70-120?
My mistake, it would actually be random() % (critRate+70) If you did that it would be from 0-120. I dont know how to make it start from a value higher than 0. Just make sure you bracket the terms after the % modulus sign
Last edited on
okay. thanks.
I suggest to not use random_device before checking it entropy().

For some implementation it gives same sequence of number each run.
For others it can quicly exhaust sources of entropy and start to slow down whole OS. On linux implementations where dev/random is used it will cause a system-wide random device lock until entropy will be replenished.

Because of that random_device should only be used to get a seed sequence for normal PRNG and only if its entropy is larger than 0. Otherwise other sources of entropy should be considered, most common of which is time(nullptr)
Topic archived. No new replies allowed.