跳到正文

休闲·娱乐

Buckshot Roulette C++ PVP V3.0

_Michael0727_约 10 分钟
原文
文章信息与版本

文章信息

发布
2024年3月5日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 10 分钟

版本

  1. v1当前

更新日志:

  • 装填BUG更新

代码:

C++
# include <bits/stdc++.h>
# include <windows.h>
# include <conio.h>
using namespace std ;
string p1 , p2 ;
int b1 = 5 , b2 = 5 , shi , xu ;
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 + "的行动时间" ) ;
    // 道具
    LineSay ( "请选择攻击目标(W对方,S自己)" ) ;
    char a = getch ( ) ;
    while ( a != 'W' && a != 'S' )
    {
        a = getch ( ) ;
    }
    if ( a == 'S' )
    {
    	WordSay ( p2 + " 瞄准了 " + p2 ) ;
        shoot2 ( 2 ) ;
    }
    else
    {
    	WordSay ( p2 + " 瞄准了 " + p1 ) ;
        shoot1 ( 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++ PVP V2.0") ;
    Srand ( ) ;
    Sleep ( 500 ) ;
    WordSay ( "Buckshot Roulette" ) ;
    WordSay ( "C++ PVP V2.0" ) ;
    LineSay ( "灵感来自同名游戏" ) ;
    WordSay ( "By Michael0727" ) ;
    system ( "pause" ) ;
    system ( "cls") ;
    LineSay ( "请输入先手方的名字:" ) ;
    cin >> p1 ;
    LineSay ( "请输入后手方的名字:" ) ;
    cin >> p2 ;
    system ( "cls") ;
    Game ( ) ;
    return 0 ;
}
原文