I'm having a problem with my code.
It's is a game where you have to control the turtle without seeing where it is. But it won't control, it's stuck where it randomly starts. I've been scanning the code for hours, but I can't find the problem
Code:
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define ROW 25
#define COL 30
void title()
{
printf("\nWELCOME TO...\n\n");
printf("\t\t88888888888 888 888 \n");
printf("\t\t 888 888 888 \n");
printf("\t\t 888 888 888 888d888 888888 888 .d88b. \n");
printf("\t\t 888 888 888 888P* 888 888 d8P Y8b \n");
printf("\t\t 888 888 888 888 888 888 88888888 \n");
printf("\t\t 888 Y88b 888 888 Y88b. 888 Y8b. \n");
printf("\t\t 888 *Y88888 888 *Y888 888 *Y8888 \n\n");
printf("\t\t\t .d8888b. d8b \n");
printf("\t\t\td88P Y88b Y8P \n");
printf("\t\t\t888 888 \n");
printf("\t\t\t888 888d888 888 88888b. \n");
printf("\t\t\t888 88888 888P* 888 888 *88b \n");
printf("\t\t\t888 888 888 888 888 888 \n");
printf("\t\t\tY88b d88P 888 888 888 d88P \n");
printf("\t\t\t *Y8888P88 888 888 88888P* \n");
printf("\t\t\t 888 \n");
printf("\t\t\t 888 \n");
printf("\t\t\t 888 \n\n");
}
void instructions()
{
printf(" Task:\n");
printf(" The turtle is having his time swimming around the sea.\n He wants your help in guiding him under the sea and on the surface.\n");
printf("\n Controls:\n");
printf(" 8 - Up \n");
printf(" 2 - Down \n");
printf(" 4 - Left \n");
printf(" 6 - Right \n");
printf(" 7 - Pen Down \n");
printf(" 5 - Pen Up \n");
}
void menu()
{
printf("\t\t\t Press 1 to play the game.\n");
printf("\t\t\tPress 2 to view instructions.\n");
printf("\t\t\t Press 3 to to quit.\n");
}
int print(char a[ROW][COL])
{
int x,y;
system("cls");
for(x=0;x<ROW;x++)
{
printf("\t\t\t");
for(y=0;y<COL;y++)
{
printf("%c",a[x][y]);
}
printf("\n");
}
return a[ROW][COL];
}
int clear(char a[ROW][COL])
{
int x,y;
for(x=1;x<=ROW;x++)
{
for(y=1;y<=COL;y++)
{
a[x][y]=NULL;
}
}
for(x=0;x<COL;x++)
{
a[0][x]=178;
}
for(x=0;x<ROW;x++)
{
a[x][0]=178;
}
for(x=0;x<ROW;x++)
{
a[x][29]=178;
}
for(x=0;x<COL;x++)
{
a[24][x]=178;
}
return a[ROW][COL];
}
int controls (char a[ROW][COL],int row,int col)
{
int i=0,
int row2=row;
int col2=col;
int move;
do
{
move=getch();
clear(a);
switch(move)
{
case 2: row2=row2+1;
if(row2==24 || row2==0)
{
system("cls");
printf("\n\n\t\t BOOOM!");
printf("\n\n\t\t Game Over!:P");
i++;
}
else
{
a[row2][col2]='O';
print(a);
printf("\n\t\t\t\tControls:\n\t\t 8 - up // 4 - Left // 6 - Right // 2 - Down // 5 - Pen Down // 7 - Pen Up ");
}break;
case 4: col2=col2-1;
if(col2==29 || col2==0)
{
system("cls");
printf("\n\n\t\t BOOOM!");
printf("\n\n\t\t Game Over!:P");
i++;
}
else
{
a[row2][col2]='O';
print(a);
printf("\n\t\t\t\tControls:\n\t\t 8 - up // 4 - Left // 6 - Right // 2 - Down // 5 - Pen Down // 7 - Pen Up ");
}break;
case 5:a[row2][col2]=' ';
print(a);break;
case 6: col2=col2+1;
if(col2==29 || col2==0)
{
system("cls");
printf("\n\n\t\t BOOOM!");
printf("\n\n\t\t Game Over!:P");
i++;
}
else
{
a[row2][col2]='O';
print(a);
printf("\n\t\t\t\tControls:\n\t\t 8 - up // 4 - Left // 6 - Right // 2 - Down // 5 - Pen Down // 7 - Pen Up ");
} break;
case 7: a[row2][col2]='O';
print(a);break;
case 8: row2=row2-1;
if(row2==24 || row2==0)
{
system("cls");
printf("\n\n\t\t BOOOM!");
printf("\n\n\t\t Game Over!:P");
i++;
}
else
{
a[row2][col2]='O';
print(a);
printf("\n\t\t\t\tControls:\n\t\t 8 - up // 4 - Left // 6 - Right // 2 - Down // 5 - Pen Down // 7 - Pen Up ");
}break;
}
}while(i==0);
return 0;
}
main()
{
int ans,row,col;
char a[ROW][COL];
time_t t;
system("color 0A");
start:
title();
menu();
printf("\t\t\t\tYour option: ");
scanf("%d",&ans);
switch(ans)
{
case 1: system("cls");
clear(a);
srand((unsigned) time (&t));
row = rand()%25 +1;
col = rand()%30 +1;
a[row][col]=' ';
print(a);
controls(a,row,col);
//printf("bleh\n");
break;
case 2: system("cls");
instructions();
printf("\n Press enter to return to the menu.");
getch();
system("cls");
goto start;break;
case 3: system("cls");
printf("\t\t\t \nGoodbye!:D\n\n\n\n");break;
}
return 0;
}