Ir para conteúdo
Fórum Script Brasil
  • 0

Não estou conseguindo voltar com o HP inicial quando colocado para jogar novamente!


kayo duarte cavalcante

Pergunta

#include<iostream>
#include<string>

using namespace std;

class pokemoniv
{
public:
    int attack{}, defense{}, hp{}, move01{}, move02{};
    string name, nmove01, nmove02;
    void ini(int pk);
};
void pokemoniv::ini(int pk)
{
    if (pk == 1)
    {
        name = "Tyranitar";
        nmove01 = "Crunch";
        nmove02 = "Hyper beam";
        attack = 134;
        defense = 110;
        hp = 100;
        move01 = 80;
        move02 = 150;
    }
    if (pk == 2)
    {
        name = "Garchomp";
        nmove01 = "Dragon Claw";
        nmove02 = "Earthquake";
        attack = 130;
        defense = 95;
        hp = 108;
        move01 = 80;
        move02 = 100;
    }
    if (pk == 3)
    {
        name = "Dragonite";
        nmove01 = "Fly";
        nmove02 = "Outrage";
        attack = 134;
        defense = 95;
        hp = 91;
        move01 = 90;
        move02 = 120;
    }
}
class rivalpk
{
public:
    string rname = "Mewtwo";
    string rnmove01 = "Psychic";
    string rnmove02 = "Swift";
    int rattack = 154;
    int rdefense = 90;
    int rhp = 106;
    int rmove01 = 110;
    int rmove02 = 60;
};
int main()
{
    pokemoniv x;
    rivalpk y;
    int starter;
    int move;
    string player;
    int r = 0;

    int* ptr;
    ptr = &x.hp;
    int* rptr;
    rptr = &y.rhp;

    cout << "Ola eu sou o Professor Oak, qual o seu nome?" << endl;
    cin >> player;

    while (r != 2)
    {
        cout << "PROFESSOR: " << player << ", escolha seu pokemon para a batalha!Para escolher o Tyranitar precione(1), para escolher o Garchomp precione(2) e para escolher o Dragonite precione(3)." << endl;
        cin >> starter;
        x.ini(starter);

        cout << "PROFESSOR: então voce escolheu " << x.name << "." << endl;

        cout << "PROFESSOR: Vamos comecar a batalha! Esse é seu rival, ele se chama Blue." << endl << endl;
        cout << "****BATALHAR****" << endl << endl;

        cout << player << " jogou " << x.name << " para batalhar!" << endl;
        cout << "Blue jogou " << y.rname << " para batalhar!" << endl << endl;

        while (x.hp > 0 && y.rhp > 0)
        {
            cout << "Aperte (1) para usar " << x.nmove01 << " ou (2) para usar " << x.nmove02 << "." << endl;
            cin >> move;
            cout << endl;

            if (move == 1)
            {
                cout << x.name << " usou " << x.nmove01 << "!" << endl;
                int damage = ((x.attack - y.rdefense) + x.move01) - y.rhp;
                int newhprival = y.rhp - damage;
                *rptr = newhprival;
                cout << y.rname << " esta com " << y.rhp << " de hp." << endl << endl;

                if (y.rhp <= 0)
                {
                    cout << "Hp de " << y.rname << " chegou a 0!" << endl;
                    cout << "BLUE: Parece que não fui pareo para voce " << player << ", na proxima não irei perder!" << endl << endl;
                    cout << "PROFESSOR: Parabens " << player << "!" << endl;
                }

                if (y.rhp > 0)
                {
                    cout << y.rname << " usou " << y.rnmove02 << "!" << endl;
                    int rdamage = ((y.rattack - x.defense) + y.rmove02) - x.hp;
                    int newhp = x.hp - rdamage;
                    *ptr = newhp;
                    cout << x.name << " esta com " << x.hp << " de hp." << endl << endl;

                    if (x.hp <= 0)
                    {
                        cout << "Hp de " << x.name << " chegou a 0!" << endl;
                        cout << "BLUE: Voce não é pareo para mim treinador!" << endl << endl;
                        cout << "VOCE PERDEU!" << endl;
                    }
                }
            }
            if (move == 2)
            {
                cout << x.name << " usou " << x.nmove02 << "!" << endl;
                int damage = ((x.attack - y.rdefense) + x.move02) - y.rhp;
                int newhprival = y.rhp - damage;
                *rptr = newhprival;
                cout << y.rname << " esta com " << y.rhp << " de hp." << endl << endl;

                if (y.rhp <= 0)
                {
                    cout << "Hp de " << y.rname << " chegou a 0!" << endl;
                    cout << "BLUE: Parece que não fui pareo para voce " << player << ", na proxima não irei perder!" << endl << endl;
                    cout << "PROFESSOR: Parabens " << player << "!" << endl;
                }

                if (y.rhp > 0)
                {
                    cout << y.rname << " usou " << y.rnmove01 << "!" << endl;
                    int rdamage = ((y.rattack - x.defense) + y.rmove01) - x.hp;
                    int newhp = x.hp - rdamage;
                    *ptr = newhp;
                    cout << x.name << " esta com " << x.hp << " de hp." << endl << endl;

                    if (x.hp <= 0)
                    {
                        cout << "Hp de " << x.name << " chegou a 0!" << endl;
                        cout << "BLUE: Voce não é pareo para mim treinador!" << endl << endl;
                        cout << "VOCE PERDEU!" << endl;
                    }
                }
            }
        }
        cout << player << " quer jogar novamente? Se sim, aperte 1." << endl;
        cin >> r;
        system("cls");
    }
    system("pause");
    return 0;
}

 
 
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0
On 6/24/2022 at 2:53 AM, kayo duarte cavalcante said:

