ERROR in execution

I am making a simple SNAKE Game....

there are errors in running of code and i stuck over here ...so help me how to resolve this issue...



#include <iostream>
//#include <conio.h>
//#include "util.h"
using namespace std;
bool GameOver;
const int width=20;
const int height=20;
enum direction {STOP=0,LEFT,RIGHT,UP,DOWN};
direction dir;
int x,y,targetX,targetY,score;



void set()
{
GameOver=false;
dir=STOP;
x=width/2;
y=height/2;
targetX=rand()%20;
targetY=rand()%20;
score=0;

}


void Draw()
{


for(int i=0;i<22;i++)
{
cout<<"#";
}
cout<<endl;
for(int j=0;j<20;j++)
{
for(int i=0;i<20;i++)
{
if(i==0)
{
cout<<"#";
}
if(j==x && i==y)
{
cout<<"0";
}
else if(j==targetX && i==targetY)
{
cout<<"f";
}

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

}
}

for(int i=0;i<22;i++)
{
cout<<"#";
}
}

void Input()
{


}

void Logic()
{

}


int main()
{


set();
while(!GameOver)
// {
Draw();
// Input();
// Logic();
//
// }

return 0;
}
Last edited on
closed account (48T7M4Gy)
Well here's a tidied up version of your opus without changing anything, Mian Ziad.
It runs as you submitted. So the next step is to tell us what you expect it to do and why that is not what you wanted it to do.

Hint: Be as clear and specific as you can because just saying 'it doesn't work' is not a good way to be flooded with productive responses, or any at all :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>

using namespace std;

bool GameOver;
const int width=20;
const int height=20;
enum direction {STOP=0,LEFT,RIGHT,UP,DOWN};
direction dir;
int x,y,targetX,targetY,score;

void set()
{
    GameOver=false;
    dir=STOP;
    x=width/2;
    y=height/2;
    targetX=rand()%20;
    targetY=rand()%20;
    score=0;
}


void Draw()
{
    for(int i=0;i<22;i++)
    {
        cout<<"#";
    }
    cout<<endl;
    
    for(int j=0;j<20;j++)
    {
        for(int i=0;i<20;i++)
        {
            if(i==0)
            {
                cout<<"#";
            }
            if(j==x && i==y)
            {
                cout<<"0";
            }
            else if(j==targetX && i==targetY)
            {
                cout<<"f";
            }
            
            cout<<" ";
            if(i==width-1)
            {
                cout<<"#";
                cout<<endl;
            }
        }
    }
    
    for(int i=0;i<22;i++)
    {
        cout<<"#";
    }
}

void Input()
{
}

void Logic()
{
}


int main()
{
    set();
    while(!GameOver)
    {
        Draw();
    }
    
    return 0;
}
Last edited on
Topic archived. No new replies allowed.