Compare commits

..

1 Commits

Author SHA1 Message Date
JZFamily
8eb0b39ef3 point code 2018-06-17 12:13:16 +08:00
7 changed files with 90 additions and 51 deletions

Binary file not shown.

27
point.cpp Normal file
View 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
View 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
View 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);
}

10
tools.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef TOOLS_H
#define TOOLS_H
void SetWindowSize(int cols, int lines);
void SetCursorPosition(const int x, const int y);
void SetColor(int colorID);
void SetBackColor();
#endif // TOOLS_H

View File

@ -1,40 +0,0 @@
#include "ui_helper.h"
#include <Windows.h>
#include <cstdlib>
#include <cstdio>
void ClearScreen()
{
system("cls");
}
void ClearInput()
{
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
void WaitPause()
{
system("pause");
}
void title(const std::string& xtitle)
{
ClearScreen();
printf("==============================\n");
printf("%s\n", xtitle.c_str());
printf("==============================\n");
}
int GetChoice(int max_id)
{
int x;
while (scanf("%d", &x) != 1 || x<1 || x>max_id)
{
printf("输入有误. 应为在1~%d范围内的数字. 请重试.\n", max_id);
ClearInput();
}
ClearInput();
return x;
}

View File

@ -1,11 +0,0 @@
#pragma once
#include <string>
void ClearScreen();
void ClearInput();
void WaitPause();
void title(const std::string& xtitle);
int GetChoice(int max_id);