Meu primeiro jogo em c++

Jogos

Lógica de programação

C++

24/04/2020

Meu primeiro jogo em C++,tenho 18 aos comecei a estudar C++ em 2019,mais especificamente em janeiro,e para testar meus conhecimentos criei esse mini-game de combate em turnos em C++,espero que me avaliem!.


#include <iostream>
using namespace std;
#include <cstdlib>
using std::rand;
using std::srand;
using std::exit;
#include <ctime>
using std::time;
#include <iomanip>
using std::setw;

class Element {
public:
Element(int j1,int j2) {
Element1 = j1;
Element2 = j2;
DefineM1(j1);
DefineM2(j2);
DefineNameM1(j1);
DefineNameM2(j2);
}
void DefineNameM1 (int n) {
switch (n) {
case 1:
monster1 = "Killer";
break;
case 2:
monster1 = "Warrior";
break;
case 3:
monster1 = "Magic";
break;
case 4:
monster1 = "Defender";
break;
case 5:
monster1 = "Rogue";
break;
}
}
void DefineNameM2 (int n) {
switch (n) {
case 1:
monster2 = "Killer";
break;
case 2:
monster2 = "Warrior";
break;
case 3:
monster2 = "Magic";
break;
case 4:
monster2 = "Defender";
break;
case 5:
monster2 = "Rogue";
break;
}
}
void DefineM1(int m) {
switch(m) {
case 1:
vidam1 = 140,danom1 = 15,armaduram1 = 10;
hab1m1 = 25,hab2m1 = 20,ultm1 = 45;
break;
case 2:
vidam1 = 165,danom1 = 12,armaduram1 = 15;
hab1m1 = 18,hab2m1 = 6,ultm1 = 36;
break;
case 3:
vidam1 = 150,danom1 = 11,armaduram1 = 11;
hab1m1 = 20,hab2m1 = 30,ultm1 = 40;
break;
case 4:
vidam1 = 180,danom1 = 8,armaduram1 = 18;
hab1m1 = 15,hab2m1 = 8,ultm1 = 35;
break;
case 5:
vidam1 = 130,danom1 = 17,armaduram1 = 12;
hab1m1 = 25,hab2m1 = 15,ultm1 = 40;
break;
}
}
void DefineM2 (int m) {
switch(m) {
case 1:
vidam2 = 140,danom2 = 15,armaduram2 = 10;
hab1m2 = 25,hab2m2 = 20,ultm2 = 45;
break;
case 2:
vidam2 = 175,danom2 = 12,armaduram2 = 15;
hab1m2 = 18,hab2m2 = 6,ultm2 = 36;
break;
case 3:
vidam2 = 150,danom2 = 13,armaduram2 = 11;
hab1m2 = 20,hab2m2 = 30,ultm2 = 40;
break;
case 4:
vidam2 = 190,danom2 = 8,armaduram2 = 18;
hab1m2 = 15,hab2m2 = 8,ultm2 = 35;
break;
case 5:
vidam2 = 130,danom2 = 17,armaduram2 = 12;
hab1m2 = 25,hab2m2 = 25,ultm2 = 40;
break;
}
}
void Battle() {
srand(time(0));
playA = 1 + rand()% 2;
while (vidam1 > 0 || vidam2 > 0) {
if (playA == 1) {
printSkill(Element1);
cin >> skillj1;
while (skillj1 > 3 || skillj1 < 1) {
cout << "Skill invalid.Please repeat your choice\n";
cin >> skillj1;
}
while (skillj1 == 3 && cult1 < 3) {
cout << "Ultime will only be released in turn 3,repeat your choice\n";
cin >> skillj1;
}
evasion = 1 + rand() % 100;
if (cult1 == 3) {
cult1 = 1;
}
if (Element2 == 5) {
evasion += evasionR2;
if (evasion > 35) {
Choice(skillj1);
playA = 2;
cult1++;
} else {
cout << "you missed the attack!\n";
playA = 2;
cult1++;
}
}
if (Element2 != 5) {
if (evasion > 15) {
Choice(skillj1);
playA = 2;
cult1++;
} else {
cout << "you missed the attack!\n";
playA = 2;
cult1++;
}
}
if (vidam2 <= 0) {
cout << " Congratulations " << monster1 << " you eliminated the " << monster2;
exit(1);
}
}
if (playA == 2) {
printSkill(Element2);
cin >> skillj2;
if (skillj2 > 3 || skillj2 < 1) {
cout << "Skill invalid.Please repeat your choice\n";
cin >> skillj1;
}
while (skillj2 == 3 && cult2 < 3) {
cout << "Ultime will only be released in turn 3,repeat your choice\n";
cin >> skillj2;
}
evasion = 1 + rand() % 100;
if (cult2 == 3) {
cult2 = 1;
}
if (Element1 == 5) {
evasion += evasionR2;
if (evasion > 35) {
Choice(skillj1);
playA = 1;
cult2++;
} else {
cout << "you missed the attack!\n";
playA = 1;
cult2++;
}
}
if (Element1 != 5) {
if (evasion > 15) {
Choice(skillj1);
playA = 1;
cult1++;
} else {
cout << "you missed the attack!\n";
playA = 1;
cult1++;
}
}
if (vidam1 <= 0) {
cout << cout << "Congratulations " << monster2 << " you eliminated the " << monster1;
exit(1);
}
}
}
}
void messagep1 (int skill,int point) {
switch (Element1) {
case 1:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << " critical\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
}
break;
case 2:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << "damage\n\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
}
break;
case 3:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
case 2:
cout << monster1 << " recovered " << hab2m1 << " life";
cout << "\n\t"<< monster1 << "'s amount of life: " << vidam1 << '\n';
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
}
break;
case 4:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << "armor\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
}
break;
case 5:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << "evasion\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\n\t"<< monster2 << "'s amount of life: " << vidam2 << '\n';
break;
}
break;
}
}
void messagep2 (int skill,int point) {
switch (Element2) {
case 1:
switch (skill) {
case 1:
cout << monster2 << " inflicted " << point << " damage to the " << monster1;
cout << "\n\t"<< monster1 << "'s amount of life: " << vidam1 << '\n';
break;
case 2:
cout << monster2 << " increases " << hab2m2 << " critical\n\n";
break;
case 3:
cout << monster2 << " inflicted " << point << " damage to the " << monster1;
cout << "\n\t"<< monster1 << "'s amount of life: " << vidam1 << '\n';
break;
}
break;
case 2:
switch (skill) {
case 1:
Vitor

Vitor

Curtidas 0

Melhor post

Giuliano

Giuliano

25/04/2020

Boa tarde, seu código está muito extenso, assim não cabe todo no post. Tente colocar ele em um repositório (GitHub, GitLab).

E ao utilizar um código, você pode usar as tags que o fórum possui. Para isso seu código deve estar entre as tags.

Exemplo:

switch (skill) {
						case 1:
							cout << monster2 << " inflicted " << point << " damage to the " << monster1;
							cout << "\\n\\t"<< monster1 << "'s amount of life: " << vidam1 << '\\n';
						break;
						case 2:
							cout << monster2 << " increases " << hab2m2 << " critical\\n\\n";
						break;
						case 3:
							cout << monster2 << " inflicted " << point << " damage to the " << monster1;
							cout << "\\n\\t"<< monster1 << "'s amount of life: " << vidam1 << '\\n';
						break;							
					}
				break;


Para ver como utilizei as tags, caso ficou uma dúvida, basta clicar em responder, assim conseguirá ver toda formatação de minha resposta.
GOSTEI 1

Mais Respostas

Vitor

Vitor

24/04/2020

Meu primeiro jogo em C++,tenho 18 aos comecei a estudar C++ em 2019,mais especificamente em janeiro,e para testar meus conhecimentos criei esse mini-game de combate em turnos em C++,espero que me avaliem!.


#include <iostream>
using namespace std;
#include <cstdlib>
using std::rand;
using std::srand;
using std::exit;
#include <ctime>
using std::time;
#include <iomanip>
using std::setw;

class Element {
public:
Element(int j1,int j2) {
Element1 = j1;
Element2 = j2;
DefineM1(j1);
DefineM2(j2);
DefineNameM1(j1);
DefineNameM2(j2);
}
void DefineNameM1 (int n) {
switch (n) {
case 1:
monster1 = "Killer";
break;
case 2:
monster1 = "Warrior";
break;
case 3:
monster1 = "Magic";
break;
case 4:
monster1 = "Defender";
break;
case 5:
monster1 = "Rogue";
break;
}
}
void DefineNameM2 (int n) {
switch (n) {
case 1:
monster2 = "Killer";
break;
case 2:
monster2 = "Warrior";
break;
case 3:
monster2 = "Magic";
break;
case 4:
monster2 = "Defender";
break;
case 5:
monster2 = "Rogue";
break;
}
}
void DefineM1(int m) {
switch(m) {
case 1:
vidam1 = 140,danom1 = 15,armaduram1 = 10;
hab1m1 = 25,hab2m1 = 20,ultm1 = 45;
break;
case 2:
vidam1 = 165,danom1 = 12,armaduram1 = 15;
hab1m1 = 18,hab2m1 = 6,ultm1 = 36;
break;
case 3:
vidam1 = 150,danom1 = 11,armaduram1 = 11;
hab1m1 = 20,hab2m1 = 30,ultm1 = 40;
break;
case 4:
vidam1 = 180,danom1 = 8,armaduram1 = 18;
hab1m1 = 15,hab2m1 = 8,ultm1 = 35;
break;
case 5:
vidam1 = 130,danom1 = 17,armaduram1 = 12;
hab1m1 = 25,hab2m1 = 15,ultm1 = 40;
break;
}
}
void DefineM2 (int m) {
switch(m) {
case 1:
vidam2 = 140,danom2 = 15,armaduram2 = 10;
hab1m2 = 25,hab2m2 = 20,ultm2 = 45;
break;
case 2:
vidam2 = 175,danom2 = 12,armaduram2 = 15;
hab1m2 = 18,hab2m2 = 6,ultm2 = 36;
break;
case 3:
vidam2 = 150,danom2 = 13,armaduram2 = 11;
hab1m2 = 20,hab2m2 = 30,ultm2 = 40;
break;
case 4:
vidam2 = 190,danom2 = 8,armaduram2 = 18;
hab1m2 = 15,hab2m2 = 8,ultm2 = 35;
break;
case 5:
vidam2 = 130,danom2 = 17,armaduram2 = 12;
hab1m2 = 25,hab2m2 = 25,ultm2 = 40;
break;
}
}
void Battle() {
srand(time(0));
playA = 1 + rand()% 2;
while (vidam1 > 0 || vidam2 > 0) {
if (playA == 1) {
printSkill(Element1);
cin >> skillj1;
while (skillj1 > 3 || skillj1 < 1) {
cout << "Skill invalid.Please repeat your choice\\n";
cin >> skillj1;
}
while (skillj1 == 3 && cult1 < 3) {
cout << "Ultime will only be released in turn 3,repeat your choice\\n";
cin >> skillj1;
}
evasion = 1 + rand() % 100;
if (cult1 == 3) {
cult1 = 1;
}
if (Element2 == 5) {
evasion += evasionR2;
if (evasion > 35) {
Choice(skillj1);
playA = 2;
cult1++;
} else {
cout << "you missed the attack!\\n";
playA = 2;
cult1++;
}
}
if (Element2 != 5) {
if (evasion > 15) {
Choice(skillj1);
playA = 2;
cult1++;
} else {
cout << "you missed the attack!\\n";
playA = 2;
cult1++;
}
}
if (vidam2 <= 0) {
cout << " Congratulations " << monster1 << " you eliminated the " << monster2;
exit(1);
}
}
if (playA == 2) {
printSkill(Element2);
cin >> skillj2;
if (skillj2 > 3 || skillj2 < 1) {
cout << "Skill invalid.Please repeat your choice\\n";
cin >> skillj1;
}
while (skillj2 == 3 && cult2 < 3) {
cout << "Ultime will only be released in turn 3,repeat your choice\\n";
cin >> skillj2;
}
evasion = 1 + rand() % 100;
if (cult2 == 3) {
cult2 = 1;
}
if (Element1 == 5) {
evasion += evasionR2;
if (evasion > 35) {
Choice(skillj1);
playA = 1;
cult2++;
} else {
cout << "you missed the attack!\\n";
playA = 1;
cult2++;
}
}
if (Element1 != 5) {
if (evasion > 15) {
Choice(skillj1);
playA = 1;
cult1++;
} else {
cout << "you missed the attack!\\n";
playA = 1;
cult1++;
}
}
if (vidam1 <= 0) {
cout << cout << "Congratulations " << monster2 << " you eliminated the " << monster1;
exit(1);
}
}
}
}
void messagep1 (int skill,int point) {
switch (Element1) {
case 1:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << " critical\\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
}
break;
case 2:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << "damage\\n\\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
}
break;
case 3:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
case 2:
cout << monster1 << " recovered " << hab2m1 << " life";
cout << "\\n\\t"<< monster1 << "'s amount of life: " << vidam1 << '\\n';
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
}
break;
case 4:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << "armor\\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
}
break;
case 5:
switch (skill) {
case 1:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
case 2:
cout << monster1 << " increases " << hab2m1 << "evasion\\n";
break;
case 3:
cout << monster1 << " inflicted " << point << " damage to the " << monster2;
cout << "\\n\\t"<< monster2 << "'s amount of life: " << vidam2 << '\\n';
break;
}
break;
}
}
void messagep2 (int skill,int point) {
switch (Element2) {
case 1:
switch (skill) {
case 1:
cout << monster2 << " inflicted " << point << " damage to the " << monster1;
cout << "\\n\\t"<< monster1 << "'s amount of life: " << vidam1 << '\\n';
break;
case 2:
cout << monster2 << " increases " << hab2m2 << " critical\\n\\n";
break;
case 3:
cout << monster2 << " inflicted " << point << " damage to the " << monster1;
cout << "\\n\\t"<< monster1 << "'s amount of life: " << vidam1 << '\\n';
break;
}
break;
case 2:
switch (skill) {
case 1:
GOSTEI 0
POSTAR