• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            天地之靈學(xué)習(xí)小組
            我們學(xué)習(xí)小組的OpenGL學(xué)習(xí)筆記 大家一定要互相折磨呀~~
            posts - 150,  comments - 156,  trackbacks - 0

            #include "graphics.h"
            #include "stdio.h"
            #include "dos.h"
            #include "conio.h"
            #include "bios.h"
            #include "stdlib.h"
            #include "math.h"

            #ifdef __cplusplus
            #define __CPPARGS ...
            #else
            #define __CPPARGS
            #endif

            #define VK_LEFT 0x4b00
            #define VK_RIGHT 0x4d00
            #define VK_DOWN 0x5000
            #define VK_UP 0x4800
            #define VK_HOME 0x4700
            #define VK_END 0x4f00
            #define VK_SPACE 0x3920
            #define VK_ESC 0x011b
            #define VK_ENTER 0x1c0d
            #define VK_PGUP 0x4900
            #define VK_PGDOWN 0x5100
            #define TIMER 0x1c


            void drawblock(int,int,int);
            void nedr(void);
            void fk(int,int,int,int);
            void rewr(int,int,int,int);
            void rrwf(int,int);
            int  is_bd(int,int,int);
            int  is_line(void);
            void interrupt ( *oldhandler)(__CPPARGS);
            void KillTimer(void);
            void SetTimer(void interrupt (*IntProc)(__CPPARGS));
            void rscore(int);


            int fkt[]={0,4,8,12,14,16,18};
            int cj[]={0,100,300,900,1500};
            long grc[]={0,3000,60000,90000,120000,150000,180000,210000,240000,270000};
            int cjb[]={0,0,0,0,0,0,0,0,0,0};
            char cjc[]="score:         0";
            char grad[]="grade:0";


            struct shape
            {
            short xy[8];
            short color;
            short next;
            };

            struct shape shapes[19]=
            {
            /* {x1,y1,x2,y3,x3,y3,x4,y4,color,next} */
            {1,1,2,1,3,1,3,2,LIGHTBLUE,1},  /* □□□□ */
            {2,2,3,0,3,1,3,2,LIGHTBLUE,1},  /* □■□□ */
            {1,1,1,2,2,2,3,2,LIGHTBLUE,1},  /* □■□□ */
            {2,0,2,1,2,2,3,0,LIGHTBLUE,-3}, /* □■■□ */

            {1,1,1,2,2,1,3,1,LIGHTCYAN,1},  /* □□□□ */
            {2,0,3,0,3,1,3,2,LIGHTCYAN,1},  /* □■■□ */
            {1,2,2,2,3,1,3,2,LIGHTCYAN,1},  /* □■□□ */
            {2,0,2,1,2,2,3,2,LIGHTCYAN,-3}, /* □■□□ */

            {2,1,3,0,3,1,3,2,LIGHTRED,1},   /* □□□□ */
            {1,2,2,1,2,2,3,2,LIGHTRED,1},   /* □□□□ */
            {1,0,1,1,1,2,2,1,LIGHTRED,1},   /* □■□□ */
            {1,0,2,0,2,1,3,0,LIGHTRED,-3},  /* ■■■□ */

            {2,1,2,2,3,0,3,1,DARKGRAY,1},   /* □□□□ */
            {1,0,2,0,2,1,3,1,DARKGRAY,-1},  /* □□□□ */
                                            /* □■■□ */
                                            /* ■■□□ */

            {2,0,2,1,3,1,3,2,MAGENTA,1},    /* □□□□ */
            {1,2,2,1,2,2,3,1,MAGENTA,-1},   /* □□□□ */
                                            /* ■■□□ */
                                            /* □■■□ */

            {0,1,1,1,2,1,3,1,BROWN,1},  /* □■□□ */
            {1,0,1,1,1,2,1,3,BROWN,-1}, /* □■□□ */
                                        /* □■□□ */
                                        /* □■□□ */

            {2,1,2,2,3,1,3,2,YELLOW,0}, /* □□□□ */
                                        /* □□□□ */
                                        /* □■■□ */
                                        /* □■■□ */
            };

            int stx=5,sty=8,sdx=24,sdy=18,shx=7,shy=22,adx=4,ady=1,nexti,TimerCounter=0,grade=0,end=0;
            unsigned long score=0;

            short board[25][12]=  /* 方塊空間表示,1表示有方塊 */
            {
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},  /*  0   */
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},  /*  5   */
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},  /*  10  */
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},  /*  15  */
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},  /*  20  */
            };

            short colable[25][12]= /* 方塊空間顏色,1表示背景色藍(lán)色*/
            {
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},  /*  0   */
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},  /*  5   */
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},  /*  10  */
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},  /*  15  */
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},
            {1,1,1,1,1,1,1,1,1,1,1,1},  /*  20  */
            };


            void interrupt newhandler(__CPPARGS)   /* 新的時(shí)鐘中斷處理函數(shù) */
            {
            TimerCounter++;
            oldhandler();
            }

            void SetTimer(void interrupt (*IntProc)(__CPPARGS))    /* 設(shè)置新的時(shí)鐘中斷 */
            {
            oldhandler=getvect(TIMER);
            disable();
            setvect(TIMER,IntProc);
            enable();
            }

            void KillTimer()    /* 恢復(fù)原有的時(shí)鐘中斷處理過程 */
            {
            disable();
            setvect(TIMER,oldhandler);
            enable();
            }


            void rscore(int line)   /* 成績更新函數(shù) */
            {
            int i,j,k=1;
            unsigned long s,f;
            score+=cj[line];
            setfillstyle(1,GREEN);
            bar(0,5,150,30);
            s=score;
            if(s>=grc[grade])
            {
            grade++;
            grad[6]=grade+48;
            bar(180,5,300,30);
            moveto(200,20);
            outtext(grad);
            }

            for(i=9;i>0;i--)
            {
            f=pow(10,i);
            j=s/f;s=s%f;
            if((!j)&&k);
            else k=0,cjc[15-i]=j+48;
            }
            moveto(10,20);
            outtext(cjc);
            }


            int is_bd(int x1,int y1,int i)    /* 判斷是否有方塊 */
            {
            int j,x2,y2;
            for(j=0;j<4;j++)
            {
            x2=shapes[i].xy[2*j];
            y2=shapes[i].xy[2*j+1];
            if(board[x1+x2+adx][y1+y2+ady])return 0;
            }
            return 1;
            }

            void fk(int re,int x1,int y1,int i)     /* 方塊的擦除、重寫,并判斷是否結(jié)束 有問題 */
            {
            int j,x2,y2,color;
            for(j=0;j<4;j++)
            {
            x2=shapes[i].xy[2*j];
            y2=shapes[i].xy[2*j+1];
            if(!re) color=getbkcolor();
            else color=shapes[i].color;
            if(re==2)
            {
            if((x1+x2)<=-1)
            {
            printf("Game is OVER!");
            getch();
            end=1;
            }
            break;
            }
            else
            {
            if((x1+x2)<=-1)
            continue;
            }
            board[x1+x2+adx][y1+y2+ady]=re;
            colable[x1+x2+adx][y1+y2+ady]=color;
            drawblock(stx+x1+x2,sty+y1+y2,color);
            }
            /* getch();   */

            }

            void drawblock(int x,int y,int color)   /* 寫1個(gè)相對(duì)單位點(diǎn)的函數(shù) */
            {
            int i,j;
            for(i=0;i<16;i++)
            for(j=0;j<16;j++)
            putpixel(y*16+j,x*16+i,color);
            }

            void nedr(void)   /* 產(chǎn)生并寫下一個(gè)方塊的函數(shù) */
            {
            int j,x2,y2,i,color;
            setfillstyle(1,GREEN);
            nexti=i=random(19);
                bar(shy*16,shx*16,(shy+4)*16,(shx+4)*16);
            for(j=0;j<4;j++)
            {
            x2=shapes[i].xy[2*j];
            y2=shapes[i].xy[2*j+1];
            color=shapes[i].color;
            drawblock(shx+x2,shy+y2,color);
            }
            }

            int is_line(void)   /* 判斷是否成行 有問題 */
            {
            int i,j,k=0;
            for(i=23;i>4;i--)
            {
            for(j=1;j<11;j++)
            if(!board[i][j])break;
            if((j!=11)&&!k)continue;
            if(j==11){k++;continue;}
            rrwf(i,k);
            k=0;
            }
            return k;
            }

            void rrwf(int line,int k)  /* 成行后的處理 有問題 */
            {
            int i,j;
            rscore(k);
            for(i=line+k;i>4;i--)
            for(j=1;j<12;j++)
            colable[i][j]=colable[i-k][j],board[i][j]=board[i-k][j];
            setfillstyle(1,BLUE);
            bar(sty*16,stx*16,(sdy)*16-1,(sdx+1)*16-1);
            for(i=5;i<24;i++)
            for(j=1;j<11;j++)
            if(board[i][j])drawblock(stx+i-4,sty+j-1,colable[i][j]);
            }


            void main(void)
            {
            int drive,mode,i,j=0,k,x1,y1,key,re=1;

            SetTimer(newhandler);

            drive=DETECT;mode=DETECT;
            initgraph(&drive,&mode,"");

            rscore(0);

            setbkcolor(BLUE);
            x1=-4;y1=3;i=fkt[j];
            setfillstyle(1,GREEN);
            bar(shy*16,shx*16,(shy+4)*16,(shx+4)*16);
            bar((sty)*16-6,(shx-2)*16-6,(sdy)*16+5,(sdx+1)*16+5);
            setfillstyle(1,BLUE);
            bar(sty*16,stx*16,(sdy)*16-1,(sdx+1)*16-1);
            nedr();
            fk(re,x1,y1,i);
            for(key=0;;key=bioskey(1))
            {
            if(key)bioskey(0);
            if(key==VK_UP)
            {
            fk(0,x1,y1,i);
            if(is_bd((k=x1-1),y1,i))fk(re,x1=k,y1,i);
            else fk(re,x1,y1,i);
            }
            if(key==VK_LEFT)
            {
            fk(0,x1,y1,i);
            if(is_bd(x1,(k=y1-1),i))fk(re,x1,y1=k,i);
            else fk(re,x1,y1,i);
            }
            if(key==VK_RIGHT)
            {
            fk(0,x1,y1,i);
            if(is_bd(x1,(k=y1+1),i))fk(re,x1,y1=k,i);
            else fk(re,x1,y1,i);
            }
            if(key==VK_SPACE)
            {
            fk(0,x1,y1,i);
            if(is_bd(x1,y1,(k=i+shapes[i].next)))fk(re,x1,y1,i=k);
            else fk(re,x1,y1,i);
            }
            if(key==VK_PGUP)
            {
            fk(0,x1,y1,i);
            if(is_bd(x1,y1,k=fkt[++j%7]))fk(re,x1,y1,i=k);
            else fk(re,x1,y1,i);}
            if(key==VK_PGDOWN)
            {
            fk(0,x1,y1,i);
            if(is_bd(x1,y1,k=fkt[(j+=6)%7]))fk(re,x1,y1,i=k);
            else fk(re,x1,y1,i);
            }
            if(key==VK_ESC)
            break;

            if((key==VK_DOWN)||(TimerCounter>9))
            {
            if(TimerCounter>9)TimerCounter=0;
            fk(0,x1,y1,i);
            if(is_bd((k=x1+1),y1,i))
            fk(re,x1=k,y1,i);
            else
            {
            fk(re,x1,y1,i);
            is_line();
            fk(2,x1,y1,i);
            if(end)break;
            i=nexti;x1=-4;y1=3;
            fk(re,x1,y1,i);
            nedr();
            }
            }
            }

            KillTimer();


             
             


            FeedBack:
            # re: 好簡潔的俄羅斯方塊啊
            2008-11-12 21:34 | risky
            很簡潔,沒法旋轉(zhuǎn)。  回復(fù)  更多評(píng)論
              
            # re: 好簡潔的俄羅斯方塊啊
            2008-11-12 21:36 | 正牌的天地之靈和他的徒兒們肖赫_王婷婷_王冠_鄭燚_孫婷
            暈死了都,早知道你和許多用pure這樣的名字俺就不叫PureMilk了  回復(fù)  更多評(píng)論
              

            <2008年11月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            常用鏈接

            留言簿(6)

            隨筆分類(149)

            隨筆檔案(150)

            同道中人

            搜索

            •  

            積分與排名

            • 積分 - 48577
            • 排名 - 467

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲综合熟女久久久30p| 99久久免费国产精品热| 久久人妻少妇嫩草AV蜜桃| 久久午夜免费视频| 精品久久久久久无码专区 | 99久久精品费精品国产| 人妻少妇精品久久| 热re99久久精品国99热| 日批日出水久久亚洲精品tv| 精品久久久中文字幕人妻| 狠狠色丁香久久综合五月| 欧美伊人久久大香线蕉综合| 久久久久久久99精品免费观看| 伊人精品久久久久7777| 伊人色综合久久| 国产情侣久久久久aⅴ免费| 区久久AAA片69亚洲| 久久久免费观成人影院| 99久久人人爽亚洲精品美女| 亚洲av伊人久久综合密臀性色| 久久精品亚洲精品国产欧美| AV狠狠色丁香婷婷综合久久| 91麻豆国产精品91久久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲欧美一区二区三区久久| 国产一区二区三区久久| 久久精品国产亚洲av水果派 | 无码8090精品久久一区| 一本大道久久a久久精品综合| 久久国产乱子伦免费精品| 久久精品国产免费观看| 久久丝袜精品中文字幕| 久久国产影院| 久久久久亚洲精品天堂久久久久久 | 囯产精品久久久久久久久蜜桃| 久久亚洲av无码精品浪潮| 久久97久久97精品免视看秋霞| 国产成人精品久久综合| 国产亚洲精久久久久久无码AV| 久久综合欧美成人| 久久久久久A亚洲欧洲AV冫|