利用a、s、w、d來控制移動(dòng) 按下空格會(huì)發(fā)射子彈 最簡(jiǎn)單的語法用心編寫也會(huì)有好的程序
#include<stdio.h>#include<conio.h>#include<stdlib.h>void PRint(int a[][33]){system("cls");//清屏int i,j;for(i=0;i<13;i++){for(j=0;j<33;j++){if(a[i][j]==0)printf(" ");if(a[i][j]==1)printf("*");if(a[i][j]==2)printf("|");//這個(gè)是子彈}printf("/n");}}void main(){int scr[13][33]={0};int position_x,position_y;int bullet_x,bullet_y;position_x=5;position_y=15;scr[position_x][position_y]=1;print(scr);char input;while(1){ if(kbhit()) { switch(getch()) { case'a': scr[position_x][position_y]=0; position_y--; scr[position_x][position_y]=1; print(scr); break;//向左移動(dòng) case'd': scr[position_x][position_y]=0; position_y++; scr[position_x][position_y]=1; print(scr); break;//向右移動(dòng) case'w': scr[position_x][position_y]=0; position_x--; scr[position_x][position_y]=1; print(scr); break;//向上移動(dòng) case's': scr[position_x][position_y]=0; position_x++; scr[position_x][position_y]=1; print(scr); break;//向下移動(dòng)case' ':bullet_x=position_x-1;bullet_y=position_y;scr[bullet_x][bullet_y]=2;print(scr);break;//按空格發(fā)射子彈 } } if(bullet_x>=0)//子彈的運(yùn)動(dòng) { scr[bullet_x][bullet_y]=0; bullet_x--; scr[bullet_x][bullet_y]=2; print(scr); }}/*while(position_x<13){scr[position_x][position_y]=0;position_x++;scr[position_x][position_y]=1;print(scr);}*/}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注