Compare commits

..

1 Commits

Author SHA1 Message Date
b8b7b710d0 Update 2018-06-17 12:12:32 +08:00
7 changed files with 51 additions and 90 deletions

Binary file not shown.

View File

@ -1,27 +0,0 @@
#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
View File

@ -1,20 +0,0 @@
#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

View File

@ -1,33 +0,0 @@
#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
View File

@ -1,10 +0,0 @@
#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

40
ui_helper.cpp Normal file
View File

@ -0,0 +1,40 @@
#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;
}

11
ui_helper.h Normal file
View File

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