C++ Game Error.

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

94 Replies - 3614 Views - Last Post: 12 November 2017 - 01:22 AM Rate Topic: -----

#31 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 26 October 2017 - 04:08 PM

r.stiltskin Where do I create another Player object?
Was This Post Helpful? 0
  • +
  • -

#32 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2009
  • View blog
  • Posts: 5,387
  • Joined: 27-December 05

Re: C++ Game Error.

Posted 26 October 2017 - 06:19 PM

The only function that you have that runs continuously throughout the game is your main function, so that's where Player and Enemy objects should be created.
Was This Post Helpful? 0
  • +
  • -

#33 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 27 October 2017 - 12:01 PM

Well aren't they created there?
Was This Post Helpful? 0
  • +
  • -

#34 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 30 October 2017 - 03:50 PM

Bump
Was This Post Helpful? 0
  • +
  • -

#35 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2009
  • View blog
  • Posts: 5,387
  • Joined: 27-December 05

Re: C++ Game Error.

Posted 30 October 2017 - 04:32 PM

No. Here you're creating an Enemy in Player::playerMovement
void Player::playerMovement(int& Tile, bool& enemyEncountered)
{
    cout<<"                      How many tiles do you want to move?"<<endl;
    cout<<"\n\n                                    Tile:"<<Tile<<"\n"<<endl;
    cout<<"\n--------------------------------------------------------------------------------"<<endl;
    cout<<"\n\n                    Hint:You can only move 5 tile at a time."<<endl;

    if(enemyEncountered == false)
    {
        cin>>movementInput;

        Enemy en;
// ...



and in Player::playerAttack
void Player::playerAttack(string player_name, bool& enemyEncountered)
{
    cout<<"                              Please choose an attack!"<<endl;

    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;

    cout<<" 1.Hadouken\n"<<endl;
    cout<<" 2.Recover\n"<<endl;
    cout<<" 3.Might Guy\n"<<endl;
    cout<<" 4.Toxic Spikes"<<endl;
    Enemy en;
// ...



and in Player::enemyHealth
void Player::enemyHealthLeft()
{
    Enemy en;
// ...



and here you're creating a Player in Enemy::enemyAttack
void Enemy::enemyAttack(bool enemyEncountered)
{
    if(enemyEncountered == true)
    {
        srand(time(NULL));

        int attackChance;

        for(int y; y <= 5; y++)
        {
            attackChance = rand()%3;
        }

        Player pl;
// ...

Was This Post Helpful? 0
  • +
  • -

#36 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,481
  • Joined: 13-June 14

Re: C++ Game Error.

Posted 30 October 2017 - 10:03 PM

Xrey274, please don't bump your threads like that. Remember that this is a volunteer forum and members respond when they are able and want to.
Was This Post Helpful? 1
  • +
  • -

#37 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 31 October 2017 - 03:46 PM

Sorry, I just wanted to get an answer.
Was This Post Helpful? 0
  • +
  • -

#38 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 31 October 2017 - 04:22 PM

I am starting a big overhaul of the game. This should fix all of my problems. :)
Was This Post Helpful? 0
  • +
  • -

#39 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 01 November 2017 - 01:35 PM

Btw i started doing the overhaul and i noticed an error at line 38: expected primary-expression before 'string player_name'

main.cpp
#include "Player.h"
#include "Enemy.h"
#include "Animations.h"
#include "resource.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>

using namespace std;

void Engine(string player_name);
void menu(int game_over, string player_name);
void menu_dank(int game_over, string player_name);
void enemyCalling();
void Death();

int main()
{

    cout<<"                          Welcome to MortalKombat 2.\n\n"<<endl;
    cout<<"                          Press any key to continue.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;
    cout<<"\n\n Made By: Xrey274\n"<<endl;
    cout<<" Running Version: Alpha 1.4\n"<<endl;
    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
    cout<<"                                  Update Info"<<endl;

    if(cin.get())
    {
        system("cls");
    }

    string player_name;
    cout<<"                            Please enter your name:\n\n"<<endl;
    cout<<"                                   ";cin>>player_name;

    Engine(string player_name);
}

void Engine(string player_name)
{
    int Tile = 1;
    bool enemyEncountered;

    bool game_over = false;
    Player pl;
    Enemy en;
    Animations an;

    while(!game_over)
    {
        system("cls");
        if(Tile == 69)
        {
            menu_dank(game_over, player_name);
        }
        else
        {
            menu(game_over, player_name);
        }


        int input;
        cin>>input;

        int redirecting;

        switch(input)
        {
            case 1:
                system("cls");
                pl.playerMovement(redirecting, Tile, enemyEncountered);
                break;
            case 2:
                system("cls");
                pl.playerAttack(redirecting, player_name, enemyEncountered);
                break;
            case 100:
                system("cls");
                en.enemyEncountering(1, enemyEncountered);
        }
    }

    if(game_over)
    {
        Death();
    }
}

void menu(int game_over, string player_name)
{
    cout<<"                      Please choose what you want to do.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;

    cout<<"\n 1-Move\n"<<endl;
    cout<<" 2-Attack\n"<<endl;
    cout<<" 3-Inventory\n"<<endl;
    cout<<" 4-Stats\n"<<endl;
    cout<<" Player Name: "<<player_name<<endl;

    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
}

void menu_dank(int game_over, string player_name)
{
    cout<<"                      69696969696969696969696969696969696969.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;

    cout<<"\n 1-6969\n"<<endl;
    cout<<" 2-696969\n"<<endl;
    cout<<" 3-6969696969\n"<<endl;
    cout<<" 4-69696969\n"<<endl;
    cout<<" 69696969:"<<player_name<<endl;

    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
}

void Death()
{

}



Was This Post Helpful? 0
  • +
  • -

#40 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1377
  • View blog
  • Posts: 4,312
  • Joined: 20-March 10

Re: C++ Game Error.

Posted 01 November 2017 - 02:44 PM

line 38


Engine(string player_name);


should be

Engine(player_name);


you do not pass variable types into functions ..
Was This Post Helpful? 1
  • +
  • -

#41 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 02 November 2017 - 07:14 AM

Is it possible to create another object to call getHealth() without creating another instance?

Like this on like 118, 119:

#include "Player.h"
#include "Enemy.h"
#include "Animations.h"
#include "resource.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>

using namespace std;

void Engine(string player_name);
void menu(int game_over, string player_name, bool enemyEncountered);
void menu_dank(int game_over, string player_name, bool enemyEncountered);
void enemyCalling();
void Death();

int main()
{
    string player_name;

    cout<<"                          Welcome to MortalKombat 2.\n\n"<<endl;
    cout<<"                          Press any key to continue.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;
    cout<<"\n\n Made By: Xrey274\n"<<endl;
    cout<<" Running Version: Alpha 1.4\n"<<endl;
    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
    cout<<"                                  Update Info"<<endl;

    if(cin.get())
    {
        system("cls");
    }

    cout<<"                            Please enter your name:\n\n"<<endl;
    cout<<"                                   ";cin>>player_name;

    Engine(player_name);
}

void Engine(string player_name)
{
    int Tile = 1;
    bool enemyEncountered = false;

    bool game_over = false;
    Player pl;
    Enemy en;
    Animations an;

    while(!game_over)
    {
        system("cls");
        if(Tile == 69)
        {
            menu_dank(game_over, player_name, enemyEncountered);
        }
        else
        {
            menu(game_over, player_name, enemyEncountered);
        }


        int input;
        cin>>input;

        int redirecting;

        switch(input)
        {
            case 1:
                system("cls");
                pl.playerMovement(redirecting, Tile, enemyEncountered);
                break;
            case 2:
                system("cls");
                pl.playerAttack(redirecting, player_name, enemyEncountered);
                break;
        }

        switch(redirecting)
        {
            case 100:
                system("cls");
                en.enemyEncountering(1, enemyEncountered);
                break;
            case 101:
                system("cls");
                en.take_eDamage(5);
                an.hadouken_Animation();
                break;
            case 102:
                system("cls");
                an.recover_Animation();
                break;
        }
    }

    if(game_over)
    {
        Death();
    }
}

void menu(int game_over, string player_name, bool enemyEncountered)
{
    cout<<"                      Please choose what you want to do.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;

    cout<<"\n 1-Move\n"<<endl;
    cout<<" 2-Attack\n"<<endl;
    cout<<" 3-Inventory\n"<<endl;
    cout<<" 4-Stats\n"<<endl;
    cout<<" Player Name: "<<player_name<<"                                          Enemy Health: ";

    if(enemyEncountered == true)
    {
        Enemy en;
        en.getHealth();
    }

    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
}

void menu_dank(int game_over, string player_name, bool enemyEncountered)
{
    cout<<"                      69696969696969696969696969696969696969.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;

    cout<<"\n 1-6969\n"<<endl;
    cout<<" 2-696969\n"<<endl;
    cout<<" 3-6969696969\n"<<endl;
    cout<<" 4-69696969\n"<<endl;
    cout<<" 69696969:"<<player_name<<endl;

    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
}

void Death()
{

}



Was This Post Helpful? 0
  • +
  • -

#42 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5894
  • View blog
  • Posts: 20,114
  • Joined: 05-May 12

Re: C++ Game Error.

Posted 02 November 2017 - 09:02 AM

Yes. You pass the current instance that you have to the function that needs it.
Was This Post Helpful? 0
  • +
  • -

#43 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1377
  • View blog
  • Posts: 4,312
  • Joined: 20-March 10

Re: C++ Game Error.

Posted 02 November 2017 - 09:18 AM

To expand a little on that,

in void Engine,

line 48 you create an instance of a Enemy en.

You should pass this by reference into... void menu... on line 118 delete the new instance of Enemy as it should be passed

into void menu();

like this

void menu(int game_over, string player_name, bool enemyEncountered, Enemy& en)


Was This Post Helpful? 0
  • +
  • -

#44 Xrey274  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 10-December 16

Re: C++ Game Error.

Posted 02 November 2017 - 11:08 AM

I get 2 errors at 56 and 60:
error:expected primary-expression before '&' token.

#include "Player.h"
#include "Enemy.h"
#include "Animations.h"
#include "resource.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>

using namespace std;

void Engine(string player_name);
void menu(int game_over, string player_name, bool enemyEncountered, Enemy& en);
void menu_dank(int game_over, string player_name, bool enemyEncountered, Enemy& en);
void enemyCalling();
void Death();

int main()
{
    string player_name;

    cout<<"                          Welcome to MortalKombat 2.\n\n"<<endl;
    cout<<"                          Press any key to continue.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;
    cout<<"\n\n Made By: Xrey274\n"<<endl;
    cout<<" Running Version: Alpha 1.4\n"<<endl;
    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
    cout<<"                                  Update Info"<<endl;

    if(cin.get())
    {
        system("cls");
    }

    cout<<"                            Please enter your name:\n\n"<<endl;
    cout<<"                                   ";cin>>player_name;

    Engine(player_name);
}

void Engine(string player_name)
{
    int Tile = 1;
    bool enemyEncountered = false;

    bool game_over = false;
    Player pl;
    Enemy en;
    Animations an;

    while(!game_over)
    {
        system("cls");
        if(Tile == 69)
        {
            menu_dank(game_over, player_name, enemyEncountered, Enemy& en);
        }
        else
        {
            menu(game_over, player_name, enemyEncountered, Enemy& en);
        }


        int input;
        cin>>input;

        int redirecting;

        switch(input)
        {
            case 1:
                system("cls");
                pl.playerMovement(redirecting, Tile, enemyEncountered);
                break;
            case 2:
                system("cls");
                pl.playerAttack(redirecting, player_name, enemyEncountered);
                break;
        }

        switch(redirecting)
        {
            case 100:
                system("cls");
                en.enemyEncountering(1, enemyEncountered);
                break;
            case 101:
                system("cls");
                en.take_Damage(5);
                an.hadouken_Animation();
                break;
            case 102:
                system("cls");
                an.recover_Animation();
                break;
        }
    }

    if(game_over)
    {
        Death();
    }
}

void menu(int game_over, string player_name, bool enemyEncountered, Enemy& en)
{
    cout<<"                      Please choose what you want to do.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;

    cout<<"\n 1-Move\n"<<endl;
    cout<<" 2-Attack\n"<<endl;
    cout<<" 3-Inventory\n"<<endl;
    cout<<" 4-Stats\n"<<endl;
    cout<<" Player Name: "<<player_name<<"                                         Enemy Health: ";

    if(enemyEncountered == true)
    {
        en.getHealth();
    }

    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
}

void menu_dank(int game_over, string player_name, bool enemyEncountered)
{
    cout<<"                      69696969696969696969696969696969696969.\n"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;

    cout<<"\n 1-6969\n"<<endl;
    cout<<" 2-696969\n"<<endl;
    cout<<" 3-6969696969\n"<<endl;
    cout<<" 4-69696969\n"<<endl;
    cout<<" 69696969:"<<player_name<<endl;

    cout<<"\n\n--------------------------------------------------------------------------------"<<endl;
}

void Death()
{

}



Was This Post Helpful? 0
  • +
  • -

#45 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 588
  • View blog
  • Posts: 2,481
  • Joined: 13-June 14

Re: C++ Game Error.

Posted 02 November 2017 - 11:27 AM

Look carefully ato the arguments you're passing. What looks out of place? You really need to get into the habit of trying to figure out these errors.
Was This Post Helpful? 0
  • +
  • -

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »