我先说一下自己在写贪吃蛇程序时,用坐标确定蛇的位置时,用自己坐标时发现和自己所料想的坐标有差距,所以就查了逻辑坐标和设备坐标。自己写的做标要想和设备坐标保持一致。就必须想办法。
这里想到的办法就是将屏幕设备坐标求出来,然后按照屏幕的来定义坐标。
#include<iostream>
#include<conio.h>
#include<Windows.h>
using namespace std;
void gotoxy(int x, int y)
{
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void main()
{
gotoxy(4, 4);
int cx = GetSystemMetrics(SM_CXFULLSCREEN);
int cy = GetSystemMetrics(SM_CYFULLSCREEN);
cout << "." << endl;
cout << cx << endl;
cout << cy << endl;
}