|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<time.h>
#include<stdlib.h>
#include<stdio.h>//子弹那里错了,记得改 11.30
#include<string.h>/*有时会有开局杀是不是很惊喜!*/
int main(){
char ditu[9][9][3]={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
char wanjia[5]="玩家";
char diren[5]="敌军";
srand((unsigned)time(NULL));
int a = rand()%10;
int b = rand()%10;
int c = rand()%10;
int d = rand()%10;
int n=0,m=0,z;
char put[5];
printf("欢迎开始坦克大战!\n有时会有开局杀,好刺激的!\n本游戏采用wsad j模式\n另外,本游戏敌军优先级高于玩家哦。\n输入-1即可结束游戏,或者你被干翻");
do{
for(n=0;n<9;n++){
for(m=0;m<9;m++){
printf("%-4s",ditu[n][m]);
}
printf("\n");
}
printf("\n");
strcpy(ditu[a][b],diren);
strcpy(ditu[c][d],wanjia);
z = rand()%8;//z=0向左z=1向右z=2向下z=3向上 z=4子弹左 z=5子弹右 z=6子弹上 z=7子弹下
if(z==0){//向左
strcpy(ditu[a][b-1],diren);
strcpy(ditu[a][b],"0");
b = b-1;
if(b-1<0){
b = b+1;
strcpy(ditu[a][b],diren);
continue;
}
}
if(z==1){//向右
strcpy(ditu[a][b+1],diren);
strcpy(ditu[a][b],"0");
b = b+1;
if(b+1>8){
b = b-1;
strcpy(ditu[a][b],diren);
continue;
}
}
if(z==2){//向下
strcpy(ditu[a+1][b],diren);
strcpy(ditu[a][b],"0");
a = a+1;
if(a+1>8){
a = a-1;
strcpy(ditu[a][b],diren);
continue;
}
}
if(z==3){//向上
strcpy(ditu[a-1][b],diren);
strcpy(ditu[a][b],"0");
a = a-1;
if(a-1<0){
a = a+1;
strcpy(ditu[a][b],diren);
continue;
}
}
if(z==4){//发射子弹 向左
if(b!=0){
for(n=0;n<b;n++){
strcpy(ditu[z][n],"0");
}
}
else{
continue;
}
}
if(z==5){//发射子弹 向右
if(b!=8){
for(n=8;n>b;n--){
strcpy(ditu[z][n],"0");
}
}
else{
continue;
}
}
if(z==6){//发射子弹 向上
if(a!=0){
for(n=0;n<z;n++){
strcpy(ditu[n][b],"0");
}
}
else{
continue;
}
}
if(z==7){//发射子弹 向下
if(a!=8){
for(n=8;n>z;n--){
strcpy(ditu[n][b],"0");
}
}
else{
continue;
}
}
printf("\n%d\n",z);
//以下是玩家的操作 ,如果没有敌军,就重复一遍srand
//wsad
scanf("%s",&put);
if(strcmp(put,"w")==0){//w向上
strcpy(ditu[a-1][b],wanjia);
strcpy(ditu[a][b],"0");
a = a-1;
if(a-1<0){
a = a+1;
strcpy(ditu[a][b],wanjia);
continue;
}
}
if(strcmp(put,"s")==0){//s向下
strcpy(ditu[a+1][b],wanjia);
strcpy(ditu[a][b],"0");
a = a+1;
if(a+1>8){
a = a-1;
strcpy(ditu[a][b],wanjia);
continue;
}
}
if(strcmp(put,"a")==0){//s向左
strcpy(ditu[a][b-1],wanjia);
strcpy(ditu[a][b],"0");
b = b-1;
if(b-1<0){
b = b+1;
strcpy(ditu[a][b],wanjia);
continue;
}
}
if(strcmp(put,"d")==0){//d向右
strcpy(ditu[a][b+1],wanjia);
strcpy(ditu[a][b],"0");
b = b+1;
if(b+1>8){
b = b-1;
strcpy(ditu[a][b],wanjia);
continue;
}
}
for(n=0;n<9;n++){
for(m=0;m<9;m++){
printf("%-4s",ditu[n][m]);
}
printf("\n");
}
printf("\n");
}while(put!="-1");
return 0;
} |
|