Text-Adventure RPG

Ok, I've been trying to create a RPG, I have everything figured out except for the fact I want to include items that can be equipped. I am at a loss on how to incorporate things i've learned to make this happen.

Is there any planning strategies/small scale things I can try to do to help me finish my project?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdlib>
#include <iostream>
#include <map>
#include "class_game_board.h"
#include "class_item.h"
#include "class_player.h"

int main()
{
	
    system("PAUSE");
    return EXIT_SUCCESS;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include "class_item.h" 

class_item::class_item(std::string setName, int setDamage, int setArmor)
{
                                   itemName = setName;
                                   weaponDamage = setDamage;
                                   armor = setArmor;
}

std::string class_item::getName()
{
            return itemName;
}

int class_item::getDamage()
{
    return weaponDamage;
}

int class_item::getArmor()
{
    return armor;
}


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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <vector>
#include <map>
#include "class_item.h"
#include "class_player.h"

	enum class EQUIPMENT
	{
		rustySword,
		crackedShield,
		rustyAxe,
	};
	
	const std::map<EQUIPMENT, class_item> loot = 
	{
    	{ EQUIPMENT::rustySword, {"Rusty Sword", 2, 2} },
    	{ EQUIPMENT::crackedShield, {"Cracked Shield", 0, 5} },
    	{ EQUIPMENT::rustyAxe, {"Rusty Axe", 4, 0} },
	};
	



class_player::class_player()
{
                            baseAttack = 2;
                            health = 10;
                            experience = 0;
                            weaponEquipped = "Fists";
                            weaponSlot = false;

}

void class_player::displayInventory()
{
     if ( inventory.empty() )
     {
          std::cout << "You have nothing in your inventory." << std::endl;
     }
     else
     {
         std::cout << "You have " << inventory.size() << " items in your inventory." << std::endl;
         
         for ( int x = 0; x < inventory.size(); x++ )
         {
             std::cout << inventory[x].getName();
             if ( inventory[x].getName() == weaponEquipped )
             {
                  std::cout << "    [Equipped]" << std::endl;
             }
             else
             {
                 std::cout << std::endl;
             }
         }
     }
}

void class_player::displayHUD()
{
     std::cout << "Attack " << getAttack() << " | Health " << getHealth() << std::endl;
}

int class_player::getAttack()
{
    return baseAttack + weaponAttack;
}

int class_player::getHealth()
{
    return health;
}

bool class_player::isWeaponSlotAvailable()
{
     if ( weaponSlot )
     {
          return false;
     }
     else
     {
         return true;
     }
}

void class_player::addItem(const class_item& item)
{
     inventory.push_back(item);
}

void class_player::removeItem(const std::string item)
{
     for ( int x = 0; x < inventory.size(); x++ )
     {
         if ( inventory[x].getName() == item )
         {
              inventory.erase(inventory.begin() + x);
         }
     }     
}

void class_player::equipItem(const std::string item)
{
	for ( int x = 0; x < inventory.size(); x++ )
	{
		if (weaponSlot)
		{
			weaponSlot = false;
			for ( int x = 0; x < inventory.size(); x++ )
			{
				if ( inventory[x].getName() == weaponEquipped )
				{
					weaponAttack = weaponAttack - inventory[x].getDamage();
					weaponEquipped = "Fists";
				}
			
		}
		if (inventory[x].getName() == item)
		{
			
			weaponAttack = weaponAttack + inventory[x].getDamage();
		}
		
		}

	}
}


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
#include <iostream>
#include <fstream>
#include "class_game_board.h" 



class_game_board::class_game_board()
{
            std::ifstream load_game_board("Dungeon/Dungeon-Map.txt");
            if ( load_game_board.fail() )
            {
                 std::cout << "An error occured while loading the map." << std::endl;
            }
            else
            {
                for ( int x = 0; x < height; x++ )
                {
                    for ( int y = 0; y < width; y++ )
                    {
                        load_game_board >> board[x][y];
                    }
                }
                load_game_board.close();
            }
            xCoord = 1;
            yCoord = 1;
            updateCurrentLocation();                                                               
}

void class_game_board::updateCurrentLocation()
{
     currentLocation = board[xCoord][yCoord];
}

void class_game_board::updateLastLocation()
{
     lastLocation = currentLocation;
}

std::string class_game_board::getCurrentLocation()
{
     return currentLocation;
}

std::string class_game_board::getLastLocation()
{
     return lastLocation;
}

void class_game_board::moveNorth()
{
     updateLastLocation();
     xCoord--;
     updateCurrentLocation();
}

void class_game_board::moveSouth()
{
     updateLastLocation();
     xCoord++;
     updateCurrentLocation();
}

void class_game_board::moveEast()
{
     updateLastLocation();
     yCoord++;
     updateCurrentLocation();
}

void class_game_board::moveWest()
{
     updateLastLocation();
     yCoord--;
     updateCurrentLocation();
}

Last edited on
Topic archived. No new replies allowed.