當前位置:首頁 » 編程軟體 » 88w行代碼編譯

88w行代碼編譯

發布時間: 2025-01-16 22:11:24

1. 小游戲的C++代碼

/*一個火柴人游戲,親自驗證,可運行*/
/*在編譯時添加如下命令:-std=c++11,否則會編譯錯誤*/
#include <cstdio>
#include <cstdlib>
#include <Windows.h>
#include <thread>
#include <conio.h>
using namespace std;
const unsigned char CTRL_KEY = 0XE0;
const unsigned char LEFT = 0X4B;
const unsigned char RIGHT = 0X4D;
const unsigned char DOWN = 0X50;
const unsigned char UP = 0X48;
int men2[2] = {0,0};
int women2[2]={10,10};
int Game();
void gotoxy( int x, int y ) //游標移動到(x,y)位置
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
int clean( int mm, int nn )
{
gotoxy ( mm, nn );
printf ( " " );
gotoxy ( mm,nn+1);
printf ( " " );
gotoxy ( mm,nn+2);
printf (" ");
}
int men( int x, int y )
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
gotoxy( x, y );
printf(" O");
gotoxy( x, y+1 );
printf("<H>");
gotoxy( x, y+2 );
printf("I I");
}
int women( int i, int j )
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
gotoxy( i+1,j );
printf(" O");
gotoxy( i+1,j+1 );
printf("<H>");
gotoxy( i,j+2 );
printf("/I I\\");
}
int m=10, n=10;
int x=0;int y=0;
int TorF()
{
if ( x == m && y == n ) return 1;
else return 0;
}
int womenmove()
{
int turn;
int YNbreak=0;
while( YNbreak == 0 )
{
YNbreaak = TorF();
turn=rand()%3;
clean( m, n );
if( m < x ) m++;
else m--;
if( m == x )
{
if( n < y ) n++;
else n--;
}
if ( m < 0 ) m = 0;
if ( m >= 75 ) m = 75;
if ( n < 0 ) n = 0;
if ( n >= 22 ) n = 22;
women( m,n );
women2[0]=m;
women2[1]=n;
Sleep(100);
}
system ( "cls" );
gotoxy ( 28, 10 );
printf ( "You died!!!\n" );
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
system ( "pause" );
exit(0);
return 0;
}
int menmove()
{
system( "cls" );
while (1)
{
switch( getch())
{
case UP:y--;break;
case DOWN:y++;break;
case LEFT:x--;break;
case RIGHT:x++;break;
}
system( "cls" );
if ( x < 0 ) x = 0;
if ( x > 77 ) x = 77;
if ( y < 0 ) y = 0;
if ( y > 22 ) y = 22;
men( x, y );
men2[0] = x;
men2[1] = y;
}
}
int Game()
{
women( 10, 10 );
men( 0, 0 );
int t = 0;
thread qq( womenmove );
menmove();
qq.join();
return 0;
}
int main()
{
system( "mode con cols=80 lines=25" );
printf ( "游戲開始後,隨機按下一個鍵,喚醒你的藍色小人.如果你被紅色的老女人碰到了,那麼你就死了\n" );
printf ( "方向鍵操控小人\n" );
system ( "pause" );
system ( "cls" );
Game();
return 0;
}
/*留下您的贊再拿走,謝謝!*/

熱點內容
jap伺服器環境搭建 發布:2025-01-17 01:22:37 瀏覽:996
銅鏡資料庫 發布:2025-01-17 01:08:57 瀏覽:673
上傳圖片鏈接 發布:2025-01-17 01:08:11 瀏覽:891
智跑買車可以提哪些配置 發布:2025-01-17 01:06:46 瀏覽:463
qq2013源碼 發布:2025-01-17 01:06:35 瀏覽:94
sql的decode 發布:2025-01-17 01:01:01 瀏覽:4
系數參數配置什麼意思 發布:2025-01-17 00:34:03 瀏覽:755
台灣免費伺服器雲主機 發布:2025-01-17 00:29:07 瀏覽:870
c語言sizeofchar 發布:2025-01-17 00:29:01 瀏覽:469
安卓手機的雲備份在哪裡能找到 發布:2025-01-17 00:14:12 瀏覽:472