代码拉取完成,页面将自动刷新
#include "zgs.h"
int player_number, MP;
char identity,Identity;
Game game;
Pig player[MAX_PLAYER];
int kill[MAX_PLAYER],hur[MAX_PLAYER],cur[MAX_PLAYER];
bool dead[MAX_PLAYER];
int can_use(int id,char type){
for(int i=1;i<=player[id].card_number;i++)
if(player[id].card[i].type==type)
return i;
return 0;
}
void swap(int x,int y){
int z=x;
x=y;
y=z;
}
char* CARD_NAME(char s){
if(s=='K')return "杀";
if(s=='D')return "闪";
if(s=='P')return "桃";
if(s=='F')return "决斗";
if(s=='Z')return "诸葛连弩";
if(s=='N')return "南蛮入侵";
if(s=='W')return "万箭齐发";
if(s=='J')return "无懈可击";
return "???";
}
char* ID_NAME(char s){
if(s=='M')return "主公";
if(s=='F')return "反贼";
if(s=='Z')return "忠臣";
if(s=='R')return "随机";
if(s=='N')return "无(旁观模式)";
return "???";
}
int dis(int x,int y){
int ret1=1,ret2=1;
if(x>y)swap(x,y);
for(int i=x+1;i<y;i++)if(!is_dead(i))ret1++;
for(int i=1;i<x;i++)if(!is_dead(i))ret2++;
for(int i=y+1;i<=player_number;i++)if(!is_dead(i))ret2++;
return ret1<ret2?ret1:ret2;
}
Card get_a_card(){
Card ret;
int rnd=rand()%80;
if(rnd<29)ret.type='K';
else if(rnd<29+14) ret.type='D';
else if(rnd<29+14+8) ret.type='P';
else if(rnd<29+14+8+10) ret.type='F';
else if(rnd<29+14+8+20) ret.type='Z';
else if(rnd<29+14+8+20+3) ret.type='N';
else if(rnd<29+14+8+20+3+3) ret.type='W';
else if(rnd<29+14+8+20+3+3+3) ret.type='J';
return ret;
}
void use(int id,int cardid){
for(int i=cardid;i<player[id].card_number;i++)
player[id].card[i]=player[id].card[i+1];
player[id].card_number--;
puts("");
}
void show_pig(int id, bool hide){
printf("Player[%d](%s)%s: Health:%d Weapon:%s Cards:%d\n",id,player[id].is_human?"Human":"AI",MP==id||player[id].is_human?ID_NAME(player[id].id):(is_fp(id)?"已跳反":is_zp(id)?"已跳忠":""),player[id].health,player[id].has_z?CARD_NAME('Z'):"None",player[id].card_number);
//printf("Identity:%c\n",player[id].id);
//printf("Has weapon:%d\n",player[id].has_z);
if(!hide){
printf(" Cards:\n ");
for(int i=1;i<=player[id].card_number;i++)
printf("(#%d)%s ",i,CARD_NAME(player[id].card[i].type));
puts("");
}
puts("");
}
void reset_game(){
memset(dead,0,sizeof dead);
memset(kill,0,sizeof kill);
memset(hur,0,sizeof hur);
memset(cur,0,sizeof cur);
identity=Identity;
}
void game_init(){
srand(time(0));
Identity=DEFAULT_IDENTITY;
game.MP_number=DEFAULT_MP_NUMBER;
game.ZP_number=DEFAULT_ZP_NUMBER;
game.FP_number=DEFAULT_FP_NUMBER;
player_number=game.MP_number+game.ZP_number+game.FP_number;
reset_game();
}
void game_edit(){
do{
puts("-------------");
printf("Now %s:%d %s:%d %s:%d\n",ID_NAME('M'),game.MP_number,ID_NAME('Z'),game.ZP_number,ID_NAME('F'),game.FP_number);
printf("Total:%d Player(s)\n",game.MP_number+game.ZP_number+game.FP_number);
puts("1.Add/Del player(s)");
puts("2.Change your identity");
puts("3.Exit");
int opt=read_number();
switch(opt){
case 1:{
printf("M -> %s\n",ID_NAME('M'));
printf("Z -> %s\n",ID_NAME('Z'));
printf("F -> %s\n",ID_NAME('F'));
char ch=getchar();
while(ch!='M'&&ch!='Z'&&ch!='F')ch=getchar();
printf("Number of %s you want to add(Negative number to del)\n",ID_NAME(ch));
int opt=read_number();
switch(ch){
case 'M':{
int newmp=game.MP_number+opt;
if(newmp>1){
printf("Too many %s\n",ID_NAME('M'));
}else if(newmp<1){
printf("Too few %s\n",ID_NAME('M'));
}
break;
}
case 'Z':{
int newzp=game.ZP_number+opt;
if(newzp<0){
printf("Too few %s\n",ID_NAME('Z'));
}else{
game.ZP_number=newzp;
}
break;
}
case 'F':{
int newfp=game.FP_number+opt;
if(newfp<0){
printf("Too few %s\n",ID_NAME('F'));
}else{
game.FP_number=newfp;
}
break;
}
}
break;
}
case 2:{
printf("Now your are %c\n",Identity);
printf("R -> %s\n",ID_NAME('R'));
printf("M -> %s\n",ID_NAME('M'));
printf("Z -> %s\n",ID_NAME('Z'));
printf("F -> %s\n",ID_NAME('F'));
printf("N -> %s\n",ID_NAME('N'));
char ch=getchar();
while(ch!='R'&&ch!='M'&&ch!='Z'&&ch!='F'&&ch!='N')ch=getchar();
Identity=ch;
break;
}
case 3: return;
}
}while(1);
}
void give_up(int id){
printf("Player[%d] throw out all the cards.\n",id);
player[id].card_number=0;
player[id].has_z=0;
}
bool is_dead(int id){
if(dead[id])return 1;
if(player[id].health>0)return 0;
printf("Player[%d] is dying...\n",id);
if(can_use(id,'P')){
use_p(id);
return 0;
}else{
dead[id]=1;
return 1;
}
}
int game_end(){
if(is_dead(MP))return -1;
int flag=1;
for(int i=1;i<=player_number;i++)
if(player[i].id=='F'&&!is_dead(i)){
flag=0;
break;
}
return flag;
}
void show_pigs(){
for(int i=1;i<=player_number;i++)if(!is_dead(i)){
show_pig(i,0);
}
}
void game_start(){
CLEAR;
puts("Game starting...");
printf("Now %s:%d %s:%d %s:%d\n",ID_NAME('M'),game.MP_number,ID_NAME('Z'),game.ZP_number,ID_NAME('F'),game.FP_number);
printf("Total:%d Player(s)\n",game.MP_number+game.ZP_number+game.FP_number);
puts("");
puts("============================================================");
for(int i=1;i<=game.MP_number;i++)
player[i].id='M';
for(int i=1;i<=game.ZP_number;i++)
player[i+game.MP_number].id='Z';
for(int i=1;i<=game.FP_number;i++)
player[i+game.MP_number+game.ZP_number].id='F';
player_number=game.MP_number+game.ZP_number+game.FP_number;
for(int i=1;i<=player_number;i++){
player[i].card_number=0;
player[i].health=4+(MP==i);
player[i].is_human=0;
player[i].has_z=0;
player[i].Loyalty_or_opposition=0;
for(int j=1;j<=4;j++){
player[i].card_number++;
player[i].card[player[i].card_number]=get_a_card();
}
}
if(identity=='R'){
int rnd=rand()%3;
while((rnd==0&&game.MP_number==0)||(rnd==1&&game.ZP_number==0)||(rnd==2&&game.FP_number==0)){
rnd=rand()%3;
}
if(rnd==0){
identity='M';
player[1].is_human=1;
}
else if(rnd==1){
identity='Z';
player[1+game.MP_number].is_human=1;
}else{
identity='F';
player[1+game.MP_number+game.ZP_number].is_human=1;
}
}
//shuffle the order
for(int i=1;i<=player_number;i++){
int j=rand()%i+1;
Pig temp=player[i];
player[i]=player[j];
player[j]=temp;
}
int cur_player=-1;
for(int i=1;i<=player_number;i++)
if(player[i].id=='M'){
cur_player=i;
MP=i;
break;
}
while(!game_end()){
if(!is_dead(cur_player)){
puts("-----------------------------------------------");
if(player[cur_player].is_human){
human_play(cur_player);
}else{
show_pig(cur_player,1);
pick_card(cur_player,2);
while(can_use(cur_player,'Z'))
use_z(cur_player);
cure(cur_player);
attack(cur_player);
}
}
cur_player=cur_player%player_number+1;
}
puts("===========================");
printf("Game end. Winner is %s\n",game_end()==1?"主公 & 忠臣":"反贼");
puts("Summry:");
puts("Player Controller Identity Kill Death Hurt Cure");
for(int i=1;i<=player_number;i++)
printf(" %2d %-12s %-7s %4d %5d %4d %4d\n",i,player[i].is_human?"Human":"AI",ID_NAME(player[i].id),kill[i],is_dead(i),hur[i],cur[i]);
char ch=getchar();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。