Need help with snake game food bug, C++

Had a program to write based on code provided by teacher, decided to make a snake game. It does everything I want it to thus far, but the second iteration of the food (after it's redrawn) does not appear to be the same kind of object as the first. Due in roughly twelve hours, so any help is greatly appreciated. No errors.

Also, any suggestions on how to make the snake change direction? x.x;

[code]#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#pragma comment(lib, "winmm.lib")

using namespace std;

//char* SPLASHPAGE = "snakegreet.txt";
//char* GAMEOVER = "snakeend.txt";

const int BLACK=0, BLUE=1, GREEN=2, AQUA=3, RED=4, PURPLE=5, YELLOW=6, WHITE=7, GRAY=8, LIGHT_BLUE=9,
LIGHT_GREEN=10, LIGHT_AQUA=11, LIGHT_RED=12, LIGHT_PURPLE=13, LIGHT_YELLOW=14, BRIGHT_WHITE=15;
const string CHOMP = "chomp.wav";
const string SPLAT = "splat.wav";
const int maxrow=15, maxcol=77;
const int CURSOR_LEFT = 123;
const int CURSOR_RIGHT = 125;
const int CURSOR_UP = 124;
const int CURSOR_DOWN = 126;
bool CONTINUE_GAME = true;
void setColor(int foreground, int background);
//void boundaryLine(int row, int col);

int g_life = 3;
int g_Score = 0;

//void readInPage(char filename[])
//{
// setColor(BRIGHT_WHITE, BLACK);
// ifstream infile;
// infile.open(filename);
// if (infile.fail())
// {
// cout << "can't open snakegreet.txt";
// cin.get();
// exit(1);
// }
// char temp[80];
// while(!infile.eof())
// {
// infile.getline(temp, 80);
// cout << temp << endl;
// }
//}



struct worldLimit
{
static const int LEFT = 1;
static const int TOP = 1;
static const int RIGHT = 70; //80
static const int BOTTOM = 22; //24
};

class GameObject
{
private:
int x;
int y;
int prevX;
int prevY;
int width;
int height;
bool killed;

public:
int getX();
void setX(int newX);
int getY();
void setY(int newY);
int getWidth();
void setWidth(int newWidth);
int getHeight();
void setHeight(int newHeight);
int getPrevX();
int getPrevY();
virtual void draw();
virtual void redraw();
virtual void drawErase();
void move();
bool isKilled() {return killed;}
virtual void kill()
{
killed=true;
x=0; y=0; prevX=0; prevY=0; width=0; height=0;
}
};

void displayLife();
void displayScore();
void playSound(string filename);
int acquireUserInput();
void particleEffect(int x, int y);
void gotoXY(int x, int y);
void initialize();
void renderGraphics();
bool collisionDetection(GameObject o1, GameObject o2);

int GameObject::getX()
{
return x;
}
void GameObject::setX(int newX)
{
x = newX;
}
int GameObject::getY()
{
return y;
}
void GameObject::setY(int newY)
{
y = newY;
}

void GameObject::draw()
{
}

void GameObject::redraw()
{
}
void GameObject::drawErase()
{
}

int GameObject::getWidth()
{
return width;
}
void GameObject::setWidth(int newWidth)
{
width = newWidth;
}
int GameObject::getHeight()
{
return height;
}
void GameObject::setHeight(int newHeight)
{
height = newHeight;
}

void GameObject::move()
{
prevX = x;
prevY = y;
}

int GameObject::getPrevX()
{
return prevX;
}

int GameObject::getPrevY()
{
return prevY;
}


class Snake : public GameObject
{
public:

void draw();
void drawErase();
};

class Food : public GameObject
{
public:
void draw();
void redraw();
void drawErase();
void kill();
};

void info()
{
setColor(LIGHT_RED, BLACK);
gotoXY(1,23);
printf(" INFO! Use arrow keys, eat the items for points ");
gotoXY(1,24);
printf(" DON'T hit any part of the snake's body! ");
}
void Snake::draw()
{
setColor(LIGHT_YELLOW, BLACK);
gotoXY(getX(), getY()); cout << " ";
printf("
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories