Compare commits
1 Commits
jkCashWorl
...
master
Author | SHA1 | Date | |
---|---|---|---|
b8b7b710d0 |
BIN
CashWorld.cpp
BIN
CashWorld.cpp
Binary file not shown.
27
point.cpp
27
point.cpp
|
@ -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
20
point.h
|
@ -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
|
33
tools.cpp
33
tools.cpp
|
@ -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
10
tools.h
|
@ -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
40
ui_helper.cpp
Normal 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
11
ui_helper.h
Normal 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);
|
Loading…
Reference in New Issue
Block a user