SNAKE GAME IN C

  -  

*

Introduction

This Snake trò chơi Mini Project in C is a basic console program with no graphics. You may play the famous "Snake Game" in this project exactly as you would anywhere else. Khổng lồ move the snake, use the up, down, right, and left arrows.

Bạn đang xem: Snake game in c

Food is placed at various co-ordinates on the screen for the snake lớn consume. The snake"s length and score will both rise by one element each time it consumes the food.

Source Code for Snake trò chơi Project Using C Language

#include #include #include #include #include#include#include #include #include #define UP 72#define DOWN 80#define LEFT 75#define RIGHT 77int length;int bend_no;int len;char key;void record();void load();int life;void Delay(long double);void Move();void Food();int Score();void Print();void gotoxy(int x, int y);void GotoXY(int x,int y);void Bend();void Boarder();void Down();void Left();void Up();void Right();void ExitGame();int Scoreonly();struct coordinate int x; int y; int direction;;typedef struct coordinate coordinate;coordinate head, bend<500>,food,body<30>;int main() char key; Print(); system("cls"); load(); length=5; head.x=25; head.y=20; head.direction=RIGHT; Boarder(); Food(); //to generate food coordinates initially life=3; //number of extra lives bend<0>=head; Move(); //initialing initial bend coordinate return 0;void Move() int a,i; bởi void Food() if(head.x==food.x&&head.y==food.y) length++; time_t a; a=time(0); srand(a); food.x=rand()%70; if(food.x"); else printf("*"); /*body.x=head.x-i; body.y=head.y;*/ len++; Bend(); if(!kbhit()) head.x++;void Bend() int i,j,diff; for(i=bend_no; i>=0&&len0) for(j=1; j0) for(j=1; j Use arrow keys khổng lồ move the snake. -> You will be provided foods at the several coordinates of the screen which you have to eat. Everytime you eat a food the length of the snake will be increased by 1 element and thus the score. -> Here you are provided with three lives. Your life will decrease as you hit the wall or snake"s body. -> YOu can pause the game in its middle by pressing any key. To continue the paused trò chơi press any other key once again -> If you want lớn exit press esc. "); printf(" Press any key to play game..."); if(getch()==27) exit(0);void record(){ char plname<20>,nplname<20>,cha,c; int i,j,px; file *info; info=fopen("record.txt","a+"); getch(); system("cls"); printf("Enter your name "); scanf("%<^ >",plname); //************************ for(j=0; plname!=""; j++) //to convert the first letter after space to lớn capital nplname<0>=toupper(plname<0>); if(plname==" ") nplname=toupper(plname); nplname=plname; else nplname=plname; nplname=""; //***************************** //sdfprintf(info," Players List "); fprintf(info,"Player Name :%s ",nplname); //for date and time time_t mytime; mytime = time(NULL); fprintf(info,"Played Date:%s",ctime(&mytime)); //************************** fprintf(info,"Score:%d ",px=Scoreonly());//call score lớn display score //fprintf(info," Level:%d ",10);//call màn chơi to display màn chơi for(i=0; i

Output

*

Explanation

In C, the following functions are utilized in the Snake game Project:In this Snake mini project, a variety of functionalities were employed. I"ll simply danh sách them and explain the functions "gotoxy," "GotoXY," & "delay" since they"re some of the most significant functions used in this và many other C small projects.

Xem thêm: Cách Chơi Game Rules Of Survival Cách Chơi, Cách Chơi Game Rules Of Survival Trên Máy Tính

void record()void load()void Delay(long double)void Move()void Food()void Print()void Bend()int Score()void Boarder()void Down()void Left()void Up()void Right()void ExitGame()

gotoxy (int x, int y) – void gotoxy (int x, int y) – This is an essential function to learn since it is utilized in the Snake trò chơi mini project in C. This feature enables you khổng lồ print text wherever on the screen.

Final Words

To summarize, this C mini project on Snake lets you khổng lồ keep track of the player"s name and the score they earned. This has been accomplished via the usage of tệp tin handling.

Xem thêm: Game Siêu Nhân Phép Thuật Đi Cảnh Đánh Quái Vật, Siêu Nhân Phép Thuật Đi Cảnh Đánh Quái Vật

If you"re seeking for a reference project or want lớn make your own C small project game, this mini project may undoubtedly assist. It is strongly discouraged khổng lồ submit this project with few or no changes.