heads头文件:
#pragma once
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
using namespace std;
io头文件:
#include "heads.h"
int toint(char ch)
{
if(ch>='0'&&ch<='9')
return ch-'0';
return ch-'A'+10;
}
int stoint(string str)
{
int ans=0;
for(int i=0;i<str.size();i++)
ans=ans*16+toint(str[i]);
return ans;
}
void print(string a,WORD color,int x,int y,int wait)
{
WORD colorOld;
HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(handle, &csbi);
colorOld = csbi.wAttributes;
if(x>=0&&y>=0)
{
COORD pos={x,y};
SetConsoleCursorPosition(handle,pos);
}
SetConsoleTextAttribute(handle, color);
for(int i=0;i<a.size();i++)
{
if(a[i]=='<')
{
i++;
char model=a[i];
i++;
if(model=='T')
{
char ch1=a[i];
i++;
char ch2=a[i];
string b="";
int c=1;
do{
i++;
if(a[i]=='<')
c++;
if(a[i]=='>')
c--;
if(a[i]=='&')
{
b+=a[i];
i++;
}
b+=a[i];
}while(c!=0);
b.erase(b.size()-1,1);
WORD adder;
adder=toint(ch1)*16+toint(ch2);
print(b,adder,-1,-1,wait);
continue;
}
}
else
{
if(a[i]=='&')
i++;
printf("%c",a[i]);
}
Sleep(wait);
}
SetConsoleTextAttribute(handle, colorOld);
}
string getstr(int lenth)
{
char ch;
string input="";
while(ch=getchar(),ch!='\n'&&input.size()<lenth)
input+=ch;
return input;
}
注意这两个头文件的类型是heads.h和io.h不是.cpp
源代码:
#include "heads.h"
#include "io.h"
typedef long long ll;
string weapon[5] = {"木剑" , "石剑" , "铁剑" , "钻石剑" , "下界合金剑"};
void fightmainban () {
puts ("------------------------------");
puts (" 请问你要干什么? ");
puts (" 1、攻击 2、回血 3、逃跑 ");
puts ("------------------------------");
}
void mianban () {
print("<TCF >",0xF8,0,0,0);
print("<TCF > <TCF >",0xF8,0,1,0);
print("<TCF ><TF8 请问你要干什么? ><TCF >",0xF8,0,2,0);
print("<TCF ><TF81、打架 2、去商店 3、赚金币 4、打boss 5、指令 6、住旅馆><TCF >",0xF8,0,3,0);
print("<TCF > <TCF >",0xF8,0,4,0);
print("<TCF ><TF8 选择: ><TCF >",0xF8,0,4,0);
print("<TCF > <TCF >",0xF8,0,5,0);
print("<TCF >",0xF8,0,6,0);
print("",0xF8,28,4,0);
}
COORD gets_font_size()
{
COORD font_size;
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
/* 字体信息 */
struct CONSOLE_FONT
{
DWORD index;
COORD dim;
} cfi;
typedef COORD (WINAPI *PROCGETCONSOLEFONTSIZE)(HANDLE, DWORD);
typedef BOOL (WINAPI *PROCGETCURRENTCONSOLEFONT)(HANDLE, BOOL, struct CONSOLE_FONT*);
HMODULE hKernel32 = GetModuleHandle("kernel32");
PROCGETCONSOLEFONTSIZE GetConsoleFontSize = (PROCGETCONSOLEFONTSIZE)GetProcAddress(hKernel32,"GetConsoleFontSize");
PROCGETCURRENTCONSOLEFONT GetCurrentConsoleFont = (PROCGETCURRENTCONSOLEFONT)GetProcAddress(hKernel32,"GetCurrentConsoleFont");
GetCurrentConsoleFont(handle, FALSE, &cfi); /* 获取当前字体索引信息 */
font_size = GetConsoleFontSize(handle, cfi.index); /* 获取当前字体宽高信息[字符宽度及高度所占像素数] */
return font_size;
}
/*******************************************************************************
* 最大化展示控制台窗口
******************************************************************************/
void full_screen()
{
HWND hwnd = GetForegroundWindow();
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); /* 标准输出缓冲区句柄 */
int cx = GetSystemMetrics(SM_CXSCREEN); /* 屏幕宽度 */
int cy = GetSystemMetrics(SM_CYSCREEN); /* 屏幕高度 */
COORD size = gets_font_size();
char cmd[32] = { 0 };
sprintf(cmd, "MODE CON: COLS=%d LINES=%d", cx / size.X, cy / size.Y);
system(cmd);
SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}
int main () {
system("color f0");
full_screen();
SetConsoleTitle("ZCK\'s Game");
srand ((unsigned)time (NULL));
int chance = 2 , bloodchance = 2 , pricechange = 2 , hotal = 500 , tmpblood;
string s;
ll blood1 = 300000 , atk1 = 300000 , wep = 0;
ll atk , blood , equipment , money = 0;
print("<TFC----------小游戏 <TF5zck>出品---------->",0xF8,0,0,10);
print("<TFC请输入您的名字:>",0xF8,0,1,10);
print("<TFC----------------------------------->",0xF8,0,2,10);
print("",0xF8,15,1,0);
HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(handle, &csbi);
SetConsoleTextAttribute(handle, 0xF9);
WORD colorOld = csbi.wAttributes;
s=getstr(16);
SetConsoleTextAttribute(handle, colorOld);
if (s == "zck" || s == "朱宸可") {
atk = 99999999;
blood = 99999999;
equipment = 99999999;
money = 999999999999;
}
else if (s == "xhc" || s == "谢昊宸") {
atk = 1;
blood = 2;
equipment = 1;
money = -100000000;
}
else {
atk = rand () % 10 + 99902;
blood = rand () % 9 + 2000;
equipment = rand ();
tmpblood = blood;
}
int bl = 2;
bool killed = false;
blood += equipment;
char buff[150];
sprintf(buff,"<TF9%s> <TFCatk:>%lld <TFCblood:>%lld <TFCequipment:>%d \n",s.c_str(),atk,blood,equipment);
print(buff,0xF8,0,3,10);
char opt;
while (1) {
i: Sleep(2000);
system("cls");
if (killed) blood = tmpblood;
int i = 1;
mianban ();
HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(handle, &csbi);
SetConsoleTextAttribute(handle, 0xF9);
WORD colorOld = csbi.wAttributes;
opt=getch();
putch(opt);
SetConsoleTextAttribute(handle, colorOld);
print("",0xF8,0,7,0);
if (opt == '1') {
while (1) {
int blood1 = rand () % 10 + 99900;
int atk1 = rand () % 9 + 2000;
cout << "NPC血量=" << blood1 << ". 攻击力=" << atk1 << endl;
cout << "第" << i << "回合" << endl;
cout << "请问" << s << "要干什么?" << endl;
fightmainban ();
int k;
cin >> k;
if (k == 1) {
int tmp = rand () % 10;
if (tmp < 4) {
blood1 -= (atk * 2);
cout << s << "使用附魔钻石剑攻击" << endl;
cout << "NPC" << "还剩" << blood1 << "血" << endl;
}
else {
blood1 -= atk;
cout << s << "使用" << weapon[wep] << "攻击" << "NPC" << endl;
cout << "NPC" << "还剩" << blood1 << "血" << endl;
}
}
if (k == 2 && bl <= 0) puts ("泥煤吃的了......");
if (k == 2 && bl > 0) {
blood += 10;
bl -- ;
cout << s << "加10滴血" << endl;
}
if (k == 3) {
int tmp = rand () % 10;
if (tmp <= 4) {
cout << s << "逃跑了" << endl;
cout << "NPC" << "胜利" << endl;
money -= 10;
break;
}
}
if (blood1 <= 0) {
cout << s << "干掉了" << "NPC" << endl;
cout << s << "胜利" << endl;
money += rand () % 10;
break;
}
int tmp2 = rand () % 10;
if (tmp2 <= 4) {
blood -= (atk1 * 2);
cout << "NPC" << "使用篮球攻击" << s << endl;
cout << s << "还剩" << blood << "血" << endl;
}
else {
blood -= atk1;
cout << "NPC使用屁股攻击" << s << endl;
cout << s << "还剩" << blood << "血" << endl;
}
if (blood <= 0) {
cout << "NPC" << "干掉了" << s << endl;
cout << "NPC" << "胜利" << endl;
money -= 10;
killed = true;
break;
}
i ++ ;
}
}
if (opt == '2') {
puts ("欢迎来到黑心商店~~~~");
puts ("攻击武器 : 1、石剑:100元 2、铁剑:500元 3、钻石剑:2000元 4、下界合金剑:50000元");
puts ("防御装备 : 5、皮革装:300元 6、铁套:20000元 7、钻石套:50000元 8、下界合金套:100000元");
puts ("输入0,离开商店");
int op;
cin >> op;
if (op == 0) goto i;
if (op == 1 && money >= 10) atk += 30 , money -= 10 , wep = 1;
else if (money < 10) {
puts ("没钱!!!");
goto i;
}
if (op == 2 && money >= 50) atk += 500 , money -= 50 , wep = 2;
else if (money < 50) {
puts ("没钱!!!");
goto i;
}
if (op == 3 && money >= 200) atk += 1000 , money -= 200 , wep = 3;
else if (money < 200) {
puts ("没钱!!!");
goto i;
}
if (op == 4 && money >= 500) atk += 2000 , money -= 500 , wep = 4;
else if (money < 500) {
puts ("没钱!!!");
goto i;
}
if (op == 5 && money >= 30) blood += 200 , money -= 30;
else if (money < 30) {
puts ("没钱!!!");
goto i;
}
if (op == 6 && money >= 100) blood += 7000 , money -= 100;
else if (money < 100) {
puts ("没钱!!!");
goto i;
}
if (op == 7 && money >= 500) blood += 10000 , money -= 500;
else if (money < 500) {
puts ("没钱!!!");
goto i;
}
if (op == 8 && money >= 1000) blood += 30000 , money -= 1000;
else if (money < 1000) {
puts ("没钱!!!");
goto i;
}
puts ("已穿上装备");
}
if (opt == '3') {
puts ("来打工的?");
puts ("1、擦盘子 2分钟5金币");
puts ("2、巡逻 2分钟20金币");
puts ("3、管理10个人 2分钟50金币");
puts ("4、管理公司 2分钟70金币");
int y;
cin >> y;
if (y == 1 && money >= 500) {
puts ("你想做几分钟?");
int times;
cin >> times;
cout << "打工中......" << endl;
Sleep (times * 60000);
money += (times / 2) * 20;
cout << "你现在有:" << money << "元" << endl;
goto i;
}
else if (y == 1 && money < 500) {
puts ("你没资格......");
goto i;
}
if (y == 2 && money >= 2000) {
puts ("你想做几分钟?");
int times;
cin >> times;
cout << "打工中" << endl;
Sleep (times * 60000);
money += (times / 2) * 50;
cout << "你现在有:" << money << "元" << endl;
goto i;
}
else if (y == 2 && money < 2000) {
puts ("你没资格......");
goto i;
}
if (y == 3 && money >= 5000) {
puts ("你想做几分钟?");
int times;
cin >> times;
cout << "打工中" << endl;
Sleep (times * 60000);
money += (times / 2) * 5;
cout << "你现在有:" << money << "元" << endl;
goto i;
}
else if (y == 3 && money < 5000) {
puts ("你没资格......");
goto i;
}
if (y == 4 && money >= 10000) {
puts ("你想做几分钟?");
int times;
cin >> times;
cout << "打工中" << endl;
Sleep (times * 60000);
money += (times / 2) * 70;
cout << "你现在有:" << money << "元" << endl;
goto i;
}
else if (y == 4 && money < 10000) {
puts ("你没资格......");
goto i;
}
}
if (opt == '4') {
while (1) {
cout << "末影龙血量=" << blood1 << ". 攻击力=" << atk1 << endl;
cout << "第" << i << "回合" << endl;
cout << "请问" << s << "要干什么?" << endl;
fightmainban ();
int k;
cin >> k;
if (k == 1) {
int tmp = rand () % 10;
if (tmp < 4) {
blood1 -= (atk * 2);
cout << s << "使用附魔钻石剑攻击" << endl;
cout << "末影龙" << "还剩" << blood1 << "血" << endl;
}
else {
blood1 -= atk;
cout << s << "使用武器攻击" << "末影龙" << endl;
cout << "末影龙" << "还剩" << blood1 << "血" << endl;
}
}
if (k == 2 && bl <= 0) puts ("泥煤吃的了......");
if (k == 2 && bl > 0) {
blood += 10;
bl -- ;
cout << s << "加10滴血" << endl;
}
if (k == 3) {
int tmp = rand () % 10;
if (tmp <= 4) {
cout << s << "逃跑了" << endl;
cout << "末影龙" << "胜利" << endl;
money -= 10;
break;
}
}
if (blood1 <= 0) {
cout << s << "干掉了" << "末影龙" << endl;
cout << s << "胜利" << endl;
return 0;
}
int tmp2 = rand () % 10;
if (tmp2 <= 4) {
blood -= (atk1 * 2);
cout << "末影龙" << "使用龙息攻击" << s << endl;
cout << s << "还剩" << blood << "血" << endl;
}
else {
blood -= atk1;
cout << "末影龙使用翅膀攻击" << s << endl;
cout << s << "还剩" << blood << "血" << endl;
}
if (blood <= 0) {
cout << "末影龙" << "干掉了" << s << endl;
cout << "末影龙" << "胜利" << endl;
money -= 10;
killed = true;
break;
}
i ++ ;
}
}
if (opt == '5') {
puts ("指令:1、coi_money (看自己有多少钱)");
puts ("1(1)、coi_atk_and_blood (看末影龙血量、攻击力)");
puts ("1(2)、coi_me (看自己目前攻击力、血量)");
puts ("2、cut_blood (削弱末影龙3%血量,有20%的几率)");
puts ("3、atk++ (加强攻击力,作者专用)");
puts ("4、blood++ (加强血量)");
puts ("5、cut_price (降价旅馆钱数,两次机会,有20%几率)");
puts ("请输入指令:");
string zl;
cin >> zl;
if (zl == "coi_money") {
cout << "money:" << money << endl;
goto i;
}
if (zl == "coi_atk_and_blood") {
cout << "攻击力:" << atk1 << " 防御力:" << blood1 << endl;
goto i;
}
if (zl == "coi_me") {
cout << "攻击力:" << atk << " 防御力:" << blood << endl;
goto i;
}
if (zl == "cut_blood" && chance <= 0) {
puts ("泥煤机会了......");
goto i;
}
if (zl == "cut_blood" && chance > 0) {
int ran = rand ();
if (ran % 5 == 0) {
atk1 *= 0.97;
blood1 *= 0.97;
cout << "目前末影龙攻击力:" << atk1 << "血量:" << blood1 << endl;
chance -- ;
goto i;
}
else {
puts ("真不走运......");
goto i;
}
}
if (zl == "atk++" && s == "zck" || zl == "atk++" && s == "朱宸可") {
atk += 1000;
blood += 10000;
cout << "现在血量:" << atk << " 防御力:" << blood << endl;
goto i;
}
else if (zl == "atk++" && s != "zck" || zl == "atk++" && s != "朱宸可") {
puts ("你不是作者!!!!!!");
goto i;
}
if (zl == "blood++" && bloodchance <= 0) {
puts ("泥煤机会了......");
goto i;
}
if (zl == "blood++" && bloodchance > 0) {
blood += 900;
cout << "现在血量:" << blood;
bloodchance -- ;
goto i;
}
if (zl == "cut_price" && pricechange <= 0) {
puts ("泥煤机会了......");
goto i;
}
if (zl == "cut_price" && pricechange > 0) {
int price = rand () % 10;
if (price <= 4) {
hotal *= 0.8;
cout << "现在钱数:" << hotal << endl;
pricechange -- ;
goto i;
}
else {
puts ("真不走运......");
goto i;
}
}
}
if (opt == '6') {
puts ("欢迎来到酒店~~~~~");
puts ("住一次500元,血量+5000");
puts ("要住店吗?同意输入1");
int o;
cin >> o;
if (o == 1 && money >= 500) {
puts ("好好睡吧......");
blood += 5000;
money -= 500;
Sleep (3000);
puts ("第二天了");
goto i;
}
else if (o == 1 && money < 500) {
puts ("泥煤钱!!!");
goto i;
}
else {
puts ("下次再来!!!!");
goto i;
}
}
}
return 0;
}
玩不了