• BAD APPLE C++控制台程序


    使用C++语言编写,如果想改成C语言,手动以GetProcAddress的方式来调用相关函数即可。

      1 #include <windows.h>
      2 #include <mmsystem.h>
      3 #include <stdio.h>
      4 
      5 #pragma comment(lib, "winmm.lib")
      6 
      7 
      8 #define DATAFILE "BADAPPLE.txt"
      9 
     10 #define FRAME_WIDTH        80
     11 #define FRAME_HEIGHT    32
     12 
     13 #define DATA_TOKEN_SIZE    ( 5 + 1 )    //    $0000
    
     14 #define DATA_PITCH_SIZE    ( FRAME_WIDTH + 1 )        // ###...
    
     15 #define DATA_FRAME_SIZE    ( DATA_TOKEN_SIZE + ( DATA_PITCH_SIZE * FRAME_HEIGHT ) )
     16 
     17 #define FRAME_COUNT    3271
     18 
     19 #define VIDEO_TIME    218000.0f    // 3:38 (218000ms)
     20 
     21 
     22 void main(void)
     23 {
     24     HANDLE hOutput;
     25 
     26     hOutput = GetStdHandle( STD_OUTPUT_HANDLE );
     27 
     28     CONSOLE_CURSOR_INFO coc = { 1, FALSE };
     29     COORD co = { FRAME_WIDTH, FRAME_HEIGHT };
     30     SMALL_RECT rc = { 0, 0, FRAME_WIDTH - 1, FRAME_HEIGHT - 1 };
     31 
     32     SetConsoleCursorInfo( hOutput, &coc );
     33     SetConsoleScreenBufferSize( hOutput, co );
     34     SetConsoleWindowInfo( hOutput, TRUE, &rc );
     35 
     36     SetConsoleTitle( "Bad Apple By Crsky @2016" );
     37 
     38     FILE    *fp;
     39     int        size;
     40     char    *buf;
     41     char    *cur;
     42     int        start;
     43 
     44     buf = NULL;
     45 
     46     fp = fopen( DATAFILE, "rb" );
     47 
     48     if ( !fp )
     49     {
     50         printf( "%s not found.
    ", DATAFILE );
     51         goto err;
     52     }
     53 
     54     size = DATA_FRAME_SIZE * FRAME_COUNT;
     55 
     56     buf = new char[ size ];
     57 
     58     if ( fread( buf, size - 1, 1, fp ) != 1 )
     59     {
     60         printf( "Failed to read in data file.
    " );
     61         goto err;
     62     }
     63 
     64     buf[ size - 1 ] = '';
     65 
     66     fclose( fp );
     67 
     68     mciSendString( "open BADAPPLE.wma alias BGM", NULL, 0, NULL );
     69     mciSendString( "play BGM", NULL, 0, NULL );
     70 
     71     start = GetTickCount();
     72 
     73     while ( 1 )
     74     {
     75         int        time;
     76         float    percen;
     77         int        frame;
     78         COORD    xy = { 0, 0 };
     79         DWORD    written;
     80 
     81         if ( GetKeyState( VK_SPACE ) )
     82         {
     83             printf( "Stop play.
    " );
     84             break;
     85         }
     86 
     87         time = GetTickCount();
     88         percen = ( time - start ) / VIDEO_TIME;
     89 
     90         if ( percen > 1 )
     91         {
     92             printf( "End of play.
    " );
     93             break;
     94         }
     95 
     96         frame = percen * FRAME_COUNT;
     97         cur = &buf[ ( DATA_FRAME_SIZE * frame ) + DATA_TOKEN_SIZE ];
     98 
     99         for ( ; xy.Y < FRAME_HEIGHT; xy.Y++, cur += DATA_PITCH_SIZE )
    100             WriteConsoleOutputCharacter( hOutput, cur, DATA_PITCH_SIZE - 1, xy, &written );
    101 
    102         Sleep( 60 );
    103     }
    104 
    105     mciSendString( "stop", NULL, 0, NULL );
    106     mciSendString( "close", NULL, 0, NULL );
    107 
    108 err:
    109     if ( buf )
    110         delete[] buf;
    111 
    112     Sleep( 500 );
    113 }

    效果图:

    完整程序下载:百度网盘

  • 相关阅读:
    VB6:从Comctl.dll中加载TREEVIEW并美化OCX版本(修正)
    一个围猫的小游戏
    从RES文件中直接加载JPG的函数
    Vistaform Control v1.40正式发布(下载)
    比CopyMemory还要快的函数SuperCopyMemory
    VB开发日志:做按钮时顺便做的颜色调整工具
    魔兽按键精灵 V2.0(修正1)
    魔兽按键精灵准备开发3.0版本
    VB高级编程之:完全子类化模仿OFFICE2007按钮
    VB:我的进度条Diy
  • 原文地址:https://www.cnblogs.com/crsky/p/5984260.html
Copyright © 2020-2023  润新知