#include<iostream>
#include<string>

using namespace std;

class pokemoniv
{
public:
    int attack{}, defense{}, hp{}, move01{}, move02{};
    string name, nmove01, nmove02;
    void ini(int pk);
};
void pokemoniv::ini(int pk)
{
    if (pk == 1)
    {
        name = "Tyranitar";
        nmove01 = "Crunch";
        nmove02 = "Hyper beam";
        attack = 134;
        defense = 110;
        hp = 100;
        move01 = 80;
        move02 = 150;
    }
    if (pk == 2)
    {
        name = "Garchomp";
        nmove01 = "Dragon Claw";
        nmove02 = "Earthquake";
        attack = 130;
        defense = 95;
        hp = 108;
        move01 = 80;
        move02 = 100;
    }
    if (pk == 3)
    {
        name = "Dragonite";
        nmove01 = "Fly";
        nmove02 = "Outrage";
        attack = 134;
        defense = 95;
        hp = 91;
        move01 = 90;
        move02 = 120;
    }
}
class rivalpk
{
public:
    string rname = "Mewtwo";
    string rnmove01 = "Psychic";

    int rattack = 154;
    int rdefense = 90;
    int rhp = 106;
    int rmove01 = 110;
    int rmove02 = 60;
};
int main()
{
    pokemoniv x;
    rivalpk y;
    int starter;
    int move;
    string player;
    int r = 0;

    int* ptr;
    ptr = &x.hp;
    int* rptr;
    rptr = &y.rhp;

    cout << "Hello I'm Professor Oak, what's his name?" << endl;
    cin >> player;

    while (r != 2)
    {
        cout << "TEACHER: " << player << ", choose your pokemon for the battle! To choose Tyranitar press(1), to choose Garchomp press(2) and to choose Dragonite press(3)." << endl;
        cin >> starter;
        x.ini(starter);

        cout << "TEACHER: so you chose " << x.name << "." << endl;         cout << "TEACHER: Let's start the battle! This is your rival, his name is Blue." << endl << endl;         cout << "****BATTLE****" << endl << endl;         cout << player << " played " << x.name << "  




  



        {
            cout << "Press (1) to use " << x.nmove01 << " or (2) to use " << x.nmove02 << "." << endl;
            cin >> move;
            cout << endl;

            if (move == 1)
            {
                cout << x.name << " used " << x.nmove01 << "!" << endl;                 int damage = ((x.attack - y.rdefense) + x.move01) - y.rhp;                 int newhprival = y.rhp - damage;                 *rptr = newhprival;                 cout << y.rname << " is with " << y.rhp << " from hp." << endl << endl;  







                    cout << "Hp of " << y.rname << " has reached 0!" << endl;
                    cout << "BLUE: Looks like I wasn't a match for you " << player << ", next time I won't lose!" << endl << endl;
                    cout << "TEACHER: Congratulations " << player << "!" << endl;
                }

                if (y.rhp > 0)
                {
                    cout << y.rname << " used " << y.rnmove02 << "!" << endl;
                    int rdamage = ((y.rattack - x.defense) + y.rmove02) - x.hp;
                    int newhp = x.hp - rdamage;
                    *ptr = newhp;
                    cout << x.name << " is with " << x.hp << " from hp." << endl << endl;  

                    if (x.hp <= 0)
                    {
                        cout << "Hp of " << x.name << " has reached 0!" << endl;                         cout << "BLUE: You are no match for me coach!" << endl << endl;                         cout << "YOU LOST!" << endl;                     }                 }             }             if (move == 2)             {                 cout << x.name << " used " << x.nmove02 << "!" << endl;                 int damage = ((x.attack - y.rdefense) + x.move02) - y.rhp;                 int newhprival = y.rhp - damage;                 *rptr = newhprival;  World's Hardest Game







  



                cout << y.rname << " is with " << y.rhp << " from hp." << endl << endl;

                if (y.rhp <= 0)
                {
                    cout << "Hp of " << y.rname << " has reached 0!" << endl;
                    cout << "BLUE: Looks like I wasn't a match for you " << player << ", next time I won't lose!" << endl << endl;
                    cout << "TEACHER: Congratulations " << player << "!" << endl;
                }

                if (y.rhp > 0)
                {
                    cout << y.rname << "


                    *ptr = newhp;
                    cout << x.name << " is with " << x.hp << " from hp." << endl << endl;                     if (x.hp <= 0)                     {                         cout << "Hp of " << x.name << " has reached 0!" << endl;                         cout << "BLUE: You are no match for me coach!" << endl << endl;                         cout << "YOU LOST!" << endl;                     }                 }             }         }         cout << player << " want to play again?         If yes, press 1." << endl; cin >> r;         system("cls");     }  



  










    system("pause");
    return 0;
}

 
 

There may be some error in the parameters leading to this error. Have you checked again?

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...