• <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++博客 首頁 新隨筆 聯系 聚合 管理
              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) | 評論 (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) | 評論 (0)編輯 收藏

            2007年3月12日 #

            很多游戲都是用鼠標控制的,所以說處理鼠標事件也是非常重要的,鼠標事件和鍵盤事件處理方式差的不太多,所以我就直接給出了一個小程序,該程序把窗口一分為二,當在左半部分移動時,左面部分就變綠色,右面部分變黑色,在右半部分移動時,該部分就變藍色,左半部分就變成了黑色,當鼠標左擊時,對應的部分將會變紅色。

            #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) | 評論 (3)編輯 收藏

            這次我們看看如何在SDL中處理鍵盤事件,每次事件發生以后,有關事件的所有信息都存儲在SDL_Event類型的變量當中,查查手冊我們可以知道,實際SDL_Event是一個聯合體。
            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;
            當發生鍵盤事件時,key變量就是有效的。
            typedef struct{
            ? Uint8 type;
            ? Uint8 state;
            ? SDL_keysym keysym;
            } SDL_KeyboardEvent;
            key變量是一個結構體,其中keysym成員包含了按鍵信息。
            typedef struct{
            ? Uint8 scancode;
            ? SDLKey sym;
            ? SDLMod mod;
            ? Uint16 unicode;
            } SDL_keysym;
            在keysym的成員當中,sym記錄按鍵所對應的虛擬鍵。
            比如說向上就是SDLK_UP;向下就是SDLK_DOWN;大家可以自己去查手冊。

            下面就看一個處理鍵盤消息的實例吧。
            該例子中,我們一旦發現有上下左右四個鍵被按下,就馬上在屏幕上顯示相對應的消息,這里用到了擴展類庫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) | 評論 (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 ;
            }

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

            僅列出標題  下一頁
            国产成年无码久久久久毛片| 久久久精品人妻无码专区不卡| 亚洲狠狠综合久久| 久久国产精品无码HDAV| 久久99国产精品久久99小说| 国产L精品国产亚洲区久久| 久久美女人爽女人爽| 久久精品国内一区二区三区| 久久超碰97人人做人人爱| 久久99国内精品自在现线| 人妻久久久一区二区三区| 色偷偷88888欧美精品久久久| 亚洲午夜久久久影院| 精品国产乱码久久久久久1区2区| 99久久夜色精品国产网站| 久久久无码精品亚洲日韩按摩| 久久超乳爆乳中文字幕| 91麻精品国产91久久久久| 狠狠色综合网站久久久久久久| 久久精品亚洲男人的天堂| 亚洲国产高清精品线久久| 精品国产99久久久久久麻豆| 欧美亚洲色综久久精品国产| 久久ww精品w免费人成| 国产一区二区精品久久岳| 亚洲精品tv久久久久久久久久| 一本一本久久aa综合精品| 久久精品男人影院| 久久精品国产一区二区电影| 久久久久亚洲精品日久生情| 国产精品视频久久久| 久久久久国产精品嫩草影院| 亚洲综合精品香蕉久久网| 91麻豆精品国产91久久久久久| 久久久这里只有精品加勒比| 久久久久久亚洲AV无码专区| 久久精品国产99国产精品| 亚洲中文久久精品无码| 久久久久亚洲爆乳少妇无| 久久亚洲AV成人出白浆无码国产| 四虎国产永久免费久久|