Snake
Snake
/* Author : Lochh2@fpt.com */
/*-------------------------*/
/* Include library */
#include <iostream>
#include <vector>
#include <conio.h>
#include <windows.h>
#include <cstring>
#include <time.h>
#include <random>
/* Declare function */
void init_wall(void);
void draw_screen(void);
void draw_snake(void);
void apple();
void interf();
void interf_start();
void select();
void gameover();
void start_game();
void gotoxy(int x, int y);
bool isAte();
bool dead();
int random(void);
/* Select Director */
enum Direction
{
UP,
DOWN,
LEFT,
RIGHT
};
Direction g_direction = Direction::RIGHT; /* Defaut direction is RIGHT */
struct point
{
int x;
int y;
};
/* Global Variable */
char g_screen[20][41] = {' '}; /* Charactor will be print in the screen */
float g_level = 6.0; /* Number to calculate delay time */
int g_score = 0; /* Score */
point g_apple{ 0,0 }; /* Storage random apple */
std::vector<point> g_snake = /* Init snake at start game */
{
point{8,10},
point{8,9},
point{8,8},
point{8,7},
};
}
void start_game()
{
apple(); /* Creat random
Apple */
while (true)
{
if (_kbhit()) /* Key press
detection */
{
char f_ch = _getch(); /* Read and assignment to
g_direction */
f_ch = tolower(f_ch);