fighting game

Hey so im creating a fighting game in c++ im pretty knew to the program and only know the basics, heres the code so far:

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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
if(menu==3){
		system("cls");
		cout << "choose a lvl of difficulty:\n1.easy\n2.medium\n3.hard\n";

		cin >> difficulty;
		if(difficulty == 1){
			comp.dex = 5;
			comp.str = 5;
			comp.health = 125;
			comp.crit = comp.dex*3;
			comp.damage = comp.str;
		}
		if(difficulty == 2){
			comp.dex = 5;
			comp.str = 10;
			comp.health = 125;
			comp.crit = comp.dex*3;
			comp.damage = comp.str;
		}
		if(difficulty == 3){
			comp.dex = 5;
			comp.str = 10;
			comp.health = 150;
			comp.crit = comp.dex*3;
			comp.damage = comp.str;
		}
		comp.critdmg = comp.damage*2;
		system("cls");
		cout << "are you ready to enter the arena?\n1.yes\n2.no\n";
		cin >> rcheck;
		if(rcheck == 1){
			//fighting system

srand( time(NULL) );

randname = rand() % 10 + 1;
if(randname==1){
comp.name = "petius maximus";
}
if(randname==2){
comp.name = "erikus masius";
}
if(randname==3){
comp.name = "marcus mixus";
}
if(randname==4){
comp.name = "adux laxus";
}
if(randname==5){
comp.name = "viktus mizus";
}
if(randname==6){
comp.name = "ebrius medius";
}
if(randname==7){
comp.name = "timus tuttilus";
}
if(randname==8){
comp.name = "josius haxus";
}
if(randname==9){
comp.name = "toxus loxus";
}
if(randname==10){
comp.name = "adoxus raxus";
}

cout << "                         " << player.name << " " << "please enter the arena!\n";
Sleep (2000);
cout << "                         " <<comp.name << " " << "please enter the arena!\n";
Sleep (2000);
system("cls");
cout << player.name << " " << "health: " << comp.health;   
cout << "                              " <<comp.name<< " " << "health: " << comp.health << "\n";
cout << "\n\n\n\n\n\n                               PREPARE TO FIGHT!\n";
cout << "\n\n\n\n\n\n                                       3\n";
Sleep (1000);
system("cls");
cout << player.name << " " << "health: " << comp.health;   
cout << "                              " <<comp.name<< " " << "health: " << comp.health << "\n";
cout << "\n\n\n\n\n\n                               PREPARE TO FIGHT!\n";
cout << "\n\n\n\n\n\n                                       2\n";
Sleep (1000);
system("cls");
cout << player.name << " " << "health: " << comp.health;    
cout << "                              " <<comp.name<< " " << "health: " << comp.health << "\n";
cout << "\n\n\n\n\n\n                               PREPARE TO FIGHT!\n";
cout << "\n\n\n\n\n\n                                       1\n";
Sleep (1000);
system("cls");
cout << player.name << " " << "health: " << comp.health;     
cout << "                              " <<comp.name<< " " << "health: " << comp.health << "\n";
cout << "\n\n\n\n\n\n                               PREPARE TO FIGHT!\n";
cout << "\n\n\n\n\n\n                                       go!\n";
Sleep (1000);
system("cls");

while(true){
turn++;
system("cls");
if(turn==1){
cout << player.name << " " << "health: " << comp.health;   
cout << "                              " <<comp.name<< " " << "health: " << comp.health << "\n";
cout << "                                  Press 1 to attack!\n";
cin >> turnpick;
if(turnpick ==1){
	srand( time(NULL) );
randc = rand() % 100 + 1;
if(player.crit > randc){
cout << "you make a CRITICAL STRIKE attack that deals " << player.critdmg << " " << "damage!\n";
comp.health = comp.health - player.critdmg;
}
if(comp.crit < randc){
	cout << "you make a normal strike attack that deals " << comp.damage << " " << "damage!\n";
player.health = player.health - comp.damage;
turn=0;
}

if(wield == "dagger"){
srand( time(NULL) );

randh = rand() % 100 + 1;

if(dubbelhit > randh){
player.damage = player.damage*2;
cout << "DUBBEL HIT\n";
    }
}

if(wield == "hammer"){
srand( time(NULL) );

rands = rand() % 100 + 1;
if(stun > rands){
stundur = 1;
    }

}
}

}
_getch();
if(turn==2){
	cout << player.name << " " << "health: " << comp.health;   
cout << "                              " <<comp.name<< " " << "health: " << comp.health << "\n";
	srand( time(NULL) );

randc = rand() % 100 + 1;
if(comp.crit > randc){
cout << comp.name <<  "make a CRITICAL STRIKE attack that deals " << comp.critdmg << " " << "damage!\n";
player.health = player.health - comp.critdmg;
turn=0;
}
if(comp.crit < randc){
	cout << comp.name <<  "make a normal strike attack that deals " << comp.damage << " " << "damage!\n";
player.health = player.health - comp.damage;
turn=0;
}
}
_getch();
if(player.health == 0){
cout << "you lost the fight you loose 5 gold.n";
gold = gold-5;
break;
}
if(comp.health == 0){

srand( time(NULL) );

plusgold = rand() % 10 + 5;

cout << "You have achived victory!\nyou gain " << plusgold << " " << "gold!\n";
gold = gold + plusgold;
player.health = hp;
break;
}
}
}
}

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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <iostream>
#include <conio.h>
#include <string>
#include <time.h>
#include <Windows.h>

using namespace std;

struct armors{
	int larmor;
	int chmail;
	int parmor;
}equip_a;

struct shields{
	int  lshield;
	int  wshield;
	int  ishield;
}equip_s;

struct weapons{
	string dagger;
	string bsword;
	string isword;
	string ssword;
	string axe;
	string hammer;
	string none;
}equip_w;


struct stats{
	string name;
	int dex;
	int str;
	int health;
	int crit;
	int block;
	int armor;
	int damage;
	int turn;
	int attack;
	int critdmg;
}player,comp;

int main()
{
	string wield;
	string equiped;
	string offhand;

	equip_w.dagger = "dagger";
	equip_w.bsword = "bsword";
	equip_w.isword = "isword";
	equip_w.ssword = "ssword";
	equip_w.axe = "axe";
	equip_w.hammer = "hammer";
	equip_w.none = "none";

	equiped = equip_w.none;

	int dubbelhit;
	int randh;
	int randc;
	int rands;
	int stundur;
	int stun;
	int effect;
	int pick;
	int turnpick;
	int answear;
	int gold=20;
	int price;
	int stat_pt;
	int put;
	int menu;
	int plusvw;
	int plusvs;
	int plusva;
	int plusvc;
	int randname;
	int ulti;
	int rcheck;
	int hp;
	int difficulty;
	int plusgold;
	int turn=0;
	string equiped_true;

	
	

	player.dex = 0;
	player.block = 0;
	player.crit = 0;
	player.str = 0;
	player.health = 100;
	player.armor = 0;

	stat_pt = 15;
		cout << "enter your name: ";
		cin >> player.name;
	while(stat_pt >= 0){
		
		
	
		system("cls");
	cout << "stat picking\npoints left: "<< stat_pt << endl;
	cout << "1.dex(more crit)   "<< player.dex <<"\n2.str(higher dmg)   "<< player.str <<"\n3.health(you know...)   "<< player.health << endl;
	cin >> put;
		if(put == 1){
			player.dex++;
			stat_pt--;
		}
		if(put == 2){
			player.str++;
			stat_pt--;
		}
		if(put == 3){
			player.health++;
			player.health++;
			player.health++;
			player.health++;
			player.health++;

			stat_pt--;
		}

		if(stat_pt == 0){
			break;
		}

		
	}


_getch();
system("cls");
cout << "dex :" << player.dex;
cout << "\n" << "str: "<< player.str;
cout << "\n" << "health: " << player.health;
cout << "\n";

_getch();

hp = player.health;
player.crit = player.dex*3;
player.damage = player.str;
player.critdmg = player.damage*2;



(i have only entered the part of the code with the fighting code and the variabels)

in btw i have not yet done the chest part and still have some modifiactions im working on for the shop.

the problem lies in the fighting part.
i think the code should see if i generate a crit or not and deal damage accordingly but the opponents health dont change also there is something laggy about the _getch(); thou i think that has more with my biggest problem to do:

the comp dont spawn any text i made a system that if turn == 1 the user attacks if turn == 2 the comp attacks, but it dosent seem like it registers or even gets to turn2

can you guys see any misstakes please help me i have been looking around for about 2 hours and im stuck

thanks in advance

//spinno

edit its fixed now if a mod could delete this thread it would be awsome

Last edited on
closed account (E60S216C)
The code compiled good, but you left out the closing bracket at the end of the function.

And I found it pretty good up to date. The stats part seemed cool.
Topic archived. No new replies allowed.