• <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>

            VC++ C++ C# Algorithm

            C++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              21 Posts :: 3 Stories :: 31 Comments :: 0 Trackbacks

            2007年3月15日 #

            ?

            void ?move( int ?number, char ?from, char ?rely, char ?to)
            {
            ????
            if (number? == ? 1 )
            ????
            {
            ????????printf(
            " Move?a?disk?from?%c?to?%c\n " ,from,to);
            ????????
            return ;
            ????}

            ????move(number
            - 1 ,from,to,rely);
            ????move(
            1 ,from,rely,to);
            ????move(number
            - 1 ,rely,from,to);
            }


            int ?_tmain( int ?argc,?_TCHAR * ?argv[])
            {
            ????move(
            3 , ' A ' , ' B ' , ' C ' );
            ????::system(
            " pause " );
            ????
            return ? 0 ;
            }


            ?

            ?

            posted @ 2007-03-15 16:46 大熊貓 閱讀(301) | 評(píng)論 (0)編輯 收藏

            ?1 int ?A[ 10 ] = { 1 , 2 , 5 , 7 , 3 , 14 , 78 , 25 , 11 , 14 } ;
            ?2 void ?InsertSort( int ?a[], int ?size)
            ?3 {
            ?4 ???? for ( int ?i = 1 ;?i < size;?i ++ )
            ?5 ???? {
            ?6 ???????? int ?key = a[i];
            ?7 ???????? int ?j = i - 1 ;
            ?8 ???????? while (a[j] > key? && ?j >= 0 )
            ?9 ???????? {
            10 ????????????a[j + 1 ] = a[j];
            11 ????????????j -- ;
            12 ????????}

            13 ????????a[j + 1 ] = key;
            14 ????}

            15 }

            16
            17 int ?_tmain( int ?argc,?_TCHAR * ?argv[])
            18 {
            19
            20 ????InsertSort(A, sizeof (A) / sizeof (A[ 0 ]));
            21 ???? for ( int ?i = 0 ;?i < 10 ;?i ++ )
            22 ???? {
            23 ????????printf( " %d\n " ,A[i]);
            24 ????}

            25 ????::system( " pause " );
            26 ???? return ? 0 ;
            27 }

            28
            posted @ 2007-03-15 16:32 大熊貓 閱讀(303) | 評(píng)論 (0)編輯 收藏

            2007年3月12日 #

            很多游戲都是用鼠標(biāo)控制的,所以說(shuō)處理鼠標(biāo)事件也是非常重要的,鼠標(biāo)事件和鍵盤(pán)事件處理方式差的不太多,所以我就直接給出了一個(gè)小程序,該程序把窗口一分為二,當(dāng)在左半部分移動(dòng)時(shí),左面部分就變綠色,右面部分變黑色,在右半部分移動(dòng)時(shí),該部分就變藍(lán)色,左半部分就變成了黑色,當(dāng)鼠標(biāo)左擊時(shí),對(duì)應(yīng)的部分將會(huì)變紅色。

            #include? " SDL.h "
            #include?
            " SDL_ttf.h "
            SDL_Surface?
            * screen = NULL;

            TTF_Font?
            * font =
            NULL;
            // screen?to?show?on?window

            const ? int ?SCREEN_BPP = 32 ;



            int ?main(? int ?argc,? char *
            ?args[]?)
            {
            ????
            // Start?SDL

            ???? bool ?quit = false ;
            ????SDL_Rect?rectLeft;
            ????SDL_Rect?rectRight;
            ????rectLeft.x
            = 0
            ;
            ????rectLeft.y
            = 0
            ;
            ????rectLeft.w
            = 320
            ;
            ????rectLeft.h
            = 480
            ;
            ????rectRight.x
            = 320
            ;
            ????rectRight.y
            = 0
            ;
            ????rectRight.w
            = 640
            ;
            ????rectRight.h
            = 480
            ;
            ????SDL_Init(?SDL_INIT_EVERYTHING?);
            ????
            if (TTF_Init() ==- 1
            )
            ????????
            return ? false
            ;
            ????
            ????screen?
            = ?SDL_SetVideoMode(? 600 ,? 480
            ,?SCREEN_BPP,?SDL_SWSURFACE?);
            ????
            if (screen ==
            NULL)
            ????????
            return ? false
            ;

            ????Uint32?colorBlue
            = SDL_MapRGB(screen -> format, 0 , 0 , 255
            );
            ????Uint32?colorGreen
            = SDL_MapRGB(screen -> format, 0 , 255 , 0
            );
            ????Uint32?colorRed
            = SDL_MapRGB(screen -> format, 255 , 0 , 0
            );
            ????Uint32?colorBlack
            = SDL_MapRGB(screen -> format, 0 , 0 , 0
            );
            ????SDL_Event?
            event
            ;
            ????
            while ( !
            quit)
            ????
            {
            ????????
            if (SDL_PollEvent( & event
            ))
            ????????
            {
            ????????????
            if ( event .type? ==
            ?SDL_MOUSEMOTION)
            ????????????
            {
            ????????????????Uint16?x
            = event
            .motion.x;
            ????????????????Uint16?y
            = event
            .motion.y;


            ????????????????
            if (x > 0 ? && ?x < 320 ? && ?y > 0 ? && ?y < 480
            ?)
            ????????????????
            {
            ????????????????????SDL_FillRect(screen,
            &
            rectLeft,colorBlue);
            ????????????????????SDL_FillRect(screen,
            &
            rectRight,colorBlack);
            ????????????????}

            ????????????????
            if (x > 320 ? && ?x < 640 ? && ?y > 0 ? && ?y < 480 ?)
            ????????????????
            {
            ????????????????????SDL_FillRect(screen,
            &
            rectRight,colorGreen);
            ????????????????????SDL_FillRect(screen,
            &
            rectLeft,colorBlack);
            ????????????????}

            ????????????}

            ????????????
            if ( event .type? == SDL_MOUSEBUTTONDOWN)
            ????????????
            {
            ????????????????Uint16?x
            = event
            .motion.x;
            ????????????????Uint16?y
            = event
            .motion.y;
            ????????????????
            if ( event .button.button? ==
            ?SDL_BUTTON_LEFT)
            ????????????????
            {
            ????????????????????
            if (x > 0 ? && ?x < 320 ? && ?y > 0 ? && ?y < 480
            ?)
            ????????????????????
            {
            ????????????????????????SDL_FillRect(screen,
            &
            rectLeft,colorRed);
            ????????????????????}

            ????????????????????
            if (x > 320 ? && ?x < 640 ? && ?y > 0 ? && ?y < 480 ?)
            ????????????????????
            {
            ????????????????????????SDL_FillRect(screen,
            &
            rectRight,colorRed);
            ????????????????????}

            ????????????????}

            ????????????}

            ????????????
            if ( event .type? == ?SDL_QUIT)
            ????????????????quit
            = true
            ;
            ????????}

            ????????
            if (SDL_Flip(screen)? == ? - 1 )
            ????????
            {
            ????????????
            return ? false
            ;
            ????????}

            ????}

            ????SDL_FreeSurface(screen);
            ????SDL_Quit();

            ????
            return ? 0 ;????
            }

            mousedown.jpg
            posted @ 2007-03-12 20:10 大熊貓 閱讀(1787) | 評(píng)論 (3)編輯 收藏

            這次我們看看如何在SDL中處理鍵盤(pán)事件,每次事件發(fā)生以后,有關(guān)事件的所有信息都存儲(chǔ)在SDL_Event類(lèi)型的變量當(dāng)中,查查手冊(cè)我們可以知道,實(shí)際SDL_Event是一個(gè)聯(lián)合體。
            typedef union{
            ? Uint8 type;
            ? SDL_ActiveEvent active;
            ? SDL_KeyboardEvent key;
            ? SDL_MouseMotionEvent motion;
            ? SDL_MouseButtonEvent button;
            ? SDL_JoyAxisEvent jaxis;
            ? SDL_JoyBallEvent jball;
            ? SDL_JoyHatEvent jhat;
            ? SDL_JoyButtonEvent jbutton;
            ? SDL_ResizeEvent resize;
            ? SDL_ExposeEvent expose;
            ? SDL_QuitEvent quit;
            ? SDL_UserEvent user;
            ? SDL_SywWMEvent syswm;
            } SDL_Event;
            當(dāng)發(fā)生鍵盤(pán)事件時(shí),key變量就是有效的。
            typedef struct{
            ? Uint8 type;
            ? Uint8 state;
            ? SDL_keysym keysym;
            } SDL_KeyboardEvent;
            key變量是一個(gè)結(jié)構(gòu)體,其中keysym成員包含了按鍵信息。
            typedef struct{
            ? Uint8 scancode;
            ? SDLKey sym;
            ? SDLMod mod;
            ? Uint16 unicode;
            } SDL_keysym;
            在keysym的成員當(dāng)中,sym記錄按鍵所對(duì)應(yīng)的虛擬鍵。
            比如說(shuō)向上就是SDLK_UP;向下就是SDLK_DOWN;大家可以自己去查手冊(cè)。

            下面就看一個(gè)處理鍵盤(pán)消息的實(shí)例吧。
            該例子中,我們一旦發(fā)現(xiàn)有上下左右四個(gè)鍵被按下,就馬上在屏幕上顯示相對(duì)應(yīng)的消息,這里用到了擴(kuò)展類(lèi)庫(kù)SDL_TTF,如有不清楚的,參考一下前面的幾篇文章。
            #include?"SDL.h"
            #include?
            "SDL_ttf.h"
            SDL_Surface?
            *screen=NULL;
            SDL_Surface?
            *up=
            NULL;
            SDL_Surface?
            *down=
            NULL;
            SDL_Surface?
            *left=
            NULL;
            SDL_Surface?
            *right=
            NULL;
            SDL_Surface?
            *message=
            NULL;
            TTF_Font?
            *font=
            NULL;
            //screen?to?show?on?window

            const?int?SCREEN_BPP=32;
            SDL_Color?textColor
            ={255,255,255}
            ;


            int?main(?int?argc,?char*
            ?args[]?)
            {
            ????
            //Start?SDL

            ????bool?quit=false;
            ????SDL_Init(?SDL_INIT_EVERYTHING?);
            ????
            if(TTF_Init()==-1
            )
            ????????
            return?false
            ;

            ????screen?
            =?SDL_SetVideoMode(?600,?480
            ,?SCREEN_BPP,?SDL_SWSURFACE?);
            ????
            if(screen==
            NULL)
            ????????
            return?false
            ;
            ????font
            =TTF_OpenFont("tahoma.ttf",28
            );
            ????up?
            =?TTF_RenderText_Solid(?font,?"Up?was?pressed."
            ,?textColor?);
            ????down?
            =?TTF_RenderText_Solid(?font,?"Down?was?pressed."
            ,?textColor?);
            ????left?
            =?TTF_RenderText_Solid(?font,?"Left?was?pressed"
            ,?textColor?);
            ????right?
            =?TTF_RenderText_Solid(?font,?"Right?was?pressed"
            ,?textColor?);
            ????SDL_Event?
            event
            ;
            ????
            while(!
            quit)
            ????
            {
            ????????
            if(SDL_PollEvent(&event
            ))
            ????????
            {
            ????????????
            if(event.type?==
            ?SDL_KEYDOWN)
            ????????????
            {
            ????????????????
            switch(event
            .key.keysym.sym)
            ????????????????
            {
            ????????????????????
            case?SDLK_UP:?message=up;break
            ;
            ????????????????????
            case?SDLK_DOWN:?message=down;break
            ;
            ????????????????????
            case?SDLK_LEFT:?message=left;break
            ;
            ????????????????????
            case?SDLK_RIGHT:?message=right;break
            ;
            ????????????????}

            ????????????}

            ????????????
            if(event.type?==?SDL_QUIT)
            ????????????????quit
            =true
            ;
            ????????}

            ????????
            if(message?!=?NULL)
            ????????
            {
            ????????????Uint32?colorVal
            =SDL_MapRGB(screen->format,0,0,0
            );
            ????????????SDL_FillRect(screen,?
            &screen->
            clip_rect,colorVal);
            ????????????SDL_BlitSurface(message,NULL,screen,NULL);

            ????????????message
            =
            NULL;
            ????????}

            ????????
            if(SDL_Flip(screen)?==?-1)
            ????????
            {
            ????????????
            return?false
            ;
            ????????}

            ????}

            ????
            //Quit?SDL
            ????SDL_Quit();

            ????
            return?0
            ;????
            }

            a.jpg
            posted @ 2007-03-12 19:27 大熊貓 閱讀(1268) | 評(píng)論 (0)編輯 收藏

            2007年3月10日 #

            ?

            int ?_tmain( int ?argc,?_TCHAR * ?argv[])
            {
            ?
            char ?str1[]??????? = ? " abc " ;
            ?
            char ?str2[]??????? = ? " abc " ;
            ?
            const ? char ?str3[]? = ? " abc " ;?
            ?
            const ? char ?str4[]? = ? " abc " ;?
            ?
            const ? char * ?str5?? = ? " abc " ;
            ?
            const ? char * ?str6?? = ? " abc " ;

            ?cout
            << (str1 == str2) << " \n " ;
            ?cout
            << (str3 == str4) << " \n " ;
            ?cout
            << (str5 == str6) << " \n " ;
            ?::system(
            " pause " );
            ?
            return ? 0 ;
            }

            以上會(huì)輸出什么呢,答案是0,0,1。
            前面四個(gè)變量都在棧上分配了內(nèi)存,故內(nèi)存地址大家都不同,而str5和str6所指字符串在常量區(qū),大家有者一樣的地址。
            posted @ 2007-03-10 22:09 大熊貓 閱讀(1076) | 評(píng)論 (0)編輯 收藏

            僅列出標(biāo)題  下一頁(yè)
            开心久久婷婷综合中文字幕| 久久精品中文字幕一区| 亚洲国产精品无码久久九九| 久久精品亚洲中文字幕无码麻豆| 精品乱码久久久久久夜夜嗨| 久久精品国产亚洲av影院| 久久综合亚洲色HEZYO国产| 久久国产亚洲高清观看| 奇米影视7777久久精品人人爽| 2021国产成人精品久久| 久久婷婷五月综合97色一本一本| 久久综合色之久久综合| 91精品无码久久久久久五月天| 久久精品国产久精国产思思 | 色综合合久久天天综合绕视看| 亚洲午夜久久久久久久久久| 婷婷久久综合| 99久久综合国产精品二区| 国产精品久久久久9999| 日韩精品久久久久久免费| 99精品国产99久久久久久97| 久久这里的只有是精品23| 欧美久久综合九色综合| 久久久久亚洲AV综合波多野结衣 | 久久久青草青青亚洲国产免观| 99久久国产宗和精品1上映| 欧美激情一区二区久久久| 久久99热这里只频精品6| 亚洲国产精品一区二区三区久久| 久久精品国产精品亚洲下载| 国产精品免费久久久久影院 | 99久久婷婷国产综合亚洲| 性欧美丰满熟妇XXXX性久久久 | 国产精品免费久久| 国产精品无码久久综合网| 99久久精品费精品国产| 久久99精品国产麻豆不卡| 久久久久久亚洲精品无码| 亚洲中文字幕伊人久久无码 | 亚洲国产成人精品91久久久| 久久伊人五月天论坛|