⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 puke-room.c

📁 C实现的MUD,对大家基本入门网络游戏很有帮助!
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  <SecCrypt CPL V3R05>  */ //puke-room.c...weiqi,  98/01/18//扑克牌。inherit  ROOM;string  *pai_name  =  ({"【黑A】",  "【黑2】",  "【黑3】",  "【黑4】",  "【黑5】",  "【黑6】",  "【黑7】",  "【黑8】",  "【黑9】",  "【黑十】",  "【黑J】",  "【黑Q】",  "【黑K】",  "【红A】",  "【红2】"  ,"【红3】",  "【红4】",  "【红5】",  "【红6】",  "【红7】",  "【红8】",  "【红9】",  "【红十】",  "【红J】",  "【红Q】",  "【红K】",  "【草A】",  "【草2】",  "【草3】",  "【草4】",  "【草5】",  "【草6】",  "【草7】",  "【草8】",  "【草9】",  "【草十】",  "【草J】",  "【草Q】",  "【草K】",  "【方A】",  "【方2】",  "【方3】",  "【方4】",  "【方5】",  "【方6】",  "【方7】",  "【方8】",  "【方9】",  "【方十】",  "【方J】",  "【方Q】",  "【方K】",  "【小王】",  "【大王】"});int  pai_size  =  sizeof(pai_name)-2;//for  gongzhu,  it's  52.string  *pai_state  =  ({"i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i"});//here  state  can  be  i(initial),  t(table),  n(north),  s(south),  w(west),  e(east).string  *pai_destination  =  ({"i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i",  "i"});//here  destination  can  be  i(initial),  t(table),  n(north),  s(south),  w(west),  e(east).//this  is  mainly  for  score.string  e_id  =  "no  one";string  w_id  =  "no  one";string  n_id  =  "no  one";string  s_id  =  "no  one";string  who_to_play  =  "no  one";  int  e_score  =  0;int  w_score  =  0;int  n_score  =  0;int  s_score  =  0;int  cao_double  =  1;  //can  be  1  or  2.int  hong_double  =  1;  //can  be  1  or  2.int  pig_double  =  1;  //can  be  1  or  2.int  yang_double  =  1;  //can  be  1  or  2.//last  pai  played.int  e_last  =  pai_size;  int  w_last  =  pai_size;  int  n_last  =  pai_size;  int  s_last  =  pai_size;  int  game_id  =  0;  //how  many  games  processed.int  round  =  0;  //this  indicates  how  many  rounds  processed.string  current_round_kind  =  "none";  //kind  this  round.int  current_round_step  =  0;  //can  be  0,  1,  2,  3,  4.int  *current_round_ids  =  ({53,  53,  53,  53,  53});  //the  first  element  is  reserved.int  game_status  =  0;//=0,  no  game  yet.//=1,  game  in  process.string  check_kind(int  i);int  check_rank(int  i);int  check_score(int  i);int  pai_compare(int  p1,  int  p2);int  convert_to_id(string  kind,  int  rank);void  game_process();string  get_next_player();void  game_finished();void  calculate_score();void  show_table(int  out);void  show_score();void  send_pai();string  chinese_dir(string  dir);void  game_reset();void  check_finish(int  previous_game_id);void  create  (){	set  ("short",  "拱猪房");	set  ("long",  @LONG屋中间摆着一张看起来相当结实的大方桌(table),桌边围着四把靠背木椅。东面墙上有一块大牌子(paizi),西面墙上有一块小牌子(score)。LONG);	set("item_desc",  (["paizi"  :  "拱猪规则:主要指令有:一,就坐(sit  <n,  s,  e,  w>)。二,开拱(start)。三,出牌(play  <花色>  <大小>)。  花色有(hei,  hong,  cao,  fang)或用(S/s,  H/h,  C/c,  D/d)来代表。  大小有(1,  ...,  13)或用(A/a,  J/j,  Q/q,  K/k)来代表(1,  11,  12,  13)。四,好牌亮相(double  <zhu/z,  yang/y,  hong/h,  bian/b>)。五,查自己的牌(my)。六,看桌面情况(look  table)。七,看积分(look  score)。八,退出拱猪(leave)。注意事项:一,要端正牌风,系统不揭发舞弊。二,每一盘必须在半小时内完成,否则取消重来。二,有任何bug请报告巫师。目前是测试阶段,可能还有不少错。		\n"  ]));	//for  look  something.	set("exits",  	([  //sizeof()  ==  4		//"south"  :  __DIR__"xiaomuwu",		//"north"  :  __DIR__"chufang",		//"west"  :  __DIR__"duchang2",		"west"  :  __DIR__"clubpoem",		//"up"  :  __DIR__"***",		//"down"  :  __DIR__"***",	]));		set("objects",  	([  //sizeof()  ==  1		//__DIR__"npc/gongsun"  :  1,	]));	//set("outdoors",  "city");	set("no_fight",  1);	set("no_magic",  1);		set("no_clean_up",  1);	setup();}void  init(){	add_action("do_sit",  "sit");	add_action("do_play",  "play");	add_action("do_double",  "double");	add_action("do_leave",  "leave");	add_action("do_start",  "start");		add_action("do_look",  "look");	add_action("do_my",  "my");}string  check_kind(int  i){	if(  i  <  0  )  return  "none";	else  if(  i  <  13  )    return  "hei";	else  if(  i  <  26  )    return  "hong";	else  if(  i  <  39  )    return  "cao";	else  if(  i  <  52  )    return  "fang";	else  if(  i  ==  52  )    return  "xwang";	else  if(  i  ==  53  )    return  "dwang";	else  return  "none";}int  check_rank(int  i){	int  rank;	if(  i  <  0  )  rank  =  0;	else  if(  i  <  52  )  	{		rank  =  1+(i%13);		if  (  rank  ==  1  )  rank  =  14;  //this  is  for  A.	}	else  rank  =  1+i;	return  rank;}int  check_score(int  i){	int  rank;	if(pai_name[i]=="【黑Q】")  return  100*pig_double;	if(pai_name[i]=="【方J】")  return  -100*yang_double;	if(pai_name[i]=="【草十】")  return  -10;	if(check_kind(i)  !=  "hong"  )  return  0;	rank  =  check_rank(i);	if(  rank  <  5  )  return  0;	else  if  (  rank  <=  10  )  return  10*hong_double;	else  return  (rank-9)*10*hong_double;  }int  convert_to_id(string  kind,  int  rank){	if(  kind  ==  "xwang"  )  return  52;	if(  kind  ==  "dwang"  )  return  53;	if(  rank  ==  14  )  rank  =  1;  	//this  is  for  A.	//but  can  also  be  sent  in  as  1  here.		if(  kind  ==  "hei"  )  return  (rank  -1);	else  if(  kind  ==  "hong"  )  return  (rank  +12);  	else  if(  kind  ==  "cao"  )  return  (rank  +25);  	else  if(  kind  ==  "fang"  )  return  (rank  +38);	else  return  53;  	}string  chinese_dir(string  dir){	if(dir  ==  "east"  ||  dir  ==  "e")  return  "东";	else  if(dir  ==  "west"  ||  dir  ==  "w")  return  "西";	else  if(dir  ==  "south"  ||  dir  ==  "s")  return  "南";	else  if(dir  ==  "north"  ||  dir  ==  "n")  return  "北";	else  if(dir  ==  "up"  ||  dir  ==  "u")  return  "上";	else  if(dir  ==  "down"  ||  dir  ==  "d")  return  "下";	else  if(dir  ==  "left"  ||  dir  ==  "l")  return  "左";	else  if(dir  ==  "right"  ||  dir  ==  "r")  return  "右";	else  return  "?";}int  do_sit(string  arg){	string  dir,  my_id;	object  players;	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(!arg)  return  notify_fail("你要坐哪边?\n");	if  (  arg  ==  "east"  ||  arg  ==  "e"  )	{		if(  objectp(players=present(e_id,  this_object()))  &&  living(players)  )  		{			return  notify_fail("东座已经有人了。\n");		}		else  		{			e_id  =  my_id;			message_vision("$N坐上了东边的椅子。\n",  me);			return  1;		}	}	else  if  (  arg  ==  "west"  ||  arg  ==  "w"  )	{		if(  objectp(players=present(w_id,  this_object()))  &&  living(players)  )  		{			return  notify_fail("西座已经有人了。\n");		}		else  		{			w_id  =  my_id;			message_vision("$N坐上了西边的椅子。\n",  me);			return  1;		}	}	else  if  (  arg  ==  "north"  ||  arg  ==  "n"  )	{		if(  objectp(players=present(n_id,  this_object()))  &&  living(players)  )  		{			return  notify_fail("北座已经有人了。\n");		}		else  		{			n_id  =  my_id;			message_vision("$N坐上了北边的椅子。\n",  me);			return  1;		}	}	else  if  (  arg  ==  "south"  ||  arg  ==  "s"  )	{		if(  objectp(players=present(s_id,  this_object()))  &&  living(players)  )  		{			return  notify_fail("南座已经有人了。\n");		}		else  		{			s_id  =  my_id;			message_vision("$N坐上了南边的椅子。\n",  me);			return  1;		}	}	else  return  notify_fail("你要坐哪边?\n");}int  do_play(string  arg){	object  players;	object  me;	int  rank;	string  kind,  rank_str,  my_id;	int  pai_id;	string  pai_owner;	me=this_player();	my_id  =  me->query("id");	//check  if  I  am  playing...	if(  my_id  !=  e_id  &&  my_id  !=  w_id  &&  my_id  !=  n_id  &&  my_id  !=  s_id  )		return  notify_fail("观牌不语真君子。\n");	//everyone  is  here?	if(!objectp(players=present(e_id,  this_object()))  )	{		e_id  =  "no  one";		return  notify_fail("东家不在了。找人来替补吧。\n");	}	if(!objectp(players=present(w_id,  this_object()))  )	{		w_id  =  "no  one";		return  notify_fail("西家不在了。找人来替补吧。\n");	}	if(!objectp(players=present(n_id,  this_object()))  )	{		n_id  =  "no  one";		return  notify_fail("北家不在了。找人来替补吧。\n");	}	if(!objectp(players=present(s_id,  this_object()))  )	{		s_id  =  "no  one";		return  notify_fail("南家不在了。找人来替补吧。\n");	}	//who  to  play?	if(my_id  !=  who_to_play  )		return  notify_fail("还没到你出牌。\n");	if(  (!  arg)  ||  (sscanf  (arg,"%s  %s",  kind,  rank_str)  !=  2))		return  notify_fail("请使用:play  <花色>  <大小>\n");	//convert...	if(  kind  ==  "S"  ||  kind  ==  "s"  )  kind  =  "hei";	else  if(  kind  ==  "H"  ||  kind  ==  "h"  )  kind  =  "hong";	else  if(  kind  ==  "C"  ||  kind  ==  "c"  )  kind  =  "cao";	else  if(  kind  ==  "D"  ||  kind  ==  "d"  )  kind  =  "fang";	else  if(  kind  ==  "hei"  ||  kind  ==  "hong"  ||  kind  ==  "cao"  ||  kind  ==  "fang"  )  kind  =  kind;//do  nothing  here.	else  return  notify_fail("花色只有(hei,  hong,  cao,  fang)或用(S/s,  H/h,  C/c,  D/d)来代表。\n");	if(  rank_str  ==  "1"  ||  rank_str  ==  "A"  ||  rank_str  ==  "a"  )  rank  =  1;	else  if(  rank_str  ==  "2")  rank  =  2;  	else  if(  rank_str  ==  "3")  rank  =  3;  	else  if(  rank_str  ==  "4")  rank  =  4;  	else  if(  rank_str  ==  "5")  rank  =  5;  	else  if(  rank_str  ==  "6")  rank  =  6;  	else  if(  rank_str  ==  "7")  rank  =  7;  	else  if(  rank_str  ==  "8")  rank  =  8;  	else  if(  rank_str  ==  "9")  rank  =  9;  	else  if(  rank_str  ==  "10")  rank  =  10;  	else  if(  rank_str  ==  "11"  ||  rank_str  ==  "J"  ||  rank_str  ==  "j"  )  rank  =  11;	else  if(  rank_str  ==  "12"  ||  rank_str  ==  "Q"  ||  rank_str  ==  "q"  )  rank  =  12;	else  if(  rank_str  ==  "13"  ||  rank_str  ==  "K"  ||  rank_str  ==  "k"  )  rank  =  13;	else  return  notify_fail("大小只有(1,  ...,  13)或用(A/a,  J/j,  Q/q,  K/k)来代表(1,  11,  12,  13)。\n");		//if  I  have  this  pai.		pai_id  =  convert_to_id(kind,  rank);	if(  pai_id  <  0  ||  pai_id  >=  pai_size)  //note,  here  no  wang.		return  notify_fail("没有这张牌。\n");	if(  pai_state[pai_id]  ==  "e"  )  pai_owner  =  e_id;	else  if(  pai_state[pai_id]  ==  "w"  )  pai_owner  =  w_id;	else  if(  pai_state[pai_id]  ==  "n"  )  pai_owner  =  n_id;	else  if(  pai_state[pai_id]  ==  "s"  )  pai_owner  =  s_id;	else  if(  pai_state[pai_id]  ==  "t"  )  return  notify_fail("这张牌出过了。\n");	else  return  notify_fail("奇怪,这张牌丢了。\n");	if(  my_id  !=  pai_owner  )		return  notify_fail("你没有这张牌。\n");	//I    can  play  out  this  pai.	message_vision("$N打出一张"+pai_name[pai_id]+"。\n",  me);	if(  pai_state[pai_id]  ==  "e"  )  e_last  =  pai_id;	else  if(  pai_state[pai_id]  ==  "w"  )  w_last  =  pai_id;	else  if(  pai_state[pai_id]  ==  "n"  )  n_last  =  pai_id;	else  if(  pai_state[pai_id]  ==  "s"  )  s_last  =  pai_id;	else  tell_room(this_object(),  "出问题了(set  last  pai),叫巫师来吧。\n");	pai_state[pai_id]  =  "t";//mark  it  as  on  table.		game_process();	return  1;}void  game_process(){	object  next_player;	int  i,  pai_on_table;	int  rd;	string  rd_msg;	//check  score  for  this  round  if  needed.	pai_on_table  =  0;	for(i=0;  i<pai_size;  i++)	{		if(  pai_state[i]  ==  "t"  )  pai_on_table++;	}	current_round_step  =  pai_on_table%4;  //this  can  be  1,2,3,0.	if(  current_round_step  ==  0  &&  pai_on_table  !=  0)  		current_round_step  =  4;  //now  it'll  be  1,2,3,4(only  at  the  beginning,  0)	//set  curent  round's  pai.	if(  who_to_play  ==  e_id  )  		current_round_ids[current_round_step]  =  e_last  ;	else  if(  who_to_play  ==  w_id  )  		current_round_ids[current_round_step]  =  w_last  ;	else  if(  who_to_play  ==  n_id  )  		current_round_ids[current_round_step]  =  n_last  ;	else  if(  who_to_play  ==  s_id  )  		current_round_ids[current_round_step]  =  s_last  ;	else  		tell_room(this_object(),  "出问题了(set  current  ids),叫巫师来吧。\n");		//set  round  rank	if(  current_round_step  ==  1  )	{		if(  who_to_play  ==  e_id  )  			current_round_kind  =  check_kind(  e_last  );		else  if(  who_to_play  ==  w_id  )  			current_round_kind  =  check_kind(  w_last  );		else  if(  who_to_play  ==  n_id  )  			current_round_kind  =  check_kind(  n_last  );		else  if(  who_to_play  ==  s_id  )  			current_round_kind  =  check_kind(  s_last  );		else  			tell_room(this_object(),  "出问题了(set  current  kind),叫巫师来吧。\n");	}  	if(  current_round_step  ==  4  )	{//check  score...		who_to_play  =  get_next_player();	}	else	{//轮着排。		if(  who_to_play  ==  e_id  )  who_to_play  =  n_id;		else  if(  who_to_play  ==  n_id  )  who_to_play  =  w_id;		else  if(  who_to_play  ==  w_id  )  who_to_play  =  s_id;		else  if(  who_to_play  ==  s_id  )  who_to_play  =  e_id;		else  tell_room(this_object(),  "出问题了(shift  player),叫巫师来吧。\n");	}	if(  current_round_step  !=  0  )	{		rd_msg  =  "这一轮所出的牌:";		for(rd=1;  rd<=current_round_step;  rd++)		{			if  (  current_round_ids[rd]  <  pai_size  )				rd_msg  +=  pai_name[current_round_ids[rd]];		}		rd_msg  +=  "\n";		tell_room(this_object(),  rd_msg);	}	if  (pai_on_table  ==  pai_size)	{		call_out("game_finished",  1);		return;	}	if(objectp(next_player=present(who_to_play,  this_object()))  &&  living(next_player)  )	{		tell_room(this_object(),  "下面该"+next_player->query("name")+"出牌了。\n");	}	else	{		tell_room(this_object(),  "下一位出牌人跑了?\n");	}			}string  get_next_player(){	int  bigger;	string  dest;	string  next_player;	dest  =  "t";	next_player  =  "no  one";	if(  pai_compare(e_last,  w_last)  >  0  )  bigger  =  e_last;	else  bigger  =  w_last;	if(  pai_compare(n_last,  bigger)  >  0  )  bigger  =  n_last;	if(  pai_compare(s_last,  bigger)  >  0  )  bigger  =  s_last;	if(bigger  ==  e_last)	{		dest  =  "e";  

⌨️ 快捷键说明

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