Please don't provide the code for this as I do not want to plagiarize anybody's work. I need help understanding and using the code more than anything so I can write the code myself. Thanks in advance to anybody that can help.
So, I'm doing an assignment for my course and although I've done some programming before, I am completely new to C. The instructions for using the code are very unclear as well, considering we've never used this particular code library before (<conio.h>).
So like I said, I'm using the <conio.h> library (and of course <stdio.h>). My assignment is a snail game, where the snail is represent by an "*" and leaves a "." trail behind it when it moves. If the snail crosses its path, the score goes down. If it crosses an empty space, the score goes up. (The score is shown in the top corner). The snail cannot move outside the boundaries of the game screen (24 x 80).
So basically, I need help with developing the code. I've successfully managed to get the '*' to appear in the centre of the screen, but I need to know how the program can get a key from the keyboard (the NumPad arrow keys) to make the snail move in the corresponding directions. The assignment criteria sheet provides some code used to help (such as char getch()) but I have no clue how to interpret what they've written.
They provide us with these <conio.h> functions:
(As you can see, they provide us with what we can use, but not how to use them)- void clrscr() clear the (DOS) screen
- char getch() get a character from the keyboard without displaying it on the screen (blocking†)
- void putchxy(int x, int y, char c) place the character c on the screen at
coordinates (x,y)
- void gotoxy(int x, int y) move the cursor to the position at
coordinate (x,y)
- void cputsxy(int x, int y, char *s) print the string pointed to by s on
the screen at (x,y)
- _conio_gettext(int x, int y, int x2, int y2, char *buffer) Go to position (x, y), select all characters between (x, y) and (x2, y2) and copy them into the char array called buffer. NOTE: if x==x2 and y==y2, only one character (at (x,y)) will be copied. You must first create a char array to receive the copied character(s). For this assignment, a buffer with a size of [4] will be sufficient.
Please, like I said before, do not provide the code to do my assignment. I must write it all myself. I need explanations on how to write up my code. Heck, maybe even simple "English" explanations of what those functions are, what they do and how to use them will be enough for me to do it all myself.
So anyway, thanks in advance. I really hope this isn't asking too much (or too little. I'm kinda new here if you hadn't noticed.)


LinkBack URL
About LinkBacks




Reply With Quote


So for example, a 2-dimentional array of bools for dots (the trail) and x,y integers for asterisk (the slurm) will do. And some integer for score, obviously. I am sure you figured those out already. 






Bookmarks