This is for a personal hobby project of mine, im working on a console based choose your own adventure with free movement between areas using grid coordinats IE [0,0,0] and im working on static monster encounters and the combat portion of it. I would like to do random dice rolls with dmg based on atk/defense of player and monster as well as hitrate, ive already got some starter code i worked on but there is still a fair bit im not able to grasp.
Several of my questions:
Can i use nested if else statements to continue the fight step by step until the monster or players hp is <= 0 and how do i return the value of the dmg done to a players global variable. I would like to pre-set the stats for each individual monster possible have a Combat() function which then loads a Monster function IE Monster001() or Zombie() Skeleton() etc.
How do i calaculate in hit %. I'm using rand() for the dice rolls but how to incorporate % chance the hit is successful.
How do i fetch the value of total dmg from each random dice to subtract it from player / monster hp.
Then after how do i assign pre-decided exp per monster to the player in the event of victory or return the player to a death message if he fails. I'm using nested switchs for the accual menu options in each area and using goto only for Actions and Error/default for the switch. As well as each area has an AREA### goto for certain moves between areas that are oposite the flow of the code.
At some point in the future id also like to assign equipment to an inventory system using strings and and equip feature which adds stats to players stats pre-combat as well.
Here is my current dmg algorith code.
Code:#include "stdafx.h" #include <iostream> #include <cstdlib> #include <time.h> using namespace std; /* These constants define our upper and our lower bounds. */ 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; }



LinkBack URL
About LinkBacks


