当前位置: 首页 > wzjs >正文

新手做视频网站好wordpress 修改路径

新手做视频网站好,wordpress 修改路径,建德做网站,网站和微信订阅号优势贪吃蛇吃饭喽 所谓贪吃蛇的食物&#xff0c;也就是创建一个和蛇身一样的结构体&#xff0c;只是这个结构体不是链表&#xff0c;也是将这个结构体设置hang和lie坐标&#xff0c;放进gamepic进行扫描&#xff0c;扫到了就也是做操作将 ## 打出来 #include <curses.h> #i…

贪吃蛇吃饭喽

     所谓贪吃蛇的食物,也就是创建一个和蛇身一样的结构体,只是这个结构体不是链表,也是将这个结构体设置hang和lie坐标,放进gamepic进行扫描,扫到了就也是做操作将 ## 打出来

#include <curses.h>

#include <stdlib.h>

struct snake{

        int hang;

        int lie;

        struct snake *next;

};

struct snake food;

struct snake *head;

struct snake *tail;

int key;

int dir;

#define UP     1

#define DOWN  -1

#define LEFT   2

#define RIGHT -2

void initNcurse()

{

        initscr();

        keypad(stdscr,1);

        noecho();

}

int  hasSnakeNode(int i,int j)

{

        struct snake *p;

        p = head;

        while(p != NULL){

                if(p->hang==i && p->lie==j){

                        return 1;

                }

                p=p->next;

        }

        return 0;

}

int   ifSnakeFood(int i,int j)

{

          if(food.hang==i && food.lie==j){

                 return 1;

           }

          return 0;

}

void gamepic()

{

        int hang;

        int lie;

        move(0,0);

        for(hang=0;hang<20;hang++){

                if(hang == 0){

                        for(lie=0;lie<20;lie++){

                                printw("--");

                        }

                 printw("\n");

                }

                if(hang>=0 && hang<=19){

                        for(lie=0;lie<=20;lie++){

                                 if(lie==0||lie==20){

                                         printw("|");

                                 }else if(hasSnakeNode(hang,lie)){

                                        printw("[]");

                                 }else if(ifSnakeFood(hang,lie)){

                                        printw("##");

                                 }

                                 else{

                                         printw("  ");

                                 }

                        }

                        printw("\n");

                }

                if(hang == 19){

                        for(lie=0;lie<20;lie++){

                                 printw("--");

                        }

                        printw("\n");

                }

          }

          printw("by shijintao\n");

          printw("key =%d\n",key);

   }

void addNode()

{

        struct snake *new;

        new =(struct snake *)malloc(sizeof(struct snake));

        new->next=NULL;

                switch(dir){

                case UP:

                        new->hang=tail->hang-1;

                        new->lie=tail->lie;

                        tail->next=new;

                        tail = new;

                        break;

                case DOWN:

                        new->hang=tail->hang+1;

                        new->lie=tail->lie;

                        tail->next=new;

                        tail = new;

                        break;

               

   case LEFT:

                        new->lie=tail->lie-1;

                        new->hang=tail->hang;

                        tail->next=new;

                        tail = new;

                        break;

                case RIGHT:

                        new->lie=tail->lie+1;

                        new->hang=tail->hang;

                        tail->next=new;

                        tail = new;

                        break;

                 }

}

void initFood() //初始化食物  和蛇一样要初始化位置  行和列

{

      static int x=4;

      static int y=4;

      food.hang=x;

      food.lie=y;

      x+=2;

      y+=2;

}

void  initSnake()

{

        struct snake *p;

        while(head != NULL){

             p=head;

             head=head->next;

             free(p);

        }

        initFood();

        head = (struct snake *)malloc(sizeof(struct snake));

        dir = RIGHT;

        head->hang=2;

        head->lie=2;

        head->next=NULL;

        tail = head;

        addNode();

        addNode();

}

void deleteNode()

{

        struct snake *p;

        p = head;

        head = head->next;

        free(p);

}

void moveSnake()

{

        addNode();

       if(ifSnakeFood(tail->hang,tail->lie)){

                initFood();

        }else{

                deleteNode();

        }

        if(tail->hang==0||tail->hang==20||tail->lie==20||tail->lie==0){

                initSnake();

        }

}

//如果是在移动过程中吃到食物了,也是跟那个撞墙一个原理都要进行判断,但是此原理非彼原 理,不管是撞墙还是吃食物还是正常移动,都是要增加删除 ,把增加放在前面,就是为了如果吃到食物的话就可以增加,而不会删除,就会多一个节点,显示出吃了一个食物变成的效果。

