久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: 單片機貪吃蛇程序 支持液晶屏,矩陣鍵盤操作 [打印本頁]

作者: houyao    時間: 2017-5-26 13:17
標題: 單片機貪吃蛇程序 支持液晶屏,矩陣鍵盤操作
解壓縮,可以查看這個貪吃蛇程序。支持液晶屏,矩陣鍵盤操作


單片機源程序如下:
  1. /*
  2. * 貪吃蛇
  3. *
  4. * author:cole3
  5. * date:2010.11.28
  6. */


  7. #include <reg52.h>
  8. #include <stdlib.h>
  9. #include "lcd.h"

  10. #define LEN_MAX 40

  11. sbit KeyIn1 = P2^4;
  12. sbit KeyIn2 = P2^5;
  13. sbit KeyIn3 = P2^6;
  14. sbit KeyIn4 = P2^7;
  15. sbit KeyOut1 = P2^3;
  16. sbit KeyOut2 = P2^2;
  17. sbit KeyOut3 = P2^1;
  18. sbit KeyOut4 = P2^0;


  19. void key(void);
  20. void rand_dot(void);
  21. void turncount(int length,int position,int row,int page);


  22. int i=4,j=0,length=5,direction=2,k=0,dotx,doty,temx[LEN_MAX],temy[LEN_MAX];
  23. char speed=5, t_flag=0;

  24. main()
  25. {
  26.         unsigned int t,flag=1;

  27.         LCD12864_init();
  28.         TMOD = 0x01;
  29.         TH0 = 0x3C;
  30.         TL0 = 0xB0;
  31.         ET0 = 0;
  32.         TR0 = 0;
  33.         EA = 1;

  34.         printf2lcd(0, 0, "----------------");
  35.         printf2lcd(0, 2, "Gluttonous Snake");
  36.         printf2lcd(0, 4, "----------------");
  37.         printf2lcd(0, 6, "  Made By Kingst");
  38.         for (t=0; t<60000; t++);

  39.         ClearSree(0);

  40.         for (t=0; t<length; t++)
  41.         {
  42.                 change(t,0);
  43.                 temx[t] = t;
  44.                 temy[t] = 0;
  45.         }
  46.         rand_dot();

  47.         ET0 = 1;
  48.         TR0 = 1;

  49.         while(flag)
  50.         {
  51.                 key(); // 按鍵掃描

  52.                 // 是否前行
  53.                 if (t_flag == 1)
  54.                 {
  55.                         t_flag = 0;
  56.                         switch (direction)
  57.                         {
  58.                                 case 0: change(i,--j); break;
  59.                                 case 1: change(--i,j); break;
  60.                                 case 2: change(++i,j); break;
  61.                                 case 3: change(i,++j); break;
  62.                         }
  63.        
  64.                         clear(temx[0], temy[0]);
  65.                         for(t=0; t<length-1; t++)
  66.                         {
  67.                                 temx[t] = temx[t+1];
  68.                         }
  69.                         temx[length-1] = i;
  70.        
  71.                         for(t=0; t<length-1; t++)
  72.                         {
  73.                                 temy[t] = temy[t+1];
  74.                         }
  75.                         temy[length-1] = j;
  76.        
  77.                         if((i == dotx) && (j == doty))
  78.                         {
  79.                                 temx[length] = dotx;
  80.                                 temy[length++] = doty;
  81.                                 rand_dot();
  82.                         }
  83.                 }
  84.                 // 是否撞墻
  85.                 if ((i < 0) || (i > 31))
  86.                 {
  87.                         flag = 0;       
  88.                 }
  89.                 if ((j < 0) || (j > 15))
  90.                 {
  91.                         flag = 0;               
  92.                 }
  93.                 // 是否撞自己
  94.                 for (t=0; t<length-4; t++)
  95.                 {
  96.                         if ((i == temx[t]) && (j == temy[t]))
  97.                         {
  98.                                 flag = 0;
  99.                         }
  100.                 }

  101.                 // 是否晉級
  102.                 if (length == LEN_MAX)
  103.                 {
  104.                         TR0 = 0;
  105.                         ET0 = 0;
  106.                         ClearSree(0);
  107.                         speed--;
  108.                         if (speed < 0)
  109.                         {
  110.                                 printf2lcd(4, 1, "You Win!");
  111.                                 while (1);
  112.                         }
  113.                         else
  114.                         {
  115.                                 printf2lcd(3, 1, "Next level!");
  116.                                 for (t=0; t<60000; t++);
  117.                                 ClearSree(0);
  118.                         }
  119.                         length = 5;
  120.                         direction = 2;
  121.                         i = 4;
  122.                         j = 0;
  123.                         k = 0;
  124.                         for (t=0; t<length; t++)
  125.                         {
  126.                                 change(t,0);
  127.                                 temx[t] = t;
  128.                                 temy[t] = 0;
  129.                         }
  130.                         rand_dot();
  131.                         TR0 = 1;
  132.                         ET0 = 1;
  133.                 }
  134.         }

  135.         // game over
  136.         TR0 = 0;
  137.         ET0 = 0;
  138.         ClearSree(0);
  139.         printf2lcd(3, 1, "Game over!");
  140.         printf2lcd(3, 3, "score:");
  141.         ShowNum(9, 3, (length-5)+(LEN_MAX-5)*(5-speed));

  142.         while(1);                               
  143. }


  144. void key(void)
  145. {
  146.         KeyOut1 = 0;
  147.         KeyOut2 = 1;
  148.         KeyOut3 = 1;
  149.         KeyOut4 = 1;
  150.         if ((KeyIn4 == 0) && (direction != 3))
  151.                 direction = 0;
  152.        
  153.         KeyOut1 = 1;
  154.         KeyOut2 = 1;
  155.         KeyOut3 = 0;
  156.         KeyOut4 = 1;
  157.         if ((KeyIn4 == 0) && (direction != 0))
  158.                 direction = 3;

  159.         KeyOut1 = 1;
  160.         KeyOut2 = 0;
  161.         KeyOut3 = 1;
  162.         KeyOut4 = 1;
  163.         if ((KeyIn4 == 0) && (direction != 2))
  164.                 direction = 1;

  165.         KeyOut1 = 1;
  166.         KeyOut2 = 1;
  167.         KeyOut3 = 1;
  168.         KeyOut4 = 0;
  169.         if ((KeyIn4 == 0) && (direction != 1))
  170.                 direction = 2;
  171. }


  172. void rand_dot(void)
  173. {
  174.           int ii;
  175.        
  176.         while (1)
  177.         {
  178.                 dotx = rand() % 32;
  179.                   doty = rand() % 16;

  180.                   for (ii=0; ii<length; ii++)
  181.                 {
  182.                         if ((dotx == temx[ii]) && (doty == temy[ii]))
  183.                                 break;
  184.                 }
  185. ……………………

  186. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
貪吃蛇程序.rar (41.5 KB, 下載次數: 16)







歡迎光臨 (http://m.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 国产在线播放av | 99精品在线 | 欧美一区二区三区国产 | 欧美日韩专区 | 成人精品视频在线观看 | 九九九久久国产免费 | 污书屋 | 三级成人在线 | 日韩电影在线 | 日韩三级在线 | 中文字幕免费在线 | 伊大人久久| 国产免费福利 | 国产精品免费高清 | 日本激情视频在线播放 | 成人免费观看男女羞羞视频 | 欧美日韩中文字幕 | 欧美日韩成人一区二区 | 男女视频在线观看免费 | 国产精品99999999 | 欧美日本在线观看 | 男人的天堂中文字幕 | 亚洲精品日韩综合观看成人91 | 成人在线视频免费播放 | 成人国产一区二区三区精品麻豆 | 伊人精品在线 | 一区二区在线 | 国产成人叼嘿视频在线观看 | 宅女噜噜66国产精品观看免费 | 国产精品美女久久久久aⅴ国产馆 | 国产精品高清在线 | 欧美黑人一区二区三区 | va精品 | 久久久蜜桃 | 黄视频在线网站 | 久久精品| 97视频人人澡人人爽 | 国产高清免费 | 亚洲国产成人精品一区二区 | 亚洲一区久久 | 中文字幕不卡在线观看 |