跳到正文

个人记录

简陋的移动程序

XSDB约 1 分钟
原文
文章信息与版本

文章信息

发布
2022年4月17日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

代码如下

C++
#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;
}
原文