C++“阴熊”大追杀0.1.1测试版正式出台!框架已搭好,欢迎大家提出意见!
老规矩,先上代码:
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#define FOREGROUND_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
using namespace std;
short teach;
long long hp=100,xp=100,money=200;
string name;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
struct thing{
string name="";
// string out="";
};
thing your[6][10];
void b_color(short x){
switch(x){
case 0:{
SetConsoleTextAttribute(hConsole, BACKGROUND_RED);
break;
}
case 1:{
SetConsoleTextAttribute(hConsole, BACKGROUND_RED | BACKGROUND_BLUE);
break;
}
case 2:{
SetConsoleTextAttribute(hConsole, BACKGROUND_RED | BACKGROUND_GREEN);
break;
}
case 3:{
SetConsoleTextAttribute(hConsole, BACKGROUND_GREEN);
break;
}
case 4:{
SetConsoleTextAttribute(hConsole, BACKGROUND_GREEN | BACKGROUND_BLUE);
break;
}
case 5:{
SetConsoleTextAttribute(hConsole, BACKGROUND_BLUE);
break;
}
case 6:{
SetConsoleTextAttribute(hConsole, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
break;
}
}
}
void color(short x){
switch(x){
case 0:{
SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
break;
}
case 1:{
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_BLUE);
break;
}
case 2:{
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN);
break;
}
case 3:{
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN);
break;
}
case 4:{
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
}
case 5:{
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE);
break;
}
case 6:{
SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
break;
}
}
}
void print(short time,string out){
for(int i=0;i<out.size();i++){
cout<<out[i];
Sleep(time);
}
}
void print_bag();
void thing_var();
void Start(){
MessageBox(0,"欢迎来到阴熊大追杀!!!","鸡你太美",MB_OK);
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_BLUE);
print(30,"如果你看到了这行字(还是一个一个出现的),就表明你成功启动了游戏!!!");
Sleep(1000);
cout<<endl;
}
void kill(){
}
int main(){
Start();
in:
color(6);
string tmp;
// print(30,"是否开启教程?(y/n):");
// cin>>tmp;
// if(tmp=="y"){
// teach=1;
// }
// else if(tmp=="n"){
// teach=0;
// }
// else{
// color(0);
// print(30,"你咩!输错了!!!");
// goto in;
// }
color(6);
system("cls");
cout<<"请输入你的名字:";
cin>>name;
if(teach){
cout<<"如果你第一次玩这个游戏。。。"<<endl;
Sleep(500);
cout<<"请先根据勾股定理把exe最大化。。。"<<endl;
Sleep(500);
cout<<"啊!不是这意思,直接";
system("pause");
}
system("cls");
while(true){
color(2);
printf("-----金币:%d 经验值:%d 生命值:%d-----",money,xp,hp);
cout<<endl;
color(4);
cout<<"hi,"<<name<<".what would you want to do?"<<endl;
color(3);
cout<<"----------------------------------------"<<endl;
color(6);
cout<<"\t1-开始战斗"<<endl;
cout<<"\t2-技能与装备中心"<<endl;
cout<<"\t3-商店"<<endl;
cout<<"\t4-战宠和同伴"<<endl;
cout<<"\t5-创建自定义技能(暂未开放)"<<endl;
cout<<"\t6-小镇"<<endl;
cout<<"\t7-地图(暂未开放)"<<endl;
cout<<"\t8-存档与读档(暂未开放)"<<endl;
color(3);
cout<<"----------------------------------------";
color(6);
// if(teach!=0){
// cout<<endl<<endl<<endl<<endl;
// color(3);
// switch(teach){
// case 1:{
// cout<<teach<<"- 一切的一切皆从开始战斗开始,\n 输入1,否则结束教程。";
// break;
// }
// }
// teach++;
// color(6);
// }
cin>>tmp;
system("cls");
if(tmp=="1");
if(tmp=="2")thing_var();
if(tmp=="3");
if(tmp=="4");
if(tmp=="5"){
color(1);
print(30,"暂未开放");
color(6);
Sleep(1000);
}
if(tmp=="6");
if(tmp=="7"){
color(1);
print(30,"暂未开放");
color(6);
Sleep(1000);
}
if(tmp=="8"){
color(1);
print(30,"暂未开放");
color(6);
Sleep(1000);
}
system("cls");
}
}
void print_bag(){
out:
system("cls");
print(50,"你的物品:");
for(int i=1;i<=4;i++){
for(int j=1;j<=9;j++){
if(your[i][j].name=="")your[i][j].name="空空如也";
cout<<setw(10)<<your[i][j].name<<" ";
}
cout<<endl<<endl;
}
cout<<"战斗时主物品栏:"<<endl<<endl;
for(int j=1;j<=9;j++){
if(your[5][j].name=="")your[5][j].name="空空如也";
cout<<setw(10)<<your[5][j].name<<" ";
}
cout<<endl<<endl;
print(30,"输入坐标交换物品(输入1 5 5 1将会把第一排第五个与第五排第一个交换,输入0 0 0 0退出,x坐标<=9、y坐标<=5):");
short x1,y1,x2,y2;
thing t;
cin>>x1>>y1>>x2>>y2;
if(!min(x1,min(y1,min(x2,y2)))||x1>9||x2>9||y1>5||y2>5)return;
t=your[x1][y1];
your[x1][y1]=your[x2][y2];
your[x2][y2]=t;
goto out;
}
void thing_var(){
system("cls");
string var;
cout<<"\t1-你的物品"<<endl;
cout<<"\t2-退出"<<endl;
cin>>var;
if(var=="1")print_bag();
if(var=="2")return;
}
内容分析
一、当前目标
希望能做成Windows窗口程序;增加动画。
二、更新状态
目前仅可以显示主页和物品栏,大家都试一下。
另:内容有很多技巧(有打字输出;循环算法;改变颜色)以后 专门找一个系列搞一下
本期内容到此结束,让我们期待下次0.1.1版本吧!
标签:case,FOREGROUND,0.1,C++,break,hConsole,阴熊,SetConsoleTextAttribute,tmp From: https://blog.csdn.net/Eason_MC_/article/details/144198529