首页 > 学院 > 开发设计 > 正文

利用a、s、w、d来控制移动 按下空格会发射子弹 最简单的语法用心编写也会有好的程序

2019-11-08 02:16:04
字体:
来源:转载
供稿:网友

利用a、s、w、d来控制移动 按下空格会发射子弹 最简单的语法用心编写也会有好的程序

#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("|");//这个是子弹}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;//向左移动       case'd':       scr[position_x][position_y]=0;       position_y++;       scr[position_x][position_y]=1;       print(scr);       break;//向右移动       case'w':       scr[position_x][position_y]=0;       position_x--;       scr[position_x][position_y]=1;       print(scr);       break;//向上移动       case's':       scr[position_x][position_y]=0;       position_x++;       scr[position_x][position_y]=1;       print(scr);       break;//向下移动case' ':bullet_x=position_x-1;bullet_y=position_y;scr[bullet_x][bullet_y]=2;print(scr);break;//按空格发射子弹 }  }  if(bullet_x>=0)//子弹的运动 { 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);}*/}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表