I got it to work. Seems to work. Just forgot to active l-conio in my compiler and how void functions work.
My problem right now is digit detection. Here is my problem statement:
Problem Statement:
Using the <conio.h> library, use simple text characters to animate a pencil which leaves a pencil
trace on the screen. The pencil will respond to player input; moving around the screen as
the player directs. If the player presses the ESC key or if the player gets a negative score,
the game stops.
The aim of the game is to join the numbers IN ORDER from 0 to 9, using the most direct
and efficient route.
Relevant Equations
I got the cursor working (void putchxy) working, by using a while loop. Under that, I used if statements to set it so that the direction is controlled by the numeric keypad.
Function prototype declared:
void putchxy (int x, int y, char pencil);
Working solution
#include <stdio.h>
#include <conio.h>
/*Function prototype: */
void putchxy (int x, int y, int pencil); /* Places pencil at coordinates (x,y) */
void clrscr(); /* Clears screen */
void cputsxy(int x, int y, char *s); /* */
/* Main */
int main()
{
char name;
char move;
char *s;
int score = 200;
int nextnumber;
int x = 40;
int y = 12;
int pencil = '+';
printf ("The object of the game is to the cursor +\naround the screen using the direction pad on the numeric keypad.\nJoin the digits in an ascending order to get a good score\nStart with 0\nPress ESC anytime to exit\n\n");
printf("Please enter your username.\n");
scanf("%s",&name);
/* Clears Screen after prompt */
clrscr();
/* Print out borders of the game */
printf("Score: %i Go to: %i Username: %c\n",score, nextnumber, name);
printf(" /-----------------------------------------------------------------------------\\");
printf(" | 5 |");
printf(" | |");
printf(" | |");
printf(" | 1 3 |");
printf(" | |");
printf(" | |");
printf(" | 8 |");
printf(" | 0 |");
printf(" | |");
printf(" | |");
printf(" | |");
printf(" | 7 6 |");
printf(" | |");
printf(" | |");
printf(" | 2 |");
printf(" | 4 |");
printf(" | |");
printf(" | |");
printf(" | |");
printf(" | 9 |");
printf(" | |");
printf(" | |");
printf(" | 7 |");
printf("\\-----------------------------------------------------------------------------/");
while ((int)move !=27)
{
putchxy(x, y, pencil);
move = getch();
if (move == '8' && y > 1 )
{
y--;
}
else if (move =='2' && y <24)
{
y++;
}
else if (move =='4' && x > 2)
{
x--;
}
else if (move =='6' && x < 79)
{
x++;
}
}
return 0;
}
From what I've read, I think I may have to use to retrieve the value the cursor is on. The function prototype I may be able to use is:
void _conio_gettext(int x, int y, int x, int y, char buffer[]);
I'm guessing a do while loop could be used. The value will have to be stored somewhere so a char buffer is going to be used. I think that char buffer[4] is equivalent to holding 1 character. I don't know what to do from here.
Does the buffer collect the values of the spaces as well as the numbers that I randomly entered around the grid? Is the function prototype I'm using appropriate or should something else be used?
Hope you guys can help.
Thanks.