程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> C語言基礎知識 >> 十全十美游戲

十全十美游戲

編輯:C語言基礎知識
//十全十美游戲
  //6*6一直到10*10,不過我只玩過6*6,其它的不知道能不能過
  //按p鍵可以跳關 #define Up  0x4800
  #define Down  0x5000
  #define P    0x1970
  #define R    0x1372
  #define Enter  0x1c0d
  #define Esc   0x11b
  #define Right  0x4d00
  #define Left  0x4b00 #include<bios.h>
  #include<stdio.h>
  #include<dos.h>
  #include<graphics.h>
  #include<conio.h>
  #include<stdlib.h> //定義核心數據
  int LargeStartx;
  int LargeStarty;  //大方格的起始位置
  int SmallStartx;
  int SmallStarty;  //小方格的起始位置 int array=5;          //行列式的大小
  int position;       //方格的位置用0-array*array-1表示 typedef strUCt rect2  //定義大方格的屬性即移動方格的屬性
  {
  int nowx;
  int nowy;
  int agox;
  int agoy;
  int size;//40
  char color;
  }Large;
  Large LargeRect;
  char Attr[10*10];  //記錄小方格的狀態,用'W'(white)與'R'(red)表示。 typedef struct add     //用於改變小方格顏色時,五個方向的增加量(包括當前位置)
  {
  int x;
  int y;
  int p;
  }Add;   typedef struct  rect1 //記錄小方格的當前位置=大方格的當前位置-(大方格的大小-小方格的大小)/2,x軸與y軸一樣
  {
  int nowx;
  int nowy;
  int size;  //20
  char color;
  }Small;
  Small SmallRect; void ChargeColor(int );
  void InitData1();
  void InitData2();
  void DrawLargeRect(int ,int ,int ,char );
  void DrawSmallRect(int ,int ,int ,char );
  void InitPic();
  int Win();
  int Judge(int ,int );
  void main()
  {
  int key;
  int gdriver=DETECT, gmode;
  registerbgidriver(EGAVGA_driver);
  initgraph(&gdriver, &gmode, "");
  setbkcolor(BLUE);
  cleardevice();
  InitData1();
  InitData2();
  InitPic();
  do
     {
     key=bioskey(0);
     LargeRect.agox=LargeRect.nowx;
     LargeRect.agoy=LargeRect.nowy;
     switch(key)
        {
        case Up:
          {
          LargeRect.nowy-=LargeRect.size;
          if(LargeRect.nowy<LargeStarty)  {LargeRect.nowy+=LargeRect.size;continue;}
          setwritemode(1);
          DrawLargeRect(LargeRect.agox,LargeRect.agoy,LargeRect.size,LargeRect.color);
          DrawLargeRect(LargeRect.nowx,LargeRect.nowy,LargeRect.size,LargeRect.color);
          setwritemode(0);
          position-=array;
          break;
          }
        case Down:
          {
          LargeRect.nowy+=LargeRect.size;
          if(LargeRect.nowy>LargeStarty+LargeRect.size*(array-1))  {LargeRect.nowy-=LargeRect.size;continue;}
          setwritemode(1);
          DrawLargeRect(LargeRect.agox,LargeRect.agoy,LargeRect.size,LargeRect.color);
          DrawLargeRect(LargeRect.nowx,LargeRect.nowy,LargeRect.size,LargeRect.color);
          setwritemode(0);
          position+=array;
          break;
          }
        case Left:
          {
          LargeRect.nowx-=LargeRect.size;
          if(LargeRect.nowx<LargeStartx)  {LargeRect.nowx+=LargeRect.size;continue;}
          setwritemode(1);
          DrawLargeRect(LargeRect.agox,LargeRect.agoy,LargeRect.size,LargeRect.color);
          DrawLargeRect(LargeRect.nowx,LargeRect.nowy,LargeRect.size,LargeRect.color);
          setwritemode(0);
          position-=1;
          break;
          }
        case Right:
          {
          LargeRect.nowx+=LargeRect.size;
          if(LargeRect.nowx>LargeStartx+LargeRect.size*(array-1))  {LargeRect.nowx-=LargeRect.size;continue;}
          setwritemode(1);
          DrawLargeRect(LargeRect.agox,LargeRect.agoy,LargeRect.size,LargeRect.color);
          DrawLargeRect(LargeRect.nowx,LargeRect.nowy,LargeRect.size,LargeRect.color);
          setwritemode(0);
          position+=1;
          break;
          }
        case P:
          {
          setbkcolor(BLUE);
          cleardevice();
          if(array<10)  array++;
          else array=5;
          InitData2();
          InitPic();
          break;
          }
        case R:
          {
          setbkcolor(BLUE);
          cleardevice();
          InitData2();
          InitPic();
          break;
          }
        case Enter:
          {
          SmallRect.nowx=LargeRect.nowx+10;
          SmallRect.nowy=LargeRect.nowy+10;
          for(int i=0;i<5;i++)
       ChargeColor(i);
          break;
          }
        case Esc:
          {
          closegraph();
          exit(1);
                        }
        }
     if(Win())
         {
         outtextxy(100,50,"CONGRATULATIONS!");
         sleep(5);
         setbkcolor(BLUE);
                cleardevice();
                if(array<10)  array++;
         else array=5;
   
  
 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved