简陋的移动程序

· · 个人记录

代码如下

#include <bits/stdc++.h>
#include <windows.h>
#include "conio.h"
int self_x = 0,self_y = 0;
using namespace std;
void draw(){
    system("cls");
    Sleep(10);
    int x,y;
    for(y = 0;y < self_y;y++){
        cout << endl;
    }
    for(x = 0;x < self_x;x++){
        cout << "  ";
    }
    cout << "我";
}
int main(){
    int down;
    draw();
    while(1){
        if (_kbhit()){
            down = _getch();
            if (down == 75&&self_x>0) //左 
            {
                self_x--; 
            }
            if (down == 77) //右 
            {
                self_x++;
            }
            if (down == 72&&self_y>0) //上 
            {
                self_y--;
            }
            if (down == 80) //下 
            {
                self_y++;
            }
            draw();
        }
    }
    return 0;
}