7

· · 个人记录

#include<bits/stdc++.h>
#include<windows.h> 
#include<conio.h>
using namespace std;
HWND hWnd=GetConsoleWindow();
HDC hdc=GetDC(hWnd);
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
HPEN white=CreatePen(PS_SOLID,1,RGB(255,255,255));
HBRUSH brushred=CreateSolidBrush(RGB(255,0,0)),brushblue=CreateSolidBrush(RGB(0,0,255));
int Cx,Cy;
struct land
{
    int type,cnt=0,team;
};
land Map[30][30];
void Cursor()
{
    while(1){
        POINT p;
        GetCursorPos(&p);
        ScreenToClient(hWnd,&p);
        Cx=p.x/20,Cy=p.y/20;
    }
}
void drawmap(){
    while(1){
    for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
            if(Map[i][j].type==1){
                if(Map[i][j].team==1)
                SelectObject(hdc,brushred);
                else 
                SelectObject(hdc,brushblue);
                SelectObject(hdc,white);
                Rectangle(hdc,j*20,i*20,(j+1)*20,(i+1)*20);
            }
        }
    }
    }
}
int random(int x)
{
    return rand()*rand()%x;
}
int main()
{
    srand(time(NULL));
    thread t1(Cursor);
    thread t2(drawmap);
    t1.detach();
    t2.detach();
    for(int i=0;i<=19;i++){
        for(int j=0;j<=19;j++)
        Map[i][j].type=1,Map[i][j].team=1;
    }
    while(1)
    {
        char s;
        s=getch();
        if(s=='o')
        Map[Cy][Cx].team=2;
    }
    return 0;
}