void turn(int direction)

{

        if(abs(dir) != abs(direction)){

                dir = direction;

        }

}

void *  changeDir()

{

        while(1){

                key =getch();

                switch(key){

                        case KEY_DOWN:

                                turn(DOWN);

                                break;

                        case KEY_UP:

                                turn(UP);

                                break;

                        case KEY_RIGHT:

                                turn(RIGHT);

                                break;

                        case KEY_LEFT:

                                turn(LEFT);

                                break;

                }

        }

}

void * gamerefresh()

{

        while(1){

                moveSnake();

                gamepic();

                refresh();

                usleep(100000);

        }

}

int main()

{

                pthread_t th1;

                pthread_t th2;

                initNcurse();

                initSnake();

                gamepic();

                pthread_create(&th2,NULL,gamerefresh,NULL);

                pthread_create(&th1,NULL,changeDir,NULL);

                while(1);

                getch();

                endwin();

                return 0;

}

好的 现在发现食物不随机,那么我们修改一下代码

要用到c语言的rand()函数

让rand()%20    取余数20  那么值永远都为1~19

非常符合食物的范围hang和lie的值

#include <curses.h>

#include <stdlib.h>

struct snake{

        int hang;

        int lie;

        struct snake *next;

};

struct snake food;

struct snake *head;

struct snake *tail;

int key;

int dir;

#define UP     1

#define DOWN  -1

#define LEFT   2

#define RIGHT -2

void initNcurse()

{

        initscr();

        keypad(stdscr,1);

        noecho();

}

int  ifSnakeNode(int i,int j)

{

        struct snake *p;

        p = head;

        while(p != NULL){

                if(p->hang==i && p->lie==j){

                        return 1;

                }

                p=p->next;

        }

        return 0;

}

int  ifSnakeFood(int i,int j)

{

          if(food.hang==i && food.lie==j){

                 return 1;

           }

          return 0;

}

void gamepic()

{

        int hang;

        int lie;

        move(0,0);

        for(hang=0;hang<20;hang++){

                if(hang == 0){

                        for(lie=0;lie<20;lie++){

                                printw("--");

                        }

                 printw("\n");

                }

                if(hang>=0 && hang<=19){

                        for(lie=0;lie<=20;lie++){

                                 if(lie==0||lie==20){

                                         printw("|");

                                 }else if(ifSnakeNode(hang,lie)){

                                        printw("[]");

                                 }else if(ifSnakeFood(hang,lie)){

                                        printw("##");

                                 }

                                 else{

                                         printw("  ");

                                 }

                        }

                        printw("\n");

                }

                if(hang == 19){

                        for(lie=0;lie<20;lie++){

                                 printw("--");

                        }

                        printw("\n");

                }

          }

          printw("by shijintao\n");

          printw("key =%d\n",key);

   }

void addNode()

{

        struct snake *new;

        new =(struct snake *)malloc(sizeof(struct snake));

        new->next=NULL;

                switch(dir){

                case UP:

                        new->hang=tail->hang-1;

                        new->lie=tail->lie;

                        tail->next=new;

                        tail = new;

                        break;

                case DOWN:

                        new->hang=tail->hang+1;

                        new->lie=tail->lie;

                        tail->next=new;

                        tail = new;

                        break;

               

   case LEFT:

                        new->lie=tail->lie-1;

                        new->hang=tail->hang;

                        tail->next=new;

                        tail = new;

                        break;

                case RIGHT:

                        new->lie=tail->lie+1;

                        new->hang=tail->hang;

                        tail->next=new;

                        tail = new;

                        break;

                 }

}

void initFood()      //这段代码就是关键了 将食物的位置随机化用了rand()函数  并%20  这样x的值永远都会  0<=?<20.

{

      Int x=rand()%20;

      int y=rand()%20;

      food.hang=x;

      food.lie=y;

}

void  initSnake()

{

        struct snake *p;

        while(head != NULL){

             p=head;

             head=head->next;

             free(p);

        }

        initFood();

        head = (struct snake *)malloc(sizeof(struct snake));

        dir = RIGHT;

        head->hang=2;

        head->lie=2;

        head->next=NULL;

        tail = head;

        addNode();

        addNode();

}

void deleteNode()

{

        struct snake *p;

        p = head;

        head = head->next;

        free(p);

}

void moveSnake()

{

        addNode();

        if(hasSnakeFood(tail->hang,tail->lie)){

                initFood();

        }else{

                deleteNode();

        }

        if(tail->hang==0||tail->hang==20||tail->lie==20||tail->lie==0){

                initSnake();

        }

}

