怎么用C++控制一个移动字符的方向?
求解,求代码!
#include <windows.h> #include <conio.h> #include <iostream> using namespace std; #define UP 'w' #define RIGHT 'a' #define LEFT 'd' #define DOWN 's' class Point { public: Point(COORD coord, char Char):ShowChar(Char) { Pos = coord; Move(); } Point(char Char, SHORT x = 0, SHORT y = 0):ShowChar(Char) { Pos.X = x; Pos.Y = y; Move(); } void Up(){Pos.Y = (25+Pos.Y-1)%25;} void Down(){Pos.Y = (Pos.Y+1)%25;} void Left(){Pos.X = (80+Pos.X-1)%80;} void Right(){Pos.X = (Pos.X+1)%80;} void Move(); void Clear() { SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos); cout << ' '; } void Print() { SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos); cout << ShowChar; } private: COORD Pos;//当前字符显示的位置 const char ShowChar;//显示的字符 }; void Point::Move() { char get = 0; Print(); while (1) { get = getch(); switch (get) { case UP: Clear(); Up(); Print(); break; case DOWN: Clear(); Down(); Print(); break; case RIGHT: Clear(); Left(); Print(); break; case LEFT: Clear(); Right(); Print(); break; default:break; } get = 0; } } Point p_('Y'); int main(void) { return 0; }