Need assistance with combat calculations.

I'm pretty new so now im getting to the really juicy stuff. I need to create a combat system for a game i'm programing. I want to do random dice rolls and calculate in a few different things. They would keep rolling until player or monsters HP is less then or = to 0.

Player HP
Player Atk (ATK = Max DMG)
PlayerHitRate (% chance to hit)
Player Defense ( minus defense from max dmg)

So it would be like example

Character has 25HP 10 attack 75% hitrate 5 defense...

Monster has 15HP 8 attack 50% hitrate 3 defense...

Monster attacks player 2-8 dmg 2-8 minus defense so 2-3 dmg with a chance to hit of 50%.

here is some code i found on tutorial site for random dice rolls. anyone know how to show me how to put the above into a function?


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
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;
/*
These constants define our upper
and our lower bounds. The random numbers
will always be between 1 and 6, inclusive.
*/
int Test = 0;
const int LOW = 1;
const int HIGH = 6;
int main()
{
/*
Variables to hold random values
for the first and the second die on
each roll.
*/
int first_die, sec_die;
/*
Declare variable to hold seconds on clock.
*/
time_t seconds;
/*
Get value from system clock and
place in seconds variable.
*/
time(&seconds);
/*
Convert seconds to a unsigned
integer.
*/
srand((unsigned int) seconds);
/*
Get first and second random numbers.
*/
first_die = rand() % (HIGH - LOW + 1) + LOW;
sec_die = rand() % (HIGH - LOW + 1) + LOW;
/*
Output first roll results.
*/
cout<< "Your roll is (" << first_die << ", "
<< sec_die << "}" << endl << endl;
/*
Get two new random values.
*/
first_die = rand() % (HIGH - LOW + 1) + LOW;
sec_die = rand() % (HIGH - LOW + 1) + LOW;
/*
Output second roll results.
*/
cout<< "My roll is (" << first_die << ", "
<< sec_die << "}" << endl << endl;
cin >> Test; // Pause program to see output
return 0;
}
So far ive come up with this, if there is anyone that can help me build on this id appreciate it, for now im going to bed ive been at this all night xD but im making progress. Anyways hope to see some posts tomorrow. thanks again for everyones help!

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
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;
/*
These constants define our upper
and our lower bounds. The random numbers
will always be between 1 and 6, inclusive.
*/
int Test = 0;
int MonsterLevel = 1;
int MonsterHitPoints = 15;
int MonsterAttack = 8;
int MonsterDefense = 3;
int PlayerLevel = 1;
int PlayerHitPoints = 25;
int PlayerAttack = 10;
int PlayerDefense = 5;

int LowMonster = 2;
int HighMonster = MonsterAttack - PlayerDefense;
int LowPlayer = 2;
int HighPlayer = PlayerAttack - MonsterDefense;
int main()
{
/*
Variables to hold random values
for the first and the second die on
each roll.
*/
int first_die, sec_die;
/*
Declare variable to hold seconds on clock.
*/
time_t seconds;
/*
Get value from system clock and
place in seconds variable.
*/
time(&seconds);
/*
Convert seconds to a unsigned
integer.
*/
srand((unsigned int) seconds);
/*
Get first and second random numbers.
*/
if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
{
cout << "Monsters & Player Can Fight HP ok.\n";
first_die = rand() % (HighPlayer - LowPlayer + 1) + LowPlayer;
sec_die = rand() % (HighPlayer - LowPlayer +1) + LowPlayer;

cout<< "Players attack is (" << first_die << ", "
<< sec_die << "}" << endl << endl;

first_die = rand() % (HighMonster - LowMonster + 1) + LowMonster;
sec_die = rand() % (HighMonster - LowMonster + 1) + LowMonster;

cout<< "Monsters attack is (" << first_die << ", "
<< sec_die << "}" << endl << endl;

}
else if ( (MonsterHitPoints <= 0) && (PlayerHitPoints <= 0) );
{
cout << "Unable to fight! Player or Monster HP are 0.\n";
cin >> Test;
}
return 0;
}
Last edited on
Topic archived. No new replies allowed.