Snake game border repeatedly prints

I am just starting out with C++, and I'm trying to code the game snake - when I compile and run the program it keeps printing the borders of the game over and over again without stopping. I don't know what to do to only print it once.
Any help / insight on my issue (or if there's anything else wrong in my code) would be much appreciated.
Thank you!


#include <iostream>
using namespace std;
bool gameOver;
const int width = 20;
const int height = 20;
int x , y, fruitX, fruitY, score;
enum eDirection {STOP = 0, LEFT, RIGHT, UP, DOWN};
eDirection dir;
void setup()
{
gameOver = false;
dir = STOP;
x = width / 2;
y = height / 2;
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
}

void Draw()
{
system("clear");
for (int i = 0; i < width; i++)
cout << "#";
cout << endl;

for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (j ==0)
cout << "#";

cout << " ";


if (j == width-1)
cout << "#";
}
cout << endl;
}

for (int i = 0; i <width; i++)
;
cout << "#";
cout << endl;
}
void Input()
{

}
void Logic()
{

}
int main()
{
setup();
while (!gameOver)
{
Draw();
Input();
Logic();
}
return 0;
}
Last edited on
Apolcalypticname wrote:
I don't know what to do to only print it once.

Set
gameOver = true;
Topic archived. No new replies allowed.