资源简介

linux终端上C语言程序,3个兵种 两种模式

资源截图

代码片段和文件信息

#include
#include
#include
#define MAX 100
#define MIN 100
#define MONEY 10000
#define SOLDIERS 1000

struct soldier_attribute{
char name;
int move;
int hp;
int defense;
int attack;
int prize;
int attack_distanse;
int enemy_friend;
}s[2500]={{‘K‘220051520011}{‘I‘115021010011}{‘B‘110002015031}};
struct num_of_soldier{
int nk1;
int ni1;
int nb1;
int nk2;
int ni2;
int nb2;
}num;

void delay(int);
void print_menu();
void print_space();
void chushihua(struct soldier_attribute s[]struct num_of_soldier *pn);
void print_scene(struct soldier_attribute s[]int t);
void range_empty(struct soldier_attribute s[]int nint nearestint total);
int kill_once(struct soldier_attribute s[]int nint total);
int enemy_nearest(struct soldier_attribute s[]int nint total);
int soldier_numbers1(struct soldier_attribute s[]int total);
int soldier_numbers2(struct soldier_attribute s[]int total);
int distanse_under_range(struct soldier_attribute s[]int nint nearestint total);
int choise();
int mode_choise();
void soldier_choise(int n1int *pkint *piint *pb);

int main()
{
int knight_number1=0infantry_number1=0bowman_number1=0knight_number2=0infantry_number2=0bowman_number2=0;
int n;
int ijnearestdisk;
struct num_of_soldier *pn;
int soldier_number1soldier_number2;
int total;

pn=#
print_menu();

n=mode_choise();
puts(“choose soldiers“);
puts(“player 1 to choose“);
soldier_choise(n&knight_number1&infantry_number1&bowman_number1);
puts(“player 2 to choose“);
soldier_choise(n&knight_number2&infantry_number2&bowman_number2);

printf(“player 1       player 2\n“);
printf(“knight---%3d   knight---%3d   \n“knight_number1knight_number2);
printf(“infantry--%3d  infantry--%3d  \n“infantry_number1infantry_number2);
printf(“bowman---%3d   bowman---%3d   \n“bowman_number1bowman_number2);

num.nk1=knight_number1;
num.ni1=infantry_number1;
num.nb1=bowman_number1;
num.nk2=knight_number2;
num.ni2=infantry_number2;
num.nb2=bowman_number2;
soldier_number1=pn->nk1+pn->ni1+pn->nb1;
soldier_number2=pn->nk2+pn->ni2+pn->nb2;
total=soldier_number2+soldier_number1+240;
puts(“start the war: 1---start  2---exit“);
n=choise();

switch(n)
{
case 1:
j=0;
chushihua(spn);
printf(“\nplayer1‘s arm lef:%d  player2‘s arm lef:%d\n“soldier_number1soldier_number2);
print_space();
print_scene(stotal);
while(soldier_number1>0&&soldier_number2>0)           
{
for(i=0;i {
nearest=enemy_nearest(sitotal);
if(s[i].hp>0&&nearest>=0)
{
dis=distanse_under_range(sinearesttotal);
k=kill_once(sitotal);
if(dis>=0)
{
if(k>=0)
{
s[k].hp=-1;
s[k].name=‘-‘;
s[k].enemy_friend=0;
}
else 
{
s[nearest].hp=s[nearest].hp-s[i].attack+s[nearest].defe

评论

共有 条评论