point code
This commit is contained in:
parent
65683bcf7f
commit
8eb0b39ef3
27
point.cpp
Normal file
27
point.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "point.h"
|
||||
#include "tools.h"
|
||||
#include <iostream>
|
||||
|
||||
void Point::Print()//输出方块
|
||||
{
|
||||
SetCursorPosition(x, y);
|
||||
std::cout << "■";
|
||||
}
|
||||
|
||||
void Point::PrintCircular()//输出圆形
|
||||
{
|
||||
SetCursorPosition(x, y);
|
||||
std::cout << "●";
|
||||
}
|
||||
|
||||
void Point::Clear()//清除输出
|
||||
{
|
||||
SetCursorPosition(x, y);
|
||||
std::cout << " ";
|
||||
}
|
||||
|
||||
void Point::ChangePosition(const int x, const int y)//改变坐标
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
20
point.h
Normal file
20
point.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
#ifndef POINT_H
|
||||
#define POINT_H
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point() {}
|
||||
Point(const int x, const int y) : x(x), y(y) {}
|
||||
void Print();
|
||||
void PrintCircular();
|
||||
void Clear();
|
||||
void ChangePosition(const int x, const int y);
|
||||
bool operator== (const Point& point) { return (point.x == this->x) && (point.y == this->y); }
|
||||
int GetX() { return this->x; }
|
||||
int GetY() { return this->y; }
|
||||
private:
|
||||
int x, y;
|
||||
};
|
||||
#endif // POINT_H
|
33
tools.cpp
Normal file
33
tools.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "tools.h"
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void SetWindowSize(int cols, int lines)//设置窗口大小
|
||||
{
|
||||
system("title 贪吃蛇 ");//设置窗口标题
|
||||
char cmd[30];
|
||||
sprintf(cmd, "mode con cols=%d lines=%d", cols * 2, lines);//一个■占两个字符故*2
|
||||
system(cmd);//system(mode con cols=88 lines=88)
|
||||
}
|
||||
|
||||
void SetCursorPosition(const int x, const int y)//
|
||||
{
|
||||
COORD position;
|
||||
position.X = x * 2;
|
||||
position.Y = y;
|
||||
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);
|
||||
}
|
||||
|
||||
void SetColor(int colorID)//
|
||||
{
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorID);
|
||||
}
|
||||
|
||||
void SetBackColor()//
|
||||
{
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
|
||||
FOREGROUND_BLUE |
|
||||
BACKGROUND_BLUE |
|
||||
BACKGROUND_GREEN |
|
||||
BACKGROUND_RED);
|
||||
}
|
Loading…
Reference in New Issue
Block a user