我先說一下自己在寫貪喫蛇程序時,用座標確定蛇的位置時,用自己座標時發現和自己所料想的座標有差距,所以就查了邏輯座標和設備座標。自己寫的做標要想和設備座標保持一致。就必須想辦法。
這裏想到的辦法就是將屏幕設備座標求出來,然後按照屏幕的來定義座標。
#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;
}