i'm doing a game for my c++ course and there is something wrong with a class

the error comes up in class hero...function jumpright

#include <iostream.h>
#include <conio.h>
#include <afx.h>
#define rows 48
#define cols 80



class screen
{
private:
	char x[rows][cols];

public:

	
	screen()
	{
					int i,j;
			for(i=0;i<rows;i++)
			{
				for(j=0;j<cols;j++)
				{
					x[i][j]=' ';
				}
			}
		
			
			for(i=0;i<cols;i++)
			{
				x[0][i]='#';
			}
			
			
			for(i=0;i<cols;i++)
			{
				x[rows-1][i]='#';
			}




	}


	void setcell(int i,int c,char t)
	{
		x[i][c]=t;
	}

	void show()
	{
		 system("cls");
		 for(int i=0;i<rows;i++)
		 {
			for(int j=0;j<cols;j++)
			{
				cout<<x[i][j];
			}
		 }
		 cout.flush();
	}


};




class hero
{
private:

	int posr;
	int posc;
	int health;
	int direction;
	int speed;


public:

	hero()
	{
		posr=rows-4;
		posc=3;
		health =5;
		direction =1;
		speed =0;
	}



	void drawhero(screen &x)
	{
		char t=1;

		
		{


					
			x.setcell(posr,posc,t);
			x.setcell(posr+1,posc,'|');
			
			x.setcell(posr+1,posc-1,'-');
			x.setcell(posr+1,posc+1,' -');
			
			x.setcell(posr+2,posc-1,'|');
			x.setcell(posr+2,posc+1,'|');
		}
	}

	


 	void delhero(screen &x)
	{
	


		
		{

			x.setcell(posr,posc,' ');
			x.setcell(posr+1,posc,' ');
			
			x.setcell(posr+1,posc-1,' ');
			x.setcell(posr+1,posc+1,' ');
	
			x.setcell(posr+2,posc-1,' ');
			x.setcell(posr+2,posc+1,' ');
		}
	}




	void moveright(screen &x)
	{
	
		if(posc<cols-2)
		{

		delhero(x);

		posc++;

		drawhero(x);
		}
	
	}



	void moveleft(screen &x)
	{
		if(posc>1)
		{

		delhero(x);
		posc--;
		drawhero(x);

		}
	}

	void hit()
	{
		health--;
	}

	int gethealth()
	{
		return health;
	}







	void jumpright(screen &x, game &t)
	{
		delhero(x);
		posc+=2;
		posr--;
		drawhero(x);
		automove();
		Sleep(100);
		show();
	


		delhero(x);
		posc++;
		drawhero(x);

		automove();
		Sleep(50);
		show();
	


		delhero(x);
		posc+=2;
		posr++;
		drawhero(x);


		automove();
		


	}


};





class game
{

	screen x;
	hero bob;
	
public:

	game()
	{
		int t;
	t=	bob.gethealth();
	cout<<t;
	}

	
	 void automove()
	{
	
		cout<<"teet"<<endl;
	}

	void usermove(char t,game &nagy)
	{
			if(t=='a')
			bob.moveleft(x);

			if(t=='d')
			bob.moveright(x);

			if(t=='e')
				bob.jumpright(x);


	}

	void show()
	{
		
		
		
		bob.drawhero(x);
		x.show();
	}
	

	int run()
	{
		return 1;
	}

};


void main()
{
	
	char t;
	game nagy;
	nagy.show();

	while (nagy.run())
	{

		t=getch();
		nagy.usermove(t,nagy);
		


		nagy.show();
	}






}

Recommended Answers

All 4 Replies

There's a post at the top of the forum Read This before posting. It talks about using code tags and posting well indented and easy to read code. Please go through it.

commented: sounds like good advice to me :) +12

In addition to Agni's post: You should also post the errormessages you get.

ok sorry
i use vc++ 06
the error is
error C2061: syntax error : identifier 'game'
and i posted the whole code cause i think it is the arrangement .

i have class game down...so i don't know y it doesn't accept it...

so do i have to define the class in the beginning like functions???

Try reformatting your code, it's damn hard to read with all those white lines in it...

anyway, the error you posted is probably due to this line: void jumpright(screen &x, game &t) Here you tell the function "jumpright" that it can expect a class 'game', but the problem is that the class 'game' is not yet defined. You define the class a few lines later.

There are a number of horrible hacks to makes this code compile, but what I would really recommend is that you learn how to use header files.

Put your declaration in the header file like this (dani.h)

class foo
{
public:
    foo();
    ~foo();
    void func(void);
};

class bar
{
public:
    bar();
    ~bar();
    void func2(void);
};

Now you can put the defenition in the cpp file:

dani.cpp:

#include "dani.h"

void bar::func2()
{
    foo * f = new  foo();
    //foo is declared
    delete f;
}

void foo::func()
{
    bar * b = new bar();
    // bar is in declared
    delete b;
}

Don't forget to make a body for constructer/destructors to !

also read this about using void main()

And you also might want to update your compiler (turbo) to something from the last 10 years... Visual studio 2008 express is free for example

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.