hafez1
جمعه 17 شهریور 1391, 23:40 عصر
یه کدی هست که دوستمونAGSGSAنوشتن.ولی من وقتی اجراش می کنم خط84 دو تا ارور می ده هر کی می تونه برطرفش کنه لطفا.
#include <Windows.h>
#include <iostream>
#include <conio.h>
// Num Object
#define NUMOBJ 3
using namespace std;
void gotoxy(int x, int y)
{
COORD c;
c.X = x;
c.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_H ANDLE), c);
}
class CObject
{
public:
int xpos;
int ypos;
int xopo; // old position
int yopo; // old position
CObject();
void MoveObject();
void DisplayObject();
private:
bool xrandom;
bool yrandom;
bool xoffset;
bool yoffset;
int xofs;
// x offsetint
int yofs;
// y offsetint
int xdir;
int ydir;
int minx;
int maxx;
char shape[10];
void Cleaner();
void Random(char);
}
obj[NUMOBJ];
class CGame
{
public:
int speed;
CGame();
void Hit();
void Run();
void KeyDown();
void Display();
private:
};
void main()
{
CGame game;
system("cls");
system("color 2c");
while(1)
{
game.Run();
game.Display();
Sleep(game.speed);
}
}
CObject::CObject(){
// Object 1
strcpy_s(obj[0].shape, "|______|");
obj[0].xofs = 0;
obj[0].yofs = 2;
obj[0].xpos = obj[0].xofs;
obj[0].ypos = obj[0].yofs;
obj[0].xdir = +1;
obj[0].ydir = 0;
obj[0].minx = 1;
obj[0].maxx = 35;
obj[0].xoffset = false;
obj[0].yoffset = false;
obj[0].xrandom = false;
obj[0].yrandom = false;
// Object 2
obj[1].shape[0] = 3;
// ASCII code ... Heart
shapeobj[1].shape[1] = NULL;
obj[1].xofs = 4;
obj[1].yofs = 24;obj[1].xpos = obj[1].xofs;
obj[1].ypos = obj[1].yofs;obj[1].xdir = 0;
obj[1].ydir = +1;
obj[1].minx = 1;
obj[1].maxx = 70;
obj[1].xoffset = false;
obj[1].yoffset = true;
obj[1].xrandom = true;
obj[1].yrandom = false;
// Object 3
strcpy_s(obj[2].shape, "|______|");
obj[2].xofs = 50;
obj[2].yofs = 2;
obj[2].xpos = obj[2].xofs;
obj[2].ypos = obj[2].yofs;
obj[2].xdir = -1;obj[2].ydir = 0;
obj[2].minx = 35;
obj[2].maxx = 70;
obj[2].xoffset = false;
obj[2].yoffset = false;
obj[2].xrandom = false;
obj[2].yrandom = false;
}
void CObject::MoveObject(){
Cleaner();
xpos += xdir;
ypos += ydir;
if(xpos > maxx)
xdir = -1;
else if(xpos < minx)
{
if(xoffset)
{
if(yrandom)Random('y');
xpos = xofs;}
else xdir = +1;}
if(ypos > 23){
ydir = -1;}
else if(ypos < 1)
{
if(yoffset){
if(xrandom)Random('x');
ypos = yofs;}
else
ydir = +1;}
xopo = xpos;
yopo = ypos;}
void CObject::DisplayObject(){
gotoxy(xpos, ypos);
cout << shape;}
void CObject::Random(char random){
if(random == 'x')
{xpos = rand() % 70;
if(xpos < 10)xpos = 10;}
else if(random == 'y'){
ypos = rand() % 20;
if(ypos < 2)ypos = 2;
}}
void CObject::Cleaner(){
gotoxy(xopo, yopo);
cout << " ";
// length = 10
}
CGame::CGame(){
int gamespeed = 50;
// normal speedspeed = 100 - gamespeed;
// speed ?!!!!?
}
void CGame::Hit(){
if(obj[1].xpos >= obj[0].xpos && obj[1].xpos <= obj[0].xpos + 8)if(obj[1].ypos <= obj[0].ypos)
{
obj[1].ypos = obj[1].yopo;
system("cls");
system("color 1a");
gotoxy(38, 11);
cout << "YOU WIN!";
Sleep(500);
system("cls");
system("color 2c");
}
if(obj[1].xpos >= obj[2].xpos && obj[1].xpos <= obj[2].xpos + 8)
if(obj[1].ypos <= obj[2].ypos){obj[1].ypos = obj[1].yopo;
system("cls");
system("color 1a");
gotoxy(38, 11);
cout << "YOU WIN!";
Sleep(500);
system("cls");
system("color 2c");
}}
void CGame::Run()
{
Hit();
KeyDown();
for(int i = 0; i < NUMOBJ; i++)
obj[i].MoveObject();}
void CGame::KeyDown(){
if(_kbhit()){
if(obj[1].xpos > 2 && obj[1].xpos < 69){
char C = _getch();
if(C == 75)obj[1].xpos--;
else if(C == 77)obj[1].xpos++;}}}
void CGame::Display(){
for(int i = 0; i < NUMOBJ;i++)obj[i].DisplayObject();}
#include <Windows.h>
#include <iostream>
#include <conio.h>
// Num Object
#define NUMOBJ 3
using namespace std;
void gotoxy(int x, int y)
{
COORD c;
c.X = x;
c.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_H ANDLE), c);
}
class CObject
{
public:
int xpos;
int ypos;
int xopo; // old position
int yopo; // old position
CObject();
void MoveObject();
void DisplayObject();
private:
bool xrandom;
bool yrandom;
bool xoffset;
bool yoffset;
int xofs;
// x offsetint
int yofs;
// y offsetint
int xdir;
int ydir;
int minx;
int maxx;
char shape[10];
void Cleaner();
void Random(char);
}
obj[NUMOBJ];
class CGame
{
public:
int speed;
CGame();
void Hit();
void Run();
void KeyDown();
void Display();
private:
};
void main()
{
CGame game;
system("cls");
system("color 2c");
while(1)
{
game.Run();
game.Display();
Sleep(game.speed);
}
}
CObject::CObject(){
// Object 1
strcpy_s(obj[0].shape, "|______|");
obj[0].xofs = 0;
obj[0].yofs = 2;
obj[0].xpos = obj[0].xofs;
obj[0].ypos = obj[0].yofs;
obj[0].xdir = +1;
obj[0].ydir = 0;
obj[0].minx = 1;
obj[0].maxx = 35;
obj[0].xoffset = false;
obj[0].yoffset = false;
obj[0].xrandom = false;
obj[0].yrandom = false;
// Object 2
obj[1].shape[0] = 3;
// ASCII code ... Heart
shapeobj[1].shape[1] = NULL;
obj[1].xofs = 4;
obj[1].yofs = 24;obj[1].xpos = obj[1].xofs;
obj[1].ypos = obj[1].yofs;obj[1].xdir = 0;
obj[1].ydir = +1;
obj[1].minx = 1;
obj[1].maxx = 70;
obj[1].xoffset = false;
obj[1].yoffset = true;
obj[1].xrandom = true;
obj[1].yrandom = false;
// Object 3
strcpy_s(obj[2].shape, "|______|");
obj[2].xofs = 50;
obj[2].yofs = 2;
obj[2].xpos = obj[2].xofs;
obj[2].ypos = obj[2].yofs;
obj[2].xdir = -1;obj[2].ydir = 0;
obj[2].minx = 35;
obj[2].maxx = 70;
obj[2].xoffset = false;
obj[2].yoffset = false;
obj[2].xrandom = false;
obj[2].yrandom = false;
}
void CObject::MoveObject(){
Cleaner();
xpos += xdir;
ypos += ydir;
if(xpos > maxx)
xdir = -1;
else if(xpos < minx)
{
if(xoffset)
{
if(yrandom)Random('y');
xpos = xofs;}
else xdir = +1;}
if(ypos > 23){
ydir = -1;}
else if(ypos < 1)
{
if(yoffset){
if(xrandom)Random('x');
ypos = yofs;}
else
ydir = +1;}
xopo = xpos;
yopo = ypos;}
void CObject::DisplayObject(){
gotoxy(xpos, ypos);
cout << shape;}
void CObject::Random(char random){
if(random == 'x')
{xpos = rand() % 70;
if(xpos < 10)xpos = 10;}
else if(random == 'y'){
ypos = rand() % 20;
if(ypos < 2)ypos = 2;
}}
void CObject::Cleaner(){
gotoxy(xopo, yopo);
cout << " ";
// length = 10
}
CGame::CGame(){
int gamespeed = 50;
// normal speedspeed = 100 - gamespeed;
// speed ?!!!!?
}
void CGame::Hit(){
if(obj[1].xpos >= obj[0].xpos && obj[1].xpos <= obj[0].xpos + 8)if(obj[1].ypos <= obj[0].ypos)
{
obj[1].ypos = obj[1].yopo;
system("cls");
system("color 1a");
gotoxy(38, 11);
cout << "YOU WIN!";
Sleep(500);
system("cls");
system("color 2c");
}
if(obj[1].xpos >= obj[2].xpos && obj[1].xpos <= obj[2].xpos + 8)
if(obj[1].ypos <= obj[2].ypos){obj[1].ypos = obj[1].yopo;
system("cls");
system("color 1a");
gotoxy(38, 11);
cout << "YOU WIN!";
Sleep(500);
system("cls");
system("color 2c");
}}
void CGame::Run()
{
Hit();
KeyDown();
for(int i = 0; i < NUMOBJ; i++)
obj[i].MoveObject();}
void CGame::KeyDown(){
if(_kbhit()){
if(obj[1].xpos > 2 && obj[1].xpos < 69){
char C = _getch();
if(C == 75)obj[1].xpos--;
else if(C == 77)obj[1].xpos++;}}}
void CGame::Display(){
for(int i = 0; i < NUMOBJ;i++)obj[i].DisplayObject();}