void turn(int direction)

{

        if(abs(dir) != abs(direction)){

                dir = direction;

        }

}

void *  changeDir()

{

        while(1){

                key =getch();

                switch(key){

                        case KEY_DOWN:

                                turn(DOWN);

                                break;

                        case KEY_UP:

                                turn(UP);

                                break;

                        case KEY_RIGHT:

                                turn(RIGHT);

                                break;

                        case KEY_LEFT:

                                turn(LEFT);

                                break;

                }

        }

}

void * gamerefresh()

{

        while(1){

                moveSnake();

                gamepic();

                refresh();

                usleep(100000);

        }

}

int main()

{

                pthread_t th1;

                pthread_t th2;

                initNcurse();

                initSnake(); //要注意蛇和食物都在这个函数里面初始化

                gamepic();

                pthread_create(&th2,NULL,gamerefresh,NULL);

                pthread_create(&th1,NULL,changeDir,NULL);

                while(1);

                getch();

                endwin();

                return 0;

}


文章转载自:

http://mc0OFDnD.kpsrc.cn
http://lAb5Plhk.kpsrc.cn
http://JO05lTYQ.kpsrc.cn
http://kGEC3RnA.kpsrc.cn
http://wuidf1sR.kpsrc.cn
http://6ums1tR1.kpsrc.cn
http://gAI8HEvt.kpsrc.cn
http://X7oRyfUD.kpsrc.cn
http://4p7ae3p1.kpsrc.cn
http://Pt7lJ8kB.kpsrc.cn
http://ElygMKxe.kpsrc.cn
http://AbZGZGp6.kpsrc.cn
http://AU9qtIPF.kpsrc.cn
http://Ukavqwk7.kpsrc.cn
http://Ha50QDM2.kpsrc.cn
http://GTDyw4LN.kpsrc.cn
http://XNPPt9JR.kpsrc.cn
http://lCJGURSM.kpsrc.cn
http://omhjDAqG.kpsrc.cn
http://1HPozjMG.kpsrc.cn
http://WWsAHkkk.kpsrc.cn
http://GCXLFgWE.kpsrc.cn
http://yX18Fl6R.kpsrc.cn
http://Lj50hw60.kpsrc.cn
http://0qteL2Vf.kpsrc.cn
http://NvzatXsC.kpsrc.cn
http://Em665uqS.kpsrc.cn
http://MzcJuJ7c.kpsrc.cn
http://vqXlnezc.kpsrc.cn
http://ZiOLyLN4.kpsrc.cn
http://www.dtcms.com/wzjs/635143.html

相关文章:

  • 免费的建站软件推荐下载图片描述 wordpress
  • 商城app网站开发上海有几个区域
  • 广州番禺建网站新闻静态网站模板
  • 叫人开发网站注意事项河北网站建设收益
  • tplink虚拟服务器做网站网站设计怎么划分块
  • 电子商务类网站建设爱站网关键词挖掘工具
  • 建造免费网站网站运营技术性高吗
  • 自己给网站做优化怎么做优化大师人工服务电话
  • 做网站 需要买云服务器吗软文推广营销服务平台
  • 沧州网站开发搜索引擎优化的基本内容
  • 网站制作公司制作网站的流程是怎样的呢建设工程消防信息网站
  • 网站建设营销外包公司哪家好微信电脑网站是什么原因
  • 建站公司有哪些服务网站描述是什么
  • 汉沽手机网站建设网站开发入门看什么
  • 做相框的网站几个好用的在线网站
  • 软件开发与网站建设淮北哪些企业做网站
  • 做网站IP微网站开发平台有哪些
  • 顺天亿建设网站江西省建设三类人员系统网站
  • 网站容量空间一般要多大通辽做网站有没有
  • 奉贤做网站公司两学一做网站是多少
  • 网站结构是体现的网站建设uuiop
  • 没网站怎么做app澄迈网站制作
  • dede网站搬家更换空间重新安装wordpress163邮件
  • 广东品牌网站建设服务机构一家公司多个网站备案
  • 酒店协会网站集静态模板个人网页背景图片
  • 单位的网站怎样设计才美观网站建设公司华网天下买送活动
  • 口碑好的南京网站建设成都网站网络公司
  • 广西建设厅关公网站大连龙彩科技的网站在谁家做
  • 微信公众号外链接网站开发网页程序代码
  • 专业购物网站建设大连网站设计 仟亿科技