#include <bits/stdc++.h> using namespace std; int col=4,box1=2; int row=6,box2=3; char ct; int mcol=8; int mrow=8; void box_p(char fx){ if(fx=='w'&& box2==row){ if(box1==col){ box2--; } }else if(fx=='s'&& box2==row){ if(col==box1){ box2++; } }else if(fx=='a' && box1==col){ if(row==box2){ box1--; } }else if(fx=='d'&& box1==col){ if(row==box2){ box1++; } } } int main(int argc, char** argv) { // cin>>col>>row; // cin>>box1>>box2; while(1){ for(int i=0;i<mcol;i++){ for(int j=0;j<mrow;j++){ if(i==col&&j==row){ cout<<setw(3)<<'A'; }else if(i==box1&&j==box2){ cout<<setw(3)<<"[]"; }else{ cout<<setw(3)<<'.'; } } cout<<endl; } cout<<"请输入:wasd"<<endl; cin>>ct; if(ct=='w'||ct=='W'){ col--; if(col<0){ col=0; } box_p('w'); }else if(ct=='d'||ct=='D'){ col++; if(col>=mcol){ col=mcol-1; } box_p('d'); }else if(ct=='a'||ct=='A'){ row--; if(row<0){ row=0; } box_p('a'); }else if(ct=='s'||ct=='S'){ row++; if(row>=mrow){ row=mrow-1; } box_p('s'); } system("cls"); } return 0; }
标签:箱子,int,ct,row,box1,col,box2 From: https://www.cnblogs.com/fushuxuan/p/17615321.html