三、静态创建贪吃蛇身子

1.先创建一个蛇结点

  1 #include<curses.h>
  2 
  3 struct NodeofSnake
  4 {
  5         int hang;
  6         int lie;
  7         struct NodeofSnake *next;
  8 };
  9 
 10 struct NodeofSnake node1 ={2,2,NULL};
 11 
 12 int wheatherOfSnakeNode(int hang,int lie)
 13 {
 14         if(hang==node1.hang && lie==node1.lie ){
 15                 printw("[]");
 16                 return 1;
 17         }
 18         return 0;
 19 }
 20 
 21 void initMap()
 22 {
 23         int hang=0;
 24         int lie =0;
 25 
 26         for(hang=0;hang<=20;hang++){
 27                 if(hang==0||hang==20){
 28                         for(lie=0;lie<20;lie++){
 29                                 printw("--");
 30                         }
 31                         printw("\n");
 32                 }
 33                 if(hang>0&&hang<=19){
 34                         for(lie=0;lie<=20;lie++){
 35                                 if(lie==0||lie==20){
 36                                         printw("|");
 37                                 }else if(wheatherOfSnakeNode(hang,lie)){
 38 
 39                                 }
 40                                 else{
 41                                         printw("  ");
 42                                 }
 43                         }
 44                         printw("\n");
 45                 }
 46         }
 47         printw("By:GuoMing\n");
 48 }
 49 
 50 int main()
 51 {
 52         initscr();
 53        
 54         initMap();
 55 
 56         getch();
 57         endwin();
 58 
 59         return 0;
 60 }

2.创建多个蛇结点

  1 #include<curses.h>
  2 
  3 struct NodeofSnake
  4 {
  5         int hang;
  6         int lie;
  7         struct NodeofSnake *next;
  8 };
  9 
 10 struct NodeofSnake node1 ={2,2,NULL};
 11 struct NodeofSnake node2 ={2,3,NULL};
 12 struct NodeofSnake node3 ={2,4,NULL};
 13 struct NodeofSnake node4 ={2,5,NULL};
 14 
 15 int wheatherOfSnakeNode(int hang,int lie)
 16 {
 17           struct NodeofSnake *point = &node1;
 18           while(point!=NULL){
 19                   if(hang==point->hang && lie==point->lie ){
 20                          printw("[]");
 21                          return 1;
 22                   }
 23                   point=point->next;
 24           }
 25         return 0;
 26 }
 27 
 28 void initMap()
 29 {
 30         int hang=0;
 31         int lie =0;
 32 
 33         for(hang=0;hang<=20;hang++){
 34                 if(hang==0||hang==20){
 35                         for(lie=0;lie<20;lie++){
 36                                 printw("--");
 37                         }
 38                         printw("\n");
 39                 }
 40                 if(hang>0&&hang<=19){
 41                         for(lie=0;lie<=20;lie++){
 42                                 if(lie==0||lie==20){
 43                                         printw("|");
 44                                 }else if(wheatherOfSnakeNode(hang,lie)){
 45 
 46                                 }
 47                                 else{
 48                                         printw("  ");
 49                                 }
 50                         }
 51                         printw("\n");
 52                 }
 53         }
 54         printw("By:GuoMing\n");
 55 }
 56 
 57 int main()
 58 {
 59         initscr();
 60 
 61         node1.next = &node2;
 62         node2.next = &node3;
 63         node3.next = &node4;
 64 
 65         initMap();
 66 
 67         getch();
 68         endwin();
 69 
 70         return 0;
 71 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值