Professional Documents
Culture Documents
I have simple code for snake game but it doesnt work..have many error when i compile it..hope anyone
can help me..thanks alot..
#include <stdio>
#include <stdlib>
#include <windows>
#include <conio>
#include <time>
#include <iostream>
void move(char main[][75], int &parts, int pastCounter, int past[][2], int &apples, int &score, int &quit);
int main()
int past[1000][2];
int parts = 3;
char main[23][75];
int pastCounter = 6;
int direction = 0;
int apples = 0;
int score = 0;
int quit = 0;
int playAgain = 1;
unsigned time;
srand(time(0));
past [x][y] = 0;
past[pastCounter][0] = 1;
past[pastCounter][1] = 1;
while(quit == 0)
draw(main, score);
check(direction);
reset(main);
if (apples == 0)
{
apple(apples, main);
quitGame(score);
system("cls");
cout<<"Score : %d\n"<<score;
cout<<"\n";
}
void reset(char main[][75])
if (main[x][y] == '@')
main[x][y] == '@';
else
if (x == 0 || x == 22 || y == 0 || y == 74)
main[x][y] = 177;
else
}
void move(char main[][75], int &parts, int pastCounter, int past[][2], int &apples, int &score, int &quit)
if (past[pastCounter][0] == 22 || past[pastCounter][0] == 0)
quit = 1;
if (past[pastCounter][1] == 74 || past[pastCounter][1] == 0)
quit = 1;
apples--;
parts++;
score += 10;
quit = 1;
else
{
main[past[pastCounter - x][0]][past[pastCounter - x][1]] = 'o';
int key = 0;
if (kbhit())
key = -getch();
switch (key)
case -72:
direction = 2;
break;
case -77:
direction = 0;
break;
case -80:
direction = 3;
break;
case -75:
direction = 1;
break;
}
}
int down;
right = past[pastCounter][1];
down = past[pastCounter][0];
switch (direction)
case 0:
right ++;
break;
case 1:
right --;
break;
case 2:
down --;
break;
case 3:
down ++;
pastCounter ++;
past[pastCounter][0] = down;
past[pastCounter][1] = right;
int up = 0;
int left = 0;
apples = 3;
up = (rand() % 22);
if (main[up][left] == 'o')
apple(apples, main);
if (main[up][left] == '*')
apple(apples, main);
else
main[up][left] = '@';
}
}
int quit = 0;
system ("cls");