Where do I include Pointers in a Card Game?

Hello, this is my first post here, so if there's anything that have to be change about me or the post, feel free to point that out.

Anyway, I'm a student that in is Game Development, just started learning C++ and was given an assignment to create a RPG Card Game. In this RPG Card Game, we are required to include the use of Pointers.
Here's the a short note on my assignment notes that states it:

3) Pointers
a. Create instances of objects with keyword new
b. Use delete keyword to free memory
c. Appropriate use of shallow and/or deep copies
d. Create virtual function(s)
e. Use of polymorphism

Here's my idea of my game:

On start:
[x] prompt user whether he wants to play or need help
[x] choosing help will show help section
[x] choosing play will prompt user what game mode does he wants to play

Upon choosing quick match:
[x] prompts user to choose a character to play
[] shows user his card (draw out) and stats are on his card
[] player get to choose a starting powerup
[] randomize a card and powerup for opponent
[] round starts with class with higher speed
[] randomly draws a powerup for each side at the start of each wave.
[] player can choose to attack, defend or use powerup each turn

I roughly understand the logic of pointers but I do not know which part of my Card Game that I need to implement pointers. Can anyone point out to me where in my code I can use pointers?

Here's my code so far:

characterType.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>

using namespace std;

class characterType
{
public:
	void printStats();
	//Print the stats of a card

	characterType(int charClassIndex = 1);
	//Set the value of a card

private:
	int charClassIndex;
	int hp, str, def, spd;

	string charClass;
};


characterTypeImp.cpp
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
#include "characterType.h"
#include <iostream>

void characterType::printStats()
{
	cout << " Character: " << charClass << endl;
	cout << " HP: " << hp << endl;
	cout << " Strength: " << str << endl;
	cout << " Defense: " << def << endl;
	cout << " Speed: " << spd << endl;
}

characterType::characterType(int charClassIndex)
{
	switch(charClassIndex)
	{
	case 1:
		charClass = "Char A";
		hp = 20;
		str = 15;
		def = 13;
		spd = 10;
		break;
	case 2:
		charClass = "Char B";
		hp = 15;
		str = 5;
		def = 7;
		spd = 12;
		break;
	case 3:
		charClass = "Char C";
		hp = 15;
		str = 10;
		def = 10;
		spd = 15;
		break;
	default:
		break;
	}
}


gameMain.cpp
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
#include "characterType.h"
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

void main()
{
	int classIndex = -1;
	string choice1, choice2;

	//Welcome Message
	cout << "   ___             _     _      _             _                  ___ ___  ___  " << endl;
	cout << "  / __|__ _ _ _ __| |   /_\\  __| |_ _____ _ _| |_ _  _ _ _ ___  | _ \\ _ \\/ __|" << endl;
	cout << " | (__/ _` | '_/ _` |  / _ \\/ _` \\ V / -_) ' \\  _| || | '_/ -_) |   /  _/ (_ |" << endl;
	cout << "  \\___\\__,_|_| \\__,_| /_/ \\_\\__,_|\\_/\\___|_||_\\__|\\_,_|_| \\___| |_|_\\_|  \\___|" << endl;
	cout << "\t\tCredits to: http://patorjk.com/ for this art." << endl;
	cout << endl;
	cout << "\t\t\tWelcome to Card Adventure RPG!" << endl;
	cout << endl;

	//Asking play to choose an option, re-ask if choice isn't "play" or "help"
	do 
	{
		//Display <HELP> section when player chose "help"
		if ( choice1 == "help" )
		{
			cout << endl;

			//Showing player's choice
			cout << " !! \"help\" chosen." << endl;

			//Start of <HELP> section
			cout << " <HELP>" << endl;
			cout << " When you are given a choice like this:" << endl;
			cout << " CHOICE EXAMPLE: \"Choose one >> one/two\"" << endl;
			cout << " Type in the one of the choice word after the \">>\"" << endl;
			cout << " CORRECT EXAMPLE: \"one\" or \"two\"" << endl;
			cout << " INCORRECT EXAMPLE: \"three\" or \"ONE\"" << endl;
			cout << endl;
		}

		//Prompt player to choose an option and update to variable; choice1
		cout << " Please choose and type in one of the options >> play/help : ";
		cin >> choice1;

		//Display ERROR INPUT message when input is invalid
		if ( choice1 != "play" && choice1 != "help" )
		{
			cout << endl;
			cout << " !! ERROR INPUT" << endl;
		}
	} while ( choice1 != "play" );
	cout << endl;

	//Asking player to choose a game mode if "play" is chosen previously, re-ask if choice isn't "story" or "multiplayer"
	if ( choice1 == "play" )
	{
		//Showing player's choice
		cout << " !! \"play\" chosen." << endl;

		do
		{
			//Prompt player to choose an option and update to variable; choice2
			cout << " Please type in one of the modes to play >> quickmatch/multiplayer : ";
			cin >> choice2;

			//Display ERROR INPUT message when input is invalid
			if (choice2 != "quickmatch" && choice1 != "multiplayer")
			{
				cout << endl;
				cout << " !! ERROR INPUT" << endl;
			}
		} while( choice2 != "quickmatch" && choice2 != "multiplayer" );
	}
	cout << endl;


	if ( choice2 == "quickmatch" )
	{
		//Showing player's choice
		cout << " !! \"quickmatch\" chosen." << endl;

		do
		{
			if (classIndex == 0)
			{
				cout << endl;
				cout << " !! '0' chosen." << endl;
				cout << " <CLASS INFO>" << endl;
				cout << endl;
			}
			cout << " Pick a class to play as (type in '0' for classes information) >> 0/1/2/3 : ";
			cin >> classIndex;
		} while( classIndex != 1 && classIndex != 2 && classIndex != 3 );
	}
	cout << endl;

	characterType yourCharacter(classIndex);
	yourCharacter.printStats();
}


Also, if you spot any redundancy in my coding, free feel to point that out as well. I need as much help as much as you can give. Thanks.

PS: I don't need you to do my work, I just want to know which part of my code can pointers be used and how do I start off.
Last edited on
in gameMain.cpp lines 80,81,97 are redundant because of lines 24,25,54

as for pointers nothing really caught my eyes that would have made since to do over what you already have.
though if you end up with a function with an argument like (char arg[]) you can change it to (char *arg)

not sure if this even counts but in gameMain.cpp line 8 could be: int main(int argc,char **argv) doing this will also allow you to take command line arguments.
Last edited on
thanks for the reply, noted.
your directions tell you how to use pointers. you'll be using polymorphism and allocating dynamic memory, that's your use for pointers right there.
Topic archived. No new replies allowed.