Commit f447d015 by hlaidv

Add new file

parent 05d21e0c
Showing with 107 additions and 0 deletions
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include <conio.h>
#include <stdbool.h>
#include <unistd.h>
#define width 20
#define height 20
#define menuWidth 40
#define menuHeight 5
enum direction {Stop, Left, Right, Up, Down};
bool started = false;
bool gameover = false;
int SnakeX, SnakeY;
int AppleX, AppleY;
void mypause ( void )
{
fflush ( stdout );
getchar();
started = true;
}
void menu() {
for (int i = 0; i < menuHeight; i++) {
for (int j = 0; j < menuWidth; j++) {
printf("#");
}
printf("\n");
}
printf("\n");
for (int i = 0; i < 15; i++) {
printf(" ");
}
printf("SNAKE GAME\n\n Press Enter to continue . . .\n\n");
for (int i = 0; i < menuHeight; i++) {
for (int j = 0; j < menuWidth; j++) {
printf("#");
}
printf("\n");
}
printf("\n");
mypause();
}
void setup() {
//direction = Stop;
srand(time(NULL));
//____Snake spawnpoint
SnakeX = width / 2;
SnakeY = height / 2;
//____Apple spawnpoint
AppleX = rand() % width;
AppleY = rand() % height;
}
void borders () {
system("clear"); //clearing console window
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (i == 0 || i == width - 1 || j == 0 || j == height - 1) {
printf("#");
}
else {
if (i == SnakeX && j == SnakeY)
printf("0");
else if (i == AppleX && j == AppleY)
printf("A");
else
printf(" ");
}
}
printf("\n");
}
}
void movement () {
}
int main()
{
setup();
while (gameover == false) {
if (!started) {
menu();
}
else {
borders();
movement();
//logic();
//tail();
sleep(1);
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment