5款最好用的免费3D建模软件(附下载链接)
acan___: #pragma once #include #include//定义控制台应用程序的入口点 using namespace std; //界面颜色 void setcolor(char str[]) { if(str=="lightblue") SetConsoleTextAttribute(
acan___:
#pragma once
#include
#include
using namespace std;
//界面颜色
void setcolor(char str[])
{
if(str=="lightblue")
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|1);
if(str=="lightred")
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
if(str=="lightyellow")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
if(str=="lightpink" )
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
if(str=="blue")
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
if(str=="red")
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
if(str=="yellow")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE);
if(str=="pink")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE);
if(str=="lightgray")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN |8);
if(str=="gray")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
else return;
}
//定义敌人结构 其中最后面Frame代表结构体类型 若不加typedef代表定义的结构体变量
typedef struct Frame
{
COORD position[2];
// COORD 是Windows API中定义的一种结构,表示一个字符在控制台屏幕上的坐标。
// 其定义为:
// typedef struct _COORD {
// SHORT X;
// SHORT Y;
// } COORD;
int flag;
}Frame;
class Game
{
public:
COORD position[10];
COORD bullet[10];//子弹坐标
Frame enemy[8];//敌人数量
int score;
int rank;//级别,难度
int rankf;//等级标志
string title;
int flag_rank;//等级标志
//构造函数
Game();
//初始化所有 //设定位置
void initPlane();
void initBullet();
void initEnemy();
//填充所有 --画出形状和消失的形状
void drawPlane();
void drawPlaneToNull();
void drawBullet();
void drawBulletToNull();
void drawEnemy();
void drawEnemyToNull();
//执行某一个操作
void Playing();//游戏主循环
void planeMove(char x);//飞机移动
void judgePlane();//判断飞机是否与障碍物重叠
void GameOver();//游戏失败
void Pause();// 该成员函数用来使得游戏暂停
void Shoot();//发射子弹
void bulletMove();//子弹移动
void drawThisBulletToNull(COORD c);//画出失效子弹
void judgeEnemy();//判断子弹是否击中障碍物
void drawThisEnemyToNull(Frame f); //击败的障碍物清空
void enemyMove();//障碍物移动
void printScore();//输出分数
};
//主菜单
int drawMenu();
//隐藏光标
void HideCursor();
void SetPos(int i, int j);//设置光标
COORD random(COORD a, COORD b);//产生随机障碍物位置
void drawFrame(COORD a, COORD b, char row, char col);//画出障碍物
//把第y行,[x1, x2) 之间的坐标填充为 ch
void drawRow(int y, int x1, int x2, char ch);
//把第x列,[y1, y2] 之间的坐标填充为 ch
void drawCol(int x, int y1, int y2, char ch);
// 绘制游戏界面
void drawPlaying();
void drawFrame(Frame frame, char row, char col);//画坠毁后的战机
// 该函数用来判断战机的某一部分是否与障碍物有接触
bool judgeCoordInFrame(Frame frame, COORD spot);
void drawRow(COORD a, COORD b, char ch);
#include
#include
#include
#include
#include
using namespace std;
Game::Game()
{
// 调用类成员函数来进行初始化
initPlane();
initBullet();
initEnemy();
// 初始化四个int型数据成员,采用赋值的方式进行初始化
// string类型的数据成员title没有进行初始化,因为:
// string本身就是一个标准库类类型,它的类定义中设置了默认构造函数,
// 这些默认构造函数会将对象初始化为合理的默认状态,
// string的默认构造函数会产生空字符串,相当于"" 。
this->score = 0;
rank = 25;
rankf = 25;
flag_rank = 0;
}
void Game::initPlane()
{
COORD centren;
centren.X = 39;
centren.Y = 22;
position[0].X = position[5].X = position[7].X = position[9].X = centren.X;
position[1].X = centren.X - 2;
position[2].X = position[6].X = centren.X - 1;
position[3].X = position[8].X = centren.X + 1;
position[4].X = centren.X + 2;
for (int i = 0; i <= 4; i++)
{
position[i].Y = centren.Y;
}
for (int i = 6; i <= 8; i++)
{
position[i].Y = centren.Y + 1;
}
position[5].Y = centren.Y - 1;
position[9].Y = centren.Y - 2;
// 这个函数体类的代码其实就是为了初始化战机的十个部分的位置,战机的组成如下所示:
// | 5
// | 9
// ***** 12034
// *** 678
// 第一排5个0的坐标依次对应了position[1]position[2]position[0]position[3]position[4]
// 第二排三个0的坐标依次对应了position[6]position[7]position[8]
// 两排0上面的两|的坐标从上往下依次对应了position[5]position[9]
}
void Game::drawPlane()
{
for (int i = 0; i < 9; i++)
{
SetPos(position[i].X,position[i].Y);
if (i != 5)
{
setcolor("yellow");
cout << "*";
}
else if (i == 5)
{
setcolor("yellow");
cout << "|";
}
}
}
// 这个成员函数通过将战机的每个坐标处输出" "来代替"0"和"|",
// 来达到将战机消除的目的。
void Game::drawPlaneToNull()
{
for (int i = 0; i < 9; i++)
{
SetPos(position[i].X, position[i].Y);
cout << " ";
}
}
// 该成员函数用来初始化子弹,
// 即将每个子弹的Y坐标初始化为30(bullet[i].Y = 30)来表示子弹处于失效状态
void Game::initBullet()
{
for (int i = 0; i < 10; i++)
{
bullet[i].Y = 30;
}
}
// 该成员函数用来画出子弹
// 首先检查每颗子弹的有效性,如果子弹有效,则定位到该子弹的坐标处,输出 "^",表示该子弹,
// 如果子弹是无效的,则不绘制
void Game::drawBullet()
{
for (int i = 0; i < 10; i++)
{
if (bullet[i].Y != 30)
{
SetPos(bullet[i].X,bullet[i].Y);
setcolor("blue");
cout << "^";
}
}
}
//子弹失效
void Game::drawBulletToNull()
{
for (int i = 0; i < 10; i++)
if (bullet[i].Y != 30)
{
SetPos(bullet[i].X, bullet[i].Y + 1);
cout << " ";
}
}
// 这个函数用来初始障碍物的位置,
// 屏幕当中只能同时存在八架障碍物,
// 且每架障碍物用如下结构体Frame来表示,如下所示:
// typedef struct Frame
// {
// COORD position[2];
// int flag;
// }Frame;
COORD random(COORD a, COORD b)
{
int x = rand() % (a.X - b.X) + a.X;
int y = rand() % (a.Y - b.Y) + a.Y;
COORD c = { x,y };
return c;
}
void Game::initEnemy()
{
COORD a = { 1, 1 };
COORD b = { 45, 15 };
for (int i = 0; i < 8; i++)
{
enemy[i].position[0] = random(a, b);
// random(a, b)是调用了一个重载的函数,它表示在坐标a、b之间的矩形框
// 内随机生成一个坐标值,并将该坐标值作为障碍物的左上角的坐标。
// enemy[i].position[0]中是一个Frame结构体类型的变量,存放了障碍物i的左上角的坐标。
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
// enemy[i].position[1]也中是一个Frame结构体类型的变量,存放了障碍物i的右下角的坐标。
}
}
// 接下来要根据障碍物的左上角坐标和右下角坐标画出障碍物,
// 显然,障碍物的外形如下所示:
// --
// | |
// --
void Game::drawEnemy()
{
for (int i = 0; i < 8; i++)
{
setcolor("gray");
drawFrame(enemy[i].position[0], enemy[i].position[1], '-', '|');
}
}
// 将障碍物消除,通过输出空白的方式
void Game::drawEnemyToNull()
{
for (int i = 0; i < 8; i++)
{
drawFrame(enemy[i].position[0], enemy[i].position[1], ' ', ' ');
}
}
//隐藏光标
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = { 1,0 };//第二个值0表示隐藏光标
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void SetPos(int i, int j)//设置坐标点位(光标)
{
HANDLE hout;
COORD coord;
coord.X = i;
coord.Y = j;
hout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout, coord);
}
//左上角坐标、右下角坐标、用row填充行、用col填充列
void drawFrame(COORD a, COORD b, char row, char col)
{
drawRow(a.Y, a.X + 1, b.X - 1, row);
drawRow(b.Y, a.X + 1, b.X - 1, row);
drawCol(a.X, a.Y + 1, b.Y - 1, col);
drawCol(b.X, a.Y + 1, b.Y - 1, col);
}
//把第y行,[x1, x2) 之间的坐标填充为 ch
void drawRow(int y, int x1, int x2, char ch)
{
SetPos(x1, y);
for (int i = 0; i <= (x2 - x1); i++)
{
cout << ch;
}
}
//把第x列,[y1, y2] 之间的坐标填充为 ch
void drawCol(int x, int y1, int y2, char ch)
{
int y = y1;
while (y != y2 + 1)
{
SetPos(x, y);
cout << ch;
y++;
}
}
//主菜单绘制
int drawMenu()
{
setcolor("lightgreen");
system("Title 飞 机 大 战");
SetPos(30,1);
cout << "飞 机 大 战";
drawRow(3, 0, 79, '-');
drawRow(5, 0, 79, '-');
SetPos(28, 4);
setcolor("red");
cout << "↑和↓选择,回车确定";
int j = 11;
SetPos(12, j);
cout << ">>";
SetPos(15, 11);
cout << "1. 简单的任务";
SetPos(15, 13);
cout << "2. 困难的任务";
drawRow(20, 0, 79, '-');
SetPos(47, 11);
setcolor("yellow");
cout << "简单的任务:";
SetPos(51, 13);
cout << "简单任务的自动飞行速度较慢,任务难度较小。 ";
SetPos(30, 21);
setcolor("lightblue");
cout << "纳米核心";
setcolor("red");
drawRow(22, 0, 79, '-');
while (true)
{
if (_kbhit())
{
char x = _getch();
switch (x)
{
case 72:
{
if (j == 13)
{
SetPos(12, j);
cout << " ";
j = 11;
SetPos(12, j);
setcolor("red");
cout << ">>";
SetPos(51, 13);
cout << " ";
SetPos(47, 11);
setcolor("yellow");
cout << "简单的任务:";
SetPos(51, 13);
cout << "简单任务的自动飞行速度较慢,任务难度较小。 ";
}
break;
}
case 80:
{
if (j == 11)
{
SetPos(12, j);
cout << " ";
j = 13;
SetPos(12, j);
setcolor("red");
cout << ">>";
SetPos(51, 13);
cout << " ";
SetPos(47, 11);
setcolor("yellow");
cout << "困难的任务:";