Dungeons & Dragons based Project

So for my final class project I decided I want to make a very basic combat simulation based VERY loosely on 5e D&D. However I'm running into issues in my brain regarding logic and how to actually code this correctly.

What I have so far is this:

#include <iostream>

using namespace std;

int p_hp, p_ac, p_profmod, p_strmod;

struct goblin
{
int gob_hp = 21, gob_ac = 12, gob_strmod = 3;
};

struct soldier
{
int sol_hp = 40, sol_ac = 15, sol_strmod = 4;
};

struct dragon
{
int d_hp = 100, d_ac = 18, d_strmod = 5;
};

int main()
{
cout << "Welcome to the D&D simple combat processor!" << endl;
cout << "To begin, please enter the following info about your character." << endl;
player_info;

}

void player_info
{
//Character HP Entry and Validation
cout << "Character HP: ";
cin >> p_hp >> endl;
while(p_hp < 1)
{
cout << "Sorry, that is an invalid entry. Try again." << endl;
cin >> p_hp >> endl;
}
//Character AC Entry and Validation
cout << "Character AC(Armor Class): ";
cin >> p_ac >> endl;
while(p_ac < 10)
{
cout << "Sorry, that is an invalid entry. Try again." << endl;
cin >> p_ac >> endl;
}
cout << "Character Proficiency Modifier: " << endl;
cin >> p_profmod >> endl;
while(p_profmod < 1 || p_profmod > 10)
{
cout << "Sorry, that is an invalid entry. Try again." << endl;
cin >> p_profmod >> endl;
}

}



************************************

Essentially what I need to do after speaking with my professor is this:

-Take input from the user regarding their character.
-Store the info on a file.
-Have 3 Structures, each one containing the data of a different enemy.
-Make a menu asking which enemy they user wants to fight.
-Running a function that simulates combat between the player character and the chosen enemy.




Last edited on
Wrote this quickly hopefully it helps you. Good night :)

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
#include <iostream>
// author: mr impact
// for: cplusplus.com
struct Entity
{
	int hp;
	int ac;
	int strmod;
	std::string name;

	Entity()
		: hp(1), ac(1), strmod(1), name("unknown-entity")
	{
		//
	}
	

	inline void setName(std::string newName) { name = newName; }
	int getIntegerInput();
};

int Entity::getIntegerInput()
{
	int inputValue = 1;

	do
	{

		std::cin >> inputValue;

	} while (inputValue <= 0);

	return inputValue;
}

struct Enemy : public Entity
{

};

struct Player : public Entity
{
	int profmod;

	Player()
		: profmod(1)
	{

	}
	void create();
};

void Player::create()
{
	//Character HP Entry and Validation
	std::cout << "Set " << name.c_str() << "'s HP: ";
	hp = getIntegerInput();

	//Character AC Entry and Validation
	std::cout << "Set " << name.c_str() << "'s Armor Class: ";
	ac = getIntegerInput();

	//Character Proficiency Modifier
	std::cout << "Set " << name.c_str() << "'s Proficiency Modifier: ";
	profmod = getIntegerInput();
}

int main()
{
	Enemy dragon;
	Enemy goblin;
	Player soldier;

	std::cout << "Welcome to the D&D simple combat processor!" << std::endl;
	std::cout << "To begin, please enter the following info about your character." << std::endl;
	soldier.setName("soldier");
	soldier.create();

	return 0;
}
Topic archived. No new replies allowed.