首页
星云
工具
资源
星选
资讯
热门工具
自选颜色
:
PDF转图片
完全免费
小红书视频下载
无水印
抖音视频下载
无水印
数字星空
菜鸟重生之我要做嵌入式工程师:2-C语言【所有项目代码】
物联网
1.05MB
7
需要积分: 1
立即下载
资源介绍:
该资源包含本人初学C语言以来的所有代码,适合小白入手,主要包括: 1.环境及编译器的安装 2.基础语法的练习 3.指针的学习 4.linuxc编程的引入 5.结构体的练习
#include
//头文件 #include
#include
#define UP 1 #define DOWN -1 #define LEFT 2 #define RIGHT -2 int key; int DIR; struct Snake { int x; int y; struct Snake* next; }; struct Food { int x; int y; }; struct Food food = {2,2}; struct Snake* snakeHead=NULL; struct Snake* snakeTail=NULL; void addNodeBehind() { struct Snake* new =(struct Snake*)malloc(sizeof(struct Snake)); new->x=snakeTail->x; new->y=(snakeTail->y)+1; new->next=NULL; snakeTail->next=new; snakeTail=new; } void snakeDie(struct Snake* snakeHead) { while(snakeHead!=NULL) { struct Snake* p =snakeHead; snakeHead=snakeHead->next; free(p); p=NULL; } } void initSnake() { snakeDie(snakeHead); snakeHead=(struct Snake*)malloc(sizeof(struct Snake)); snakeTail=(struct Snake*)malloc(sizeof(struct Snake)); snakeHead->x=1; snakeHead->y=15; snakeHead->next=NULL; snakeTail=snakeHead; addNodeBehind(); addNodeBehind(); addNodeBehind(); DIR=LEFT; } void judgeSnakeKillItself() { struct Snake* p=snakeHead->next; while(p!=NULL) { if(snakeHead->x==p->x&&snakeHead->y==p->y) { initSnake(); } else { p=p->next; } } } bool judgePos(struct Snake* snakeHead) { while(snakeHead!=NULL) { if((snakeHead->x==0||snakeHead->y==0||snakeHead->x==19||snakeHead->y==19)) { return false; } snakeHead=snakeHead->next; } return true; } void deleteHeadNode() { struct Snake* p=snakeHead; snakeHead=snakeHead->next; free(p); p=NULL; } void snakeRight() { deleteHeadNode(); addNodeBehind(); if(judgePos(snakeHead)==false) { initSnake(); } } void deleteTailNode() { struct Snake* p=snakeTail; struct Snake* headTemp=snakeHead; while(headTemp->next!=snakeTail) { headTemp=headTemp->next; } headTemp->next=NULL; snakeTail=headTemp; free(p); p=NULL; } void addNodeBefore() { struct Snake* new =(struct Snake*)malloc(sizeof(struct Snake)); switch(DIR) { case UP: new->x=snakeHead->x-1; new->y=(snakeHead->y); break; case DOWN: new->x=snakeHead->x+1; new->y=(snakeHead->y); break; case LEFT: new->x=snakeHead->x; new->y=(snakeHead->y)-1; break; case RIGHT: new->x=snakeHead->x; new->y=(snakeHead->y)+1; break; default: break; } new->next=snakeHead; snakeHead=new; } void snakeLeft() { addNodeBefore(); deleteTailNode(); if(judgePos(snakeHead)==false) { initSnake(); } } bool scanSnake(struct Snake* snakeHead,int row,int column) { int i=0; while(snakeHead!=NULL) { if(row==snakeHead->x&&column==snakeHead->y) { return true; } else { snakeHead=snakeHead->next; } } return false; } bool scanFood(struct Food food,int row,int column) { if(food.x==row&&food.y==column) { return true; } return false; } void initMyscr() { initscr();//ncruse界面的初始化函数 printw("snake\n");//在ncruse模式下的printf keypad(stdscr,1); initSnake(); } void GameMap() { int row; int column; move(1,0); for(row=0;row<20;row++) { if(row==0||row==19) { for(column=0;column<20;column++) { printw("##"); } } else { for(column=0;column<20;column++) { if(column==0) { printw("#>"); } else if(column==19) { printw("<#"); } else { if(true==scanSnake(snakeHead,row,column)) { printw("[]"); } else if(true==scanFood(food,row,column)) { printw("**"); } else { printw(" "); } } } } printw("\n"); } printw("BY ZHW\n"); } void snakeEatFood() { if(snakeHead->x==food.x&&snakeHead->y==food.y) { addNodeBehind(); struct Snake* p=snakeHead; food.x=rand()%18; food.y=rand()%18; while(p!=NULL) { while((p->x==food.x&&p->y==food.y)||food.x==0||food.y==0) { food.x=rand()%18; food.y=rand()%18; } p=p->next; } } } void* refreshMap() { while(1) { refresh(); usleep(100000); snakeLeft(); GameMap(); snakeEatFood(); judgeSnakeKillItself(); } } void posCheck(int newPos) { if(abs(DIR)!=abs(newPos)) { DIR=newPos; } } void* keyScanf() { while(1) { key=getch(); switch(key) { case KEY_UP: posCheck(UP); break; case KEY_DOWN: posCheck(DOWN); break; case KEY_LEFT: posCheck(LEFT); break; case KEY_RIGHT: posCheck(RIGHT); break; default: break; } } } int main() { initMyscr(); pthread_t p1; pthread_t P2; pthread_create(&p1,NULL,refreshMap,NULL); pthread_create(&P2,NULL,keyScanf,NULL); while(1); endwin();//程序退出,恢复终端shell,没有这句话的话终端会出现乱码。(终端会混乱) return 0; }
资源文件列表:
1-c语言.zip 大约有134个文件
1-c语言/
1-c语言/._0-hello.c 4KB
1-c语言/0-hello.c 61B
1-c语言/0-hello.exe 52.76KB
1-c语言/0-project/
1-c语言/0-project/1-snake/
1-c语言/0-project/1-snake/a.out 13.41KB
1-c语言/0-project/1-snake/snake.c 4.8KB
1-c语言/0-project/1-snake/snakeSelf.c 4.68KB
1-c语言/1-printf.c 248B
1-c语言/1-printf.exe 52.76KB
1-c语言/10-factorial.c 267B
1-c语言/10-factorial.exe 53.12KB
1-c语言/11-arryAndFun.c 403B
1-c语言/11-arryAndFun.exe 52.79KB
1-c语言/12-introPtr.c 252B
1-c语言/12-introPtr.exe 52.78KB
1-c语言/13-fun&Arrys.c 827B
1-c语言/13-fun&Arrys.exe 54.17KB
1-c语言/14-ptr.c 539B
1-c语言/14-ptr.exe 52.76KB
1-c语言/15-ptrSwap.c 245B
1-c语言/15-ptrSwap.exe 52.78KB
1-c语言/16-ptrArea.c 335B
1-c语言/16-ptrArea.exe 52.76KB
1-c语言/17-ptrArry.c 327B
1-c语言/17-ptrArry.exe 53.11KB
1-c语言/18-ptrArryReversal.c 584B
1-c语言/18-ptrArryReversal.exe 54.19KB
1-c语言/19-ptrArrys.c 540B
1-c语言/19-ptrArrys.exe 52.76KB
1-c语言/2-puts.c 128B
1-c语言/2-puts.exe 52.92KB
1-c语言/20-printfPtrArrrys.c 247B
1-c语言/20-printfPtrArrrys.exe 53.12KB
1-c语言/21-arryPtr.c 558B
1-c语言/21-arryPtr.exe 54.31KB
1-c语言/22-funPrt.c 318B
1-c语言/22-funPrt.exe 53.47KB
1-c语言/23-funPrtUse.c 569B
1-c语言/23-funPrtUse.exe 53.65KB
1-c语言/24-ptrArry.c 428B
1-c语言/24-ptrArry.exe 53.65KB
1-c语言/25-ptrArry-2.c 353B
1-c语言/25-ptrArry-2.exe 53.63KB
1-c语言/26-ptrFun.c 348B
1-c语言/26-ptrFun.exe 53.11KB
1-c语言/27-doublePtr.c 740B
1-c语言/27-doublePtr.exe 53.26KB
1-c语言/28-doublePtr-2.c 331B
1-c语言/28-doublePtr-2.exe 53.11KB
1-c语言/29-doublePtrDoubleArry.c 253B
1-c语言/29-doublePtrDoubleArry.exe 53.12KB
1-c语言/3-arry.c 280B
1-c语言/3-arry.exe 53.1KB
1-c语言/30-steCopy.c 440B
1-c语言/30-steCopy.exe 52.94KB
1-c语言/31-strNCopy.c 429B
1-c语言/31-strNCopy.exe 52.94KB
1-c语言/32-strCat.c 520B
1-c语言/32-strCat.exe 53.44KB
1-c语言/33-strCmp.c 335B
1-c语言/33-strCmp.exe 52.78KB
1-c语言/34-structEX.C 1.08KB
1-c语言/34-structEX.exe 53.94KB
1-c语言/35-structPtrArry.c 1.47KB
1-c语言/35-structPtrArry.exe 54.52KB
1-c语言/36-structPtr.c 1.8KB
1-c语言/36-structPtr.exe 54.88KB
1-c语言/37-doubleStrucPtr.c 1.8KB
1-c语言/37-doubleStrucPtr.exe 54.9KB
1-c语言/38-union.c 713B
1-c语言/38-union.exe 53.77KB
1-c语言/39-link.c 270B
1-c语言/39-link.exe 8.18KB
1-c语言/4-bubble.c 394B
1-c语言/4-bubble.exe 52.76KB
1-c语言/40-linkPrintf.c 334B
1-c语言/40-linkPrintf.exe 8.28KB
1-c语言/41-linkFind.c 497B
1-c语言/41-linkFind.exe 8.33KB
1-c语言/42-linkInsert .c 1.17KB
1-c语言/42-linkInsert.exe 54.37KB
1-c语言/43-linkDelete.c 1.11KB
1-c语言/43-linkDelete.exe 54.33KB
1-c语言/44-linkCreat.c 712B
1-c语言/44-linkCreat.exe 53.83KB
1-c语言/45-linkCreatBehind.c 971B
1-c语言/45-linkCreatBehind.exe 54.35KB
1-c语言/46-linkCreatNew.c 792B
1-c语言/46-linkCreatNew.exe 53.86KB
1-c语言/47-linkCreatBehindNew.c 914B
1-c语言/47-linkCreatBehindNew.exe 54.39KB
1-c语言/48-linkChange.c 1.3KB
1-c语言/48-linkChange.exe 54.39KB
1-c语言/49-pthread.c 515B
1-c语言/5-simpleSelection.c 389B
1-c语言/5-simpleSelection.exe 52.78KB
1-c语言/6-arrys.c 231B
1-c语言/6-arrys.exe 52.93KB
1-c语言/7-maxOfArrys.c 386B
1-c语言/7-maxOfArrys.exe 52.76KB
1-c语言/8-fun.c 262B
1-c语言/8-fun.exe 53.11KB
1-c语言/9-recursion.c 286B
1-c语言/9-recursion.exe 53.12KB
1-c语言/a.exe 53.64KB
1-c语言/homework/
1-c语言/homework/1-counter.c 242B
1-c语言/homework/1-counter.exe 53.1KB
1-c语言/homework/10-funBubble.c 716B
1-c语言/homework/10-funBubble.exe 54.31KB
1-c语言/homework/11-funSimpleSelection.c 630B
1-c语言/homework/11-funSimpleSelection.exe 54.34KB
1-c语言/homework/12-ptrSwap.c 440B
1-c语言/homework/12-ptrSwap.exe 53.79KB
1-c语言/homework/13ptrFun.c 507B
1-c语言/homework/13ptrFun.exe 52.79KB
1-c语言/homework/2-toggle case.c 240B
1-c语言/homework/2-toggle case.exe 53.1KB
1-c语言/homework/3-if.c 289B
1-c语言/homework/3-if.exe 53.1KB
1-c语言/homework/4-ifelse.c 272B
1-c语言/homework/4-ifelse.exe 53.1KB
1-c语言/homework/5-break.c 442B
1-c语言/homework/5-break.exe 53.1KB
1-c语言/homework/6-continue.c 134B
1-c语言/homework/6-continue.exe 52.76KB
1-c语言/homework/7-ex.c 551B
1-c语言/homework/7-ex.exe 53.1KB
1-c语言/homework/8-ex.c 274B
1-c语言/homework/8-ex.exe 52.76KB
1-c语言/homework/9-funEx.c 470B
1-c语言/homework/9-funEx.exe 53.15KB
0评论
提交
取消回复
加载更多评论
其他资源
计算机程序设计员三级考试第三题
计算机程序设计员三级考试
计算机程序设计员三级考试第四题
计算机程序设计员三级考试
chromedriver-mac-arm64-133.0.6898.0 (1).zip
chromedriver-mac-arm64-133.0.6898.0 (1)
chromedriver-mac-arm64-133.0.6900.0.zip
chromedriver-mac-arm64-133.0.6900.0
vue2+Canvas+动态EDG数据+心电监护仪
使用vue2,利用自己封装的Canvas,实现心电监护仪的效果,数据是动态绘制,下载就可运行。
菜鸟重生之我要做嵌入式工程师:2-C51【所有项目代码】
该资源包括本人学习C51的过程中的所有代码,主要包括: 1.开发环境的搭建 2.c51单片机常用的IO口、串口、中断、定时器等 3.IIC协议、LCD1602、DHT11非标协议等 4.嵌入式常用外设(ESP8266\4G模块\语音识别模块\蓝牙模块等)
ros2-driver.zip
dddddddddaa
HC-SR04使用手册
HC-SR04超声波_原理图--.pdf HC-SR04超声波测距模块说明书--.pdf 超声波模块参考--.pdf