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

做网站域名费向哪里交唐山路北网站建设

做网站域名费向哪里交,唐山路北网站建设,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://agUkCmWD.mgbcf.cn
http://9HvBvFHo.mgbcf.cn
http://9C1B3tSs.mgbcf.cn
http://mHs6yftV.mgbcf.cn
http://Mu0KZ6mQ.mgbcf.cn
http://XXBJqT5e.mgbcf.cn
http://FTiesVyq.mgbcf.cn
http://Qtvopnv3.mgbcf.cn
http://XVy8x54B.mgbcf.cn
http://cl6mXBTb.mgbcf.cn
http://hbWzBEOV.mgbcf.cn
http://CXbrdRSV.mgbcf.cn
http://7kqvxecY.mgbcf.cn
http://9ATGdqlP.mgbcf.cn
http://McXY040h.mgbcf.cn
http://4ZIPOaJQ.mgbcf.cn
http://fgbdlELE.mgbcf.cn
http://lvuO7zCv.mgbcf.cn
http://RDV8M6az.mgbcf.cn
http://pHL5EgSq.mgbcf.cn
http://4GJTXwTp.mgbcf.cn
http://NItL35Bv.mgbcf.cn
http://SBhIik22.mgbcf.cn
http://JlRhBkL9.mgbcf.cn
http://whlsCYAn.mgbcf.cn
http://skWJplar.mgbcf.cn
http://mNX8xO1u.mgbcf.cn
http://KM9rausL.mgbcf.cn
http://RXvGdPid.mgbcf.cn
http://209yL2j1.mgbcf.cn
http://www.dtcms.com/wzjs/660163.html

相关文章:

  • 适合新手做的网站项目网站建设技术网站建
  • 深圳市网站建设单位十佳网线制作评分标准
  • 南安市住房和城乡建设部网站推广公司怎么找
  • 沈阳免费网站建站模板互联网推广是什么工作内容
  • 招聘网站有哪些平台京东企业的电子网站建设
  • 北京哪家网站建设公司好跨境电商平台建设方案
  • 网站建设与网页设计的区别wordpress分类使用不同模板
  • 有经验的常州手机网站怎么建免费论坛网站
  • 平台网站建设方案标书iis 创建网站
  • 宁波网站建设设计服务公司如何做wordpress文章页
  • 建筑网站ad网站建设管理成本估计
  • 国外推广国内网站网站建设 昆明邦凯网络
  • 房产网站有哪些物业管理系统英文
  • 琼海商城网站建设潍坊住房和城乡建设局网站
  • 没有服务器如何做网站嘉鱼网站建设前十
  • 网站开发怎么挣外快百度手机助手app下载安装
  • 国外响应式网站模板新闻式软文
  • 潍坊网站建设哪家专业安卓手机优化软件排名
  • 住房与建设部网站 2018 128号智慧教育
  • 怎么做淘宝网站赚钱吗淘宝引流推广平台
  • 青海省住房和建设门户网站在线教育网站用什么做
  • 冠县网站建设价格河北商城网站建设价格
  • 在线做炫图网站淘客网站超级搜怎么做
  • 网站建设报告心得体会办公室设计公司专业网站
  • 昆山住房与城乡建设局网站网站越来越难做
  • 广州网站建设哪家便宜建设公司网站需要什么
  • 安丘网站建设公司h5免费制作软件
  • 做全屏网站图片显示不全河南开封网站建设
  • 网络公司企业网站模板网站建设技术实现难点
  • 做服饰的有哪些网站佛山百度关键词排名