Buckshot Roulette C++ 人机对战 V3.0
_Michael0727_ · · 休闲·娱乐
更新日志
-
装填BUG更新
代码:
# include <bits/stdc++.h> # include <windows.h> # include <conio.h> using namespace std ; string p1 , p2 ; int b1 = 5 , b2 = 5 , shi , xu , dif ; bool ise = false , xu1 = false , xu2 = false ; queue <bool> gun ; void SlowSay ( string s ) { for ( int i = 0 ; i < s . size ( ) ; i ++ ) { cout << s [i] ; if ( s [i] != ' ' ) { Sleep ( 250 ) ; } } cout << endl ; Sleep ( 250 ) ; return ; } void WordSay ( string s ) { for ( int i = 0 ; i < s . size ( ) ; i ++ ) { cout << s [i] ; if ( s [i] == ' ' ) { Sleep ( 250 ) ; } } cout << endl ; Sleep ( 250 ) ; return ; } void LineSay ( string s ) { cout << s << endl ; Sleep ( 250 ) ; return ; } void initg ( ) { system ( "cls" ) ; SlowSay ( "子弹装填中....." ) ; system ( "cls" ) ; gun . empty ( ) ; int a = rand ( ) % 5 + 5 ; // 5 - 10 xu = rand ( ) % ( a - 5 ) + 3 ; // 3 - a - 2 shi = a - xu ; cout << "本轮有" << shi << "颗实弹," << xu << "颗空弹" << endl ; Sleep ( 1000 ) ; int g1 [shi + xu] ; memset( g1 , 0 , sizeof ( g1 ) ) ; for ( int i = 1 ; i < shi ; i ++ ) { int a = rand ( ) % ( shi + xu - 1 ) + 1 ; while ( g1 [a] == 1 ) { a = rand ( ) % ( shi + xu - 1 ) + 1 ; } g1 [a] = 1 ; } for ( int i = 1 ; i <= shi + xu ; i ++ ) { if ( g1 [i] ) { gun . push ( true ) ; //cout << 1 << endl ; } else { gun . push ( false ) ; //cout << 0 << endl ; } } system ( "pause" ) ; system ( "cls" ) ; return ; } void shoot1 ( int x ) { bool a = gun . front ( ) ; gun . pop ( ) ; if ( a ) { LineSay ( "一颗实弹射出" ) ; b1 -- ; shi -- ; } else { LineSay ( "一颗空弹射出" ) ; xu -- ; if ( x == 1 ) { xu1 = true ; } } return ; } void shoot2 ( int x ) { bool a = gun . front ( ) ; gun . pop ( ) ; if ( a ) { LineSay ( "一颗实弹射出" ) ; b2 -- ; shi -- ; } else { LineSay ( "一颗空弹射出" ) ; xu -- ; if ( x == 2 ) { xu2 = true ; } } return ; } void P1Round ( ) { LineSay ( p1 + "的行动时间" ) ; // 道具 LineSay ( "请选择攻击目标(W对方,S自己)" ) ; char a = getch ( ) ; while ( a != 'W' && a != 'S' ) { a = getch ( ) ; } if ( a == 'S' ) { WordSay ( p1 + " 瞄准了 " + p1 ) ; shoot1 ( 1 ) ; } else { WordSay ( p1 + " 瞄准了 " + p2 ) ; shoot2 ( 1 ) ; } system ( "pause" ) ; return ; } void P2Round ( ) { LineSay ( p2 + "的行动时间" ) ; if ( dif == 1 ) { int a = rand ( ) % 2 ; if ( a ) { WordSay ( p2 + " 瞄准了 " + p1 ) ; shoot1 ( 2 ) ; } else { WordSay ( p2 + " 瞄准了 自己" ) ; shoot2 ( 2 ) ; } } else if ( dif == 2 ) { if ( shi > xu ) { WordSay ( p2 + " 瞄准了 " + p1 ) ; shoot1 ( 2 ) ; } else if ( shi < xu ) { WordSay ( p2 + " 瞄准了 自己" ) ; shoot2 ( 2 ) ; } else { int a = rand ( ) % 2 ; if ( a ) { WordSay ( p2 + " 瞄准了 " + p1 ) ; shoot1 ( 2 ) ; } else { WordSay ( p2 + " 瞄准了 自己" ) ; shoot2 ( 2 ) ; } } } else { if ( gun . front ( ) ) { WordSay ( p2 + " 瞄准了 " + p1 ) ; shoot1 ( 2 ) ; } else { WordSay ( p2 + " 瞄准了 自己" ) ; shoot2 ( 2 ) ; } } system ( "pause" ) ; return ; } void Blood ( ) { cout << p1 ; Sleep ( 250 ) ; cout << " 血量:" ; Sleep ( 250 ) ; cout << b1 << "/5" << endl ; Sleep ( 250 ) ; cout << p2 ; Sleep ( 250 ) ; cout << " 血量:" ; Sleep ( 250 ) ; cout << b2 << "/5" << endl ; system ( "pause" ) ; return ; } void Game ( ) { initg ( ) ; while ( b1 > 0 && b2 > 0 ) { if ( gun . empty ( ) ) { LineSay ( "子弹用完,重新装填子弹" ) ; Sleep ( 250 ) ; initg ( ) ; } if ( ! xu2 ) { Sleep ( 1000 ) ; Blood ( ) ; system ( "cls" ) ; P1Round ( ) ; system ( "cls" ) ; } xu2 = false ; if ( b2 <= 0 || b1 <= 0 ) { break ; } if ( gun . empty ( ) ) { LineSay ( "子弹用完,重新装填子弹" ) ; Sleep ( 250 ) ; initg ( ) ; } if ( ! xu1 ) { Sleep ( 1000 ) ; Blood ( ) ; system ( "cls" ) ; P2Round ( ) ; system ( "cls" ) ; } xu1 = false ; } if ( ! b1 ) { cout << p2 << "获胜" << endl ; cout << p1 << "死亡" << endl ; return ; } cout << p1 << "获胜" << endl ; cout << p2 << "死亡" << endl ; return ; } void Srand ( ) { SYSTEMTIME sys ; GetLocalTime ( & sys ) ; srand ( sys . wSecond * 1000 + sys . wMilliseconds ) ; } int main ( ) { system ( "title Buckshot Roulette C++ 人机对战 V2.0") ; Srand ( ) ; Sleep ( 500 ) ; WordSay ( "Buckshot Roulette" ) ; WordSay ( "C++ 人机对战 V2.0" ) ; LineSay ( "灵感来自同名游戏" ) ; WordSay ( "By Michael0727" ) ; system ( "pause" ) ; system ( "cls") ; LineSay ( "请输入玩家的名字:" ) ; cin >> p1 ; p2 = "Dealer" ; LineSay ( "请输入难度(1-3,越高越难)" ) ; while ( dif < 1 || dif > 3 ) { dif = getch ( ) - '0' ; } system ( "cls" ) ; Game ( ) ; return 0 ; }