#include<stdio.h>
#include<string.h>
///////////////////
struct Role{
int attack;//攻擊力
int health;//血量
int magic;//法力值
};
///////////////////
struct Role Player[4][7];//創建陣列,第0行和地3行存放角色位置,中間兩行存放隨從;
int Role_Num[2]={1,1};//表示雙方角色數量(包括英雄和隨從)
///////////////////
struct Retinue{
char name[10];//設隨從編號
struct Role role;
};
///////////////////
void Order_Call(int who,int Nob,int pos,Role R[]){//who表示行動方編號;name表示隨從編號;pos表示召喚隨從處于位置
int i;
if(who==0){
if(pos>0){
Role_Num[who]++;//每召喚一次,隨從數量加一
}
for(i=Role_Num[who];i>pos;i--){
Player[who+1][i]=Player[who+1][i-1];//位置Pos中和右側隨從都要向右移動一個位置,以讓剛召喚的隨從放置在pos位置
}
Player[who+1][pos].attack=R[Nob].attack;
Player[who+1][pos].health=R[Nob].health;
}
if(who==3){
if(pos>0){
Role_Num[who]++;//每召喚一次,隨從數量加一
}
for(i=Role_Num[who];i>pos;i--){
Player[who-1][i]=Player[who-1][i-1];//位置Pos中和右側隨從都要向右移動一個位置,以讓剛召喚的隨從放置在pos位置
}
Player[who-1][pos].attack=R[Nob].attack;
Player[who-11][pos].health=R[Nob].health;
}
}
///////////////////
void Order_Attack(int who,int pos1,int pos2){//who表示己方編號(0和3);pos1表示己方處于pos1位置的隨從攻擊處于pos2位置的對方隨從
if(who==0){
//0方血量變化
Player[who+1][pos1].health=Player[who+1][pos1].health-Player[who+2][pos2].attack;
if(Role_Num[1]>0){
Player[who+2][pos2].health=Player[who+2][pos2].health-Player[who+1][pos1].attack;
if(Player[who][pos1].health<=0){
Order_Remove(who+1,pos1);
}
if(Player[who+3][pos2].health<=0){
Order_Remove(who+3,pos2);
}
}
else{
Player[who+3][0].health=Player[who+3][0].health-Player[who+1][pos1].attack;//若該位置沒有隨從,則自動攻擊英雄
}
}
if(who==3){
//3方血量變化
Player[who][pos2].health=Player[who][pos2].health-Player[who-3][pos1].attack;
if(Role_Num[0]>0){
Player[who-3][pos1].health=Player[who-3][pos1].health-Player[who][pos2].attack;
if(Player[who][pos2].health<=0){
Order_Remove(who,pos2);
}
if(Player[who-3][pos1].health<=0){
Order_Remove(who-3,pos1);
}}
}
else{
Player[who-3][0].health=Player[who-3][0].health-Player[who-1][pos2].attack;
}
}
///////////////////
int Order_Remove(int who,int pos){//who表示己方編碼;pos表示隨從位置
int i;
if(pos>0){
for(i=pos;i<Role_Num[who];i++){
if(who==0){
Player[who+1][i]=Player[who+1][i+1];//移除pos位置的隨從,pos右側的隨從都要向左移動一個位置
}
if(who==3){
Player[who-1][i]=Player[who-1][i+1];//移除pos位置的隨從,pos右側的隨從都要向左移動一個位置
}
}
}
Role_Num[who]--;//角色數量-1
return 0;
}
///////////////////
void main(){
int r;
int M;//表示命令編號
int m;
int who;
int pos1,pos2;
//**********第一部分:列印隨從庫************
//對隨從選擇庫進行賦值并列印顯示
struct Retinue R[]={{"一號",1,1,1},{"二號",2,2,2},{"三號",3,3,3},{"四號",4,4,4},{"五號",5,5,5},{"六號",6,6,6},{"七號",7,7,7},{"八號",8,8,8},{"九號",9,9,9}};//隨從賦值
//**********第二部分:初始英雄數值****************
Player[0][0].health=30;
Player[0][0].magic=2;
Player[3][0].health=30;
Player[3][0].magic=2;
//*********第三部分:操作界面*********************
while(1){
printf("1-顯示您能選擇的隨從\n");
printf("2-顯示您的狀態(血量|法力值|擁有隨從)\n");
printf("3-召喚隨從\n");
printf("4-攻擊命令\n");
printf("5-結束本回合\n");
printf("請輸入您需要的命令:\n");
scanf("%d",&M);
switch(M){
case 1://顯示您能選擇的隨從
printf("雙方現在可選擇的隨從庫:\n");
printf("\t|---------------------------|\n");
printf("\t|隨從編號|攻擊力|血量|消耗值|\n");
for(r=0;r<9;r++){
printf("\t| %s | %d | %d | %d |\n",R[r].name,R[r].role.attack,R[r].role.health,R[r].role.magic);
}
printf("\t|---------------------------|\n");
case 2://顯示您的狀態(血量|法力值|擁有隨從)
printf("請輸入要查詢的一方編碼(0或1)\n");
scanf("%d",&m);
switch(m){
case 0://[0方]
printf("[0方]血量:%d|法力值:%d|隨從數量:%d|\n\n",Player[0][0].health,Player[0][0].magic,Role_Num[0]-1);
break;
case 1://[3方]
printf("\n[3方]血量:%d|法力值:%d|隨從數量:%d|\n\n",Player[3][0].health,Player[3][0].magic,Role_Num[1]-1);
break;
}break;
case 3://召喚隨從
printf("還沒設計完畢,敬請期待\n");
case 4://攻擊命令
printf("輸入格式:\n");
printf("who pos1 pos2||您方編碼 您方隨從位置 對方隨從位置\n");
scanf("%d %d %d",&who,&pos1,&pos2);
if((who!=0||who!=3)&&(pos1<0||pos1>6)&&(pos2<0||pos2>6)){
printf("錯誤!!請輸入正確的編碼.\n");
}
else{
Order_Attack(who,pos1,pos2);
}
if(Player[0][0].health<=0){
printf("[3方]獲勝!!\n");
exit(0);
}
else if(Player[3][0].health<=0){
printf("[0方]獲勝!!\n");
exit(0);
}
else{
printf("雙方某一方仍存活,請繼續!\n");
}break;
case 5:
exit(0);//此處沒問題,可運行!!!
}
}
}
uj5u.com熱心網友回復:
/*****以下是除錯*****/1>------ 已啟動生成: 專案: LuShi, 配置: Debug Win32 ------
1> LuShi.c
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(25): error C2146: 語法錯誤: 缺少“)”(在識別符號“R”的前面)
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(25): error C2081: “Role”: 形參表中的名稱非法
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(25): error C2061: 語法錯誤: 識別符號“R”
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(25): error C2059: 語法錯誤:“;”
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(25): error C3409: 不允許空特性塊
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(25): error C2059: 語法錯誤:“)”
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(25): error C2059: 語法錯誤:“{”
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(61): warning C4013: “Order_Remove”未定義;假設外部回傳 int
1>c:\users\administrator\documents\visual studio 2012\projects\lushi\lushi\lushi.c(171): warning C4013: “exit”未定義;假設外部回傳 int
========== 生成: 成功 0 個,失敗 1 個,最新 0 個,跳過 0 個 ==========
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/60197.html
標籤:C語言
上一篇:C++ easyx
下一篇:將代碼修改了能在visual c++2010上運行,void beep()那里將開揚聲器,延時100秒關揚聲器修改成有個提示就行
