发布一个有趣的24点炸弹小游戏,希望与大家一起讨论为何NPC会与玩家有胜负分歧
  • 板块学术版
  • 楼主ProJonathan
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/5/19 12:16
  • 上次更新2024/5/19 12:38:46
查看原帖
发布一个有趣的24点炸弹小游戏,希望与大家一起讨论为何NPC会与玩家有胜负分歧
1350971
ProJonathan楼主2024/5/19 12:16

看那么多大佬在发布小gram给大家讨论, 给大家一段小程序,24点炸弹,功能较全 (洛谷上没有相对应的题!此为本小的自编)```c #include<bits/stdc++.h>

using namespace std;

//cards right sets

int cards[100]=

{1,2,3,4,5,6,7,8,9,10,11,12,13};  

//acounts detinate

string user_name="first_time_player", commands;  

int ply[30], npc[30];  

int seed=0, set_world;  

int pd=0, nd=0, p_move=1, n_move=1;  

int user_a_wons, user_a_lost;  

int n_p_r;  

int main(){

//game starting

cout<<"lets have a name:";  

cin>>user_name;cout<<endl;  

cout<<user_name<<", welcom!"<<endl;  

cout<<"please choose your world seed in a four_number struct."<<endl;  

cout<<"seeding:";  

cin>>seed;  

//world_set

for(int i=0;i<24;i++)ply[i]=cards[seed*i%13];  

for(int i=0;i<24;i++)npc[i]=cards[seed*i*i%13];  

n_p_r=seed%2;  

while(n_p_r>=5){  

	n_p_r/=2;  

}  

//command detinate

cout<<"game starting, type'/'for commands"<<endl;  

commands = " ";  

while(commands!="/start"){  

	cin>>commands;  

	if(commands=="/"){  

		cout<<"you can type '/start' to start the game,"<<endl  

		<<"type '/login' to save your progress,"<<endl  

		<<"type '/checkacounts' to check battle history."<<endl;  

	}  

	if(commands=="/login"){  

		cout<<"login process recieving user_name:";  

		cin>>user_name;  

		cout<<endl;  

	}  

	if(commands=="/checkacounts"){  

		cout<<"winning:"<<user_a_wons<<", lost:"<<user_a_lost<<endl;  

	}  

}  

//npc rules

for(int i=0;i<30;i++){  

	if(24-nd<=n_p_r){  

		if(seed%13/2==1){  

			cout<<"[system] the npc stops"<<endl;  

			n_move=0;  

			break;  

		}  

	}  

	if(nd==24)  

		cout<<"[system] the npc stops"<<endl;  

			n_move=0;  


		nd+=npc[i];  


		if(nd>24){  

			cout<<"[system] the npc is at block "<<nd<<",he explode, you win!"<<endl;  

			break;  

		}  

		if(p_move==0 and n_move==0)break;  

	cout<<"[system] npc is at block "<<nd<<endl;  

//player rules

	pd+=ply[i];  

	cout<<"[system] "<<user_name<<" is at block "<<pd<<endl;  

	if(pd>24){  

			cout<<"Uh-oh, you explode!"<<endl;  

			exit(0);}  

	cout<<"do you want to move?"<<endl;  

	string ans;  

	cin>>ans;  

	if(ans=="yes"){  

		if(pd>24){  

			cout<<"Uh-oh, you explode!"<<endl;  

			exit(0);}  

		if(p_move==0 and n_move==0)break;  

		if(pd>24){  

			cout<<"Uh-oh, you explode!"<<endl;  

			exit(0);}  

	}  

	else{  

		cout<<"[system] "<<user_name<<" stop at block "<<pd<<endl;  

		p_move == 0;}  

if(p_move==0 and n_move==0)break;  

}  

//game ending

cout<<endl<<endl<<endl;  

if(nd>pd and nd<=24){  

	cout<<endl<<endl;  

	cout<<"[system] npc WINS!"<<endl;  

}  

if(nd==pd){  

	cout<<endl<<endl;  

	cout<<"[system] npc AND "<<user_name<<" TIED!"<<endl;  

}  

if(pd>nd and pd<=24){  

	cout<<endl<<endl;  

	cout<<"[system] "<<user_name<<" WINS!"<<endl;  

}  

return 0;  

}


(这打代码肯定是没有代码error的,我验证了7遍!请大家放心,但有时代码会出问题,请大家帮我一起讨论一下,我对这种代码debug毫无头绪,~~我要哭了~~请大家谅解)
大家可以玩玩这个小程序,具体规则大家应该会懂的吧,有超强能力朋友的话也请帮我调整一下代码,
                                                     致谢所有人!
2024/5/19 12:16
加载中...