puke-room.c

来自「C实现的MUD,对大家基本入门网络游戏很有帮助!」· C语言 代码 · 共 1,002 行 · 第 1/2 页

C
1,002
字号
		next_player  =  e_id;	}	else  if(bigger  ==  w_last)  	{		dest  =  "w";  		next_player  =  w_id;	}	else  if(bigger  ==  n_last)  	{		dest  =  "n";  		next_player  =  n_id;	}	else  if(bigger  ==  s_last)	{		dest  =  "s";  		next_player  =  s_id;	}  	else  tell_room(this_object(),  "出问题了(get  next  player),叫巫师来吧。\n");	if(  check_score(e_last)  !=  0  )  pai_destination[e_last]  =  dest;	if(  check_score(w_last)  !=  0  )  pai_destination[w_last]  =  dest;	if(  check_score(n_last)  !=  0  )  pai_destination[n_last]  =  dest;	if(  check_score(s_last)  !=  0  )  pai_destination[s_last]  =  dest;	tell_room(this_object(),  chinese_dir(dest)+"家的"+pai_name[bigger]+"最大。\n");	if(pai_name[e_last]=="【黑Q】"  ||  pai_name[w_last]=="【黑Q】"  	||    pai_name[n_last]=="【黑Q】"  ||  pai_name[s_last]=="【黑Q】"  )		tell_room(this_object(),  "啊哈!猪上"+chinese_dir(dest)+"家去了。\n");	if(pai_name[e_last]=="【方J】"  ||  pai_name[w_last]=="【方J】"  	||    pai_name[n_last]=="【方J】"  ||  pai_name[s_last]=="【方J】"  )		tell_room(this_object(),  chinese_dir(dest)+"家得到了羊。\n");		return  next_player;}int  pai_compare(int  p1,  int  p2){	//same  kind.	if(  check_kind(p1)  ==  check_kind(p2)  )  		return  (check_rank(p1)-check_rank(p2));	//different  kind.	if(  check_kind(p1)  ==  current_round_kind  )  return  1;	if(  check_kind(p2)  ==  current_round_kind  )  return  -1;		//else	return  0;	}void  game_finished(){	tell_room(this_object(),  "这一局结束了。\n");	//calculate  score  for  this  round.	calculate_score();	show_table(1);	//reset.	game_reset();}void  game_reset(){	int  i;	game_status  =  0;	e_id  =  "no  one";	w_id  =  "no  one";	n_id  =  "no  one";	s_id  =  "no  one";	who_to_play  =  "no  one";	e_last  =  pai_size;  	w_last  =  pai_size;  	n_last  =  pai_size;  	s_last  =  pai_size;  	current_round_kind  =  "none";	current_round_step  =  0;	for(i=0;  i<sizeof(current_round_ids);  i++)	{		current_round_ids[i]  =  53;	}	cao_double  =  1;  //can  be  1  or  2.	hong_double  =  1;  //can  be  1  or  2.	pig_double  =  1;  //can  be  1  or  2.	yang_double  =  1;  //can  be  1  or  2.	for(i=0;  i<54;  i++)	{		pai_state[i]  =  "i";		pai_destination[i]  =  "i";	}}check_finish(int  previous_game_id){	if(previous_game_id  !=  game_id)  return;  //it  means  already  finished.	if(game_status  ==  0)  return;  //no  game,  no  need  to  cancel.	tell_room(this_object(),  "这一盘一直完不成,只好取消重来了。\n");	game_reset();}void  calculate_score(){	int  i;	int  c10;	string  hong_dest;	e_score  =  0;	w_score  =  0;	n_score  =  0;	s_score  =  0;	for(i=0;  i<pai_size;  i++)	{		if(pai_destination[i]  ==  "e")  e_score  +=  check_score(i);		else  if(pai_destination[i]  ==  "w")  w_score  +=  check_score(i);		else  if(pai_destination[i]  ==  "n")  n_score  +=  check_score(i);		else  if(pai_destination[i]  ==  "s")  s_score  +=  check_score(i);	}	//where  is  caohua  10?	c10  =  convert_to_id("cao",  10);	if(  pai_destination[c10]  =  "e"  )  e_score  *=  2*cao_double;	else  if(  pai_destination[c10]  =  "w"  )  w_score  *=  2*cao_double;	else  if(  pai_destination[c10]  =  "n"  )  n_score  *=  2*cao_double;	else  if(  pai_destination[c10]  =  "s"  )  s_score  *=  2*cao_double;		//check  if  anyone  collected  all  hong.	hong_dest  =  pai_destination[convert_to_id("hong",  1)];	for  (i=2;  i<=13;  i++)	{		if(  pai_destination[convert_to_id("hong",  i)]  !=  hong_dest  )  			return;	}	//now  all  hong  in  one  place.	if(  hong_dest  ==  "e"  )  e_score  =  -e_score;	else  if(  hong_dest  ==  "w"  )  w_score  =  -w_score;	else  if(  hong_dest  ==  "n"  )  n_score  =  -n_score;	else  if(  hong_dest  ==  "s"  )  s_score  =  -s_score;	}void  show_table(int  out){//if  out==0,  tell  player,  otherwise  tell  room.    	object  players;	int  i,  j,  rd;	string  msg,  e_msg,  w_msg,  n_msg,  s_msg;	if(  out  ==  0  )	{		msg  =  "东家:";		if(  objectp(players=present(e_id,  this_object()))  &&  living(players)  )			msg  +=  players->query("name")+";";		else  msg  +=  "暂缺;";  		msg  +=  "南家:";		if(  objectp(players=present(s_id,  this_object()))  &&  living(players)  )			msg  +=  players->query("name")+";";		else  msg  +=  "暂缺;";  		msg  +=  "西家:";		if(  objectp(players=present(w_id,  this_object()))  &&  living(players)  )			msg  +=  players->query("name")+";";		else  msg  +=  "暂缺;";  		msg  +=  "北家:";		if(  objectp(players=present(n_id,  this_object()))  &&  living(players)  )			msg  +=  players->query("name")+"\n\n";		else  msg  +=  "暂缺。\n\n";		if(  game_status  ==  1  )		{			if(  current_round_step  !=  0  )			{				msg  +=  "这一轮所出的牌:";				for(rd=1;  rd<=current_round_step;  rd++)				{					if  (  current_round_ids[rd]  <  pai_size  )						msg  +=  pai_name[current_round_ids[rd]];				}				msg  +=  "\n";			}			if(  objectp(players=present(who_to_play,  this_object()))  &&  living(players)  )				msg  +=  "下面该"+players->query("name")+"出牌。\n\n";			else  msg  +=  "下面该???出牌。\n\n";		}  		write(msg);	}	j  =  0;	msg  =  "已出的牌有:\n";	for(i=0;  i<pai_size;  i++)	{		if(  (i==13  ||    i==26  ||  i==39  ||  i==52)  )  		{			msg  +=  "\n";			j  =  0;		}		if(  pai_state[i]  ==  "t"  )  		{			j++;			msg  +=  pai_name[i];			if(  j==7  &&  (i!=12&&i!=25&&i!=38&&i!=51)  )			{				j  =  0;				msg  +=  "\n";			}		}	}	if(  out  )  tell_room(this_object(),  msg+"\n\n");	else  write(msg+"\n\n");	e_msg  =  "东家所得牌:\n";	w_msg  =  "西家所得牌:\n";	n_msg  =  "北家所得牌:\n";	s_msg  =  "南家所得牌:\n";	for(i=0;  i<52;  i++)	{		if(pai_destination[i]  ==  "e")  e_msg  +=  pai_name[i];		else  if(pai_destination[i]  ==  "w")  w_msg  +=  pai_name[i];		else  if(pai_destination[i]  ==  "n")  n_msg  +=  pai_name[i];		else  if(pai_destination[i]  ==  "s")  s_msg  +=  pai_name[i];	}	if(  out  )	{		tell_room(this_object(),  e_msg+"\n");		tell_room(this_object(),  s_msg+"\n");		tell_room(this_object(),  w_msg+"\n");		tell_room(this_object(),  n_msg+"\n");	}	else	{		write(e_msg+"\n");		write(s_msg+"\n");		write(w_msg+"\n");		write(n_msg+"\n");	}	}void  show_score(){	if(  game_id  ==  0  )	{  		write("拱猪还没开张,没有任何分数。\n");		return;	}  	if(  game_status  ==  1  )  	{		write("拱猪正在进行,这一局的分数还没出来。\n");		write("上一局的结果是:\n");	}	else    write("最新战况:\n");	write("东家:"+sprintf("%d",  e_score)+"分。\n");	write("南家:"+sprintf("%d",  s_score)+"分。\n");	write("西家:"+sprintf("%d",  w_score)+"分。\n");	write("北家:"+sprintf("%d",  n_score)+"分。\n");}int  do_leave(){	string  my_id;	object  me  =  this_player();	my_id  =  me->query("id");	if(  my_id  !=  e_id  &&  my_id  !=  w_id  &&  my_id  !=  n_id  &&  my_id  !=  s_id  )		return  notify_fail("你并没有参加拱猪。\n");	if(  my_id  ==  e_id  )  e_id  =  "no  one";	else  if(  my_id  ==  w_id  )  w_id  =  "no  one";	else  if(  my_id  ==  n_id  )  n_id  =  "no  one";	else  if(  my_id  ==  s_id  )  s_id  =  "no  one";	message_vision("$N说道:对不起,你们找人接替吧,我不玩了。\n",  me);	return  1;}int  do_double(string  arg){	int  i,  pai_on_table;	string  my_id,  dir;	object  me  =  this_player();	my_id  =  me->query("id");	if(  my_id  !=  e_id  &&  my_id  !=  w_id  &&  my_id  !=  n_id  &&  my_id  !=  s_id  )		return  notify_fail("你并没有参加拱猪。\n");	if(game_status  ==  0)  return  notify_fail("拱猪还没开始。\n");	pai_on_table  =  0;	for(i=0;  i<pai_size;  i++)	{		if(  pai_state[i]  ==  "t"  )  pai_on_table++;	}	if  (  pai_on_table  !=  0  )  return  notify_fail("太晚了。\n");		if(!arg||(arg!="zhu"&&arg!="z"&&		arg!="yang"&&arg!="y"&&		arg!="hong"&&arg!="h"&&		arg!="bian"&&arg!="b"))  		return  notify_fail("你要亮什么?\n");	if(  my_id  ==  e_id  )  dir="e";	else  if(  my_id  ==  w_id  )  dir="w";	else  if(  my_id  ==  n_id  )  dir="n";	else  if(  my_id  ==  s_id  )  dir="s";	if(arg=="zhu"||arg=="z")	{		if(  pai_state[convert_to_id("hei",  12)]  ==  dir  )		{			pig_double  =  2;			message_vision("$N奸笑了几声:嘿嘿,我有猪,你们得小心点。\n",  me);				return  1;		}		else  return  notify_fail("你手头并没有猪。\n");	}	else  if(arg=="yang"||arg=="y")	{		if(  pai_state[convert_to_id("fang",  11)]  ==  dir  )		{			yang_double  =  2;			message_vision("$N兴奋地叫道:我有羊!\n",  me);				return  1;		}		else  return  notify_fail("别做梦了。\n");	}	else  if(arg=="hong"||arg=="h")	{		if(  pai_state[convert_to_id("hong",  1)]  ==  dir  )		{			hong_double  =  2;			message_vision("$N大声道:现在我宣布,红心提价!\n",  me);				return  1;		}		else  return  notify_fail("你没有红心尖。\n");	}	else  if(arg=="bian"||arg=="b")	{		if(  pai_state[convert_to_id("cao",  10)]  ==  dir  )		{			cao_double  =  2;			message_vision("$N躲在一边偷偷直笑:变压器的油可是加满了!\n",  me);				return  1;		}		else  return  notify_fail("你还是先弄个变压器再说吧。\n");	}	return  1;}int  do_start(){	int  need_players;    	object  players,  me;	string  my_id;		need_players  =  0;	me  =  this_player();	my_id  =  me->query("id");	if(game_status  ==  1)  return  notify_fail("拱猪已经开始了。\n");	if(  my_id  !=  e_id  &&  my_id  !=  w_id  &&  my_id  !=  n_id  &&  my_id  !=  s_id  )		return  notify_fail("你还没坐下来呢。\n");	if(  !objectp(players=present(e_id,  this_object()))  )  		need_players++;	if(  !objectp(players=present(w_id,  this_object()))  )  		need_players++;	if(  !objectp(players=present(n_id,  this_object()))  )  		need_players++;	if(  !objectp(players=present(s_id,  this_object()))  )  		need_players++;		if(  need_players  >  0  )  return  notify_fail("还得找"+chinese_number(need_players)+"个人才能开拱。\n");	//now  start  game.	game_status  =  1;	game_id  ++;	call_out("check_finish",  1800,  game_id);  //30  minutes	message_vision("$N大声宣布:拱猪正式开始!\n",  me);	send_pai();		who_to_play  =  my_id;	tell_room(this_object(),  "下面由"+me->query("name")+"开牌。\n");	message_vision("$N问道:有亮相的没有?没有我可出牌了!\n",  me);	current_round_step  =  1;  //set  it  to  1  as  the  beginning.	return  1;}void  send_pai(){//send  pai  out  to  players...	int  remain,  one_set;	string  dir;	int  i,  j,  k,  which;	remain  =  pai_size;	for(k=0;  k<pai_size;  k++)	{		one_set  =  0;		if(k<13)  dir="e";		else  if(k<26)  dir="w";		else  if(k<39)  dir="n";		else  if(k<pai_size)  dir="s";		else  dir="t";		which  =  random(remain);				j=  0;		for(i=0;  i<pai_size;  i++)		{			if(pai_state[i]  ==  "i")  			{				if(j==which)  				{					if(one_set  ==  0)					{						pai_state[i]  =  dir;						remain--;						one_set  =  1;					}				}				j++;  			}			}//sent  out  1  pai.	}//all  pai  sent  out.	}int  do_look(string  arg){	if(arg  ==  "table")	{		show_table(0);		return  1;	}	else  if(arg  ==  "score")	{		show_score();		return  1;	}	else  return  0;	}int  do_my(){//check  my  pai.	int  i,  j;	object    me;	string  my_id;	string  dir,  msg;	me  =  this_player();	my_id  =  me->query("id");	if(game_status  ==  0)  return  notify_fail("拱猪还没开始。\n");	dir="no  dir";	if(  my_id  ==  e_id  )  dir="e";  	else  if(  my_id  ==  w_id  )  dir="w";	else  if(  my_id  ==  n_id  )  dir="n";	else  if(  my_id  ==  s_id  )  dir="s";	else  return  notify_fail("你并没有加入拱猪。\n");	msg  =  "你手头的牌有:\n";	j  =  0;	for(i=0;  i<pai_size;  i++)	{		if(  (i==13  ||    i==26  ||  i==39  ||  i==52)  )  		{			msg  +=  "\n";			j  =  0;  //started  another  kind  of  pai.		}		if(  pai_state[i]  ==  dir  )  		{			j++;			msg  +=  pai_name[i];			if(  j==7  &&  (i!=12&&i!=25&&i!=38&&i!=51)  )			{				j  =  0;				msg  +=  "\n";			}		}	}		write(msg+"\n\n");	return  1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?