console game

I am currently making my first console game to challenge myself but I am getting stumped on a couple of things. Please ignore my empty voids as I want to attempt those before I ask for help on those. My first question is on lines 11-18, what I'm trying to do is get the current health and attack but if I use void and try to get the current that way instead of the return then on lines 81 and 82 I get errors (I'm not sure at the moment); I'm trying to get your current health/attack and print it on lines 81 and 82. Do I have to move the health and attack text box to game.update()? Since this is my first game is there any pointers to what I can improve on in my current code (besides the blank voids and unused voids at the moment), is there parts of code were I need to change/remove? Any criticism you have will help me out, so please tell me your thoughts.

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
#include <iostream>

using namespace std;

class character
{
	int health;
	int attack;
	public:
		void enemy(int,int);
		int player_health()
		{
			return 10;
		}
		int player_attack()
		{
			return 3;
		}
		void check_dead(int,int);
}character;

class game
{
	public:
		void begin();
		void win();
		void lose();
		void update();
		void draw();
}game;

void character::enemy(int,int)
{
	health = 15;
	attack = 2;
}

void character::check_dead(int,int)
{
	
}

void game::begin()
{
	game game;
	game.draw();
	character.player_health();
	character.player_attack();
}

void game::win()
{
	cout << "You won the game!" << endl;
}

void game::lose()
{
	cout << "You have lost the game." << endl;
}

void game::update()
{
	game game;
	game.draw();
}

void game::draw()
{
	cout << "---------------------------------------" << endl;
	cout << "| #                 # ################|" << endl;
	cout << "| #                 #                #|" << endl;
	cout << "| #############     # #              #|" << endl;
	cout << "|             #     # #              #|" << endl;
	cout << "| ########### #     # #              #|" << endl;
	cout << "|           # #     # #              #|" << endl;
	cout << "| #         # #     # ######## #######|" << endl;
	cout << "| #         # #     #        #       #|" << endl;
	cout << "| ########### # ##### #      #       #|" << endl;
	cout << "|                     ################|" << endl;
	cout << "---------------------------------------" << endl;
	cout << "|  Health: " << character.player_health() << "                         |" << endl;
	cout << "|  Attack: " << character.player_attack() << "                          |" << endl;
	cout << "---------------------------------------" << endl;
}

void dead()
{
	
}

int main ()
{
	string choice;
    cout << "Welcome to Command Line Game v0.0.1!" << endl;
	cout << "1.Play" << endl;
	cout << "2.About" << endl;
	cout << "3.Exit" << endl;
	cin >> choice;
	if (choice == "play")
	{
		game.begin();
	}
    return 0;
}
your character's name is identical as the character class, same as your game class

don't declare an instance of the class inside one of its functions unless it needs more than one instance.
Do you mean things like character.player_attack() and game.begin()? I tested my code last night and it did start and displayed the right things it was supposed to. I didn't think that declaring game as game and character as character would do anything but allow me to understand. I am still stumped on my original questions.
@feare56

After I added #include <string> after your other include, I was able to print out the map in the draw() function, along with the current Health (10), and Attack (3) values. Of course, the program then ends, as there is no inputs, etc., to make movements and such.
@whitenite1

Did you change the current health and attack functions or did you just add #include <string> ? I am able to print everything out without #include <string> . I haven't gotten that far into the game yet obviously, all that I was worried about last night was getting the display up and building the game without any errors and not worrying about the user input just yet.
<string> is not required unless you're using std::string .
@feare56

No, i didn't change anything else, just added the include. I'm using MS Visual C++ Express 2012, so needed the include. Not sure what compiler you have. Anyway, I was able to show the maze, with the health and attack variables sowing under it. I added in a character movement in my program. Right now, I'm not checking for walls, etc., but that will be next. As long as this isn't a school project, I'll be glad to help out, if you would like. Send me a PM, and we can collaborate on it.
Topic archived. No new replies allowed.