跳到正文

个人记录

小游戏 · 4 蒟蒻的饼干放置游戏

xutongwei约 20 分钟
原文
文章信息与版本

文章信息

发布
2019年8月13日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 20 分钟

版本

  1. v1当前

排行有空,欢迎来添加哦~

附:刷排行榜 请在该文章下评论或私信本人

C++
#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<iostream>
#include<windows.h>
#include<algorithm>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
void block(int x,int y){
    HANDLE   hCon;
    hCon = GetStdHandle(STD_OUTPUT_HANDLE);  
    COORD   setps;
    setps.X = x;
    setps.Y = y;
    SetConsoleCursorPosition(hCon,setps);  
}
string nicheng,ni;
int len;
struct Button{
    int x,y,color;
    const char *name;
    int len;
};
void hide(){
	CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
  	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void GetPos(POINT &pt){
    HWND hwnd=GetForegroundWindow();
    GetCursorPos(&pt);
    ScreenToClient(hwnd,&pt);
    pt.y=pt.y/16,pt.x=pt.x/16;
}
void color(int a){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void gto(int x,int y){
    COORD pos;pos.X=y*2;pos.Y=x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
Button NewButton(int x,int y,int color,const char *name){
    Button t;
    t.x=x,t.y=y,t.name=name;
    t.color=color;
    t.len=strlen(name);
    return t;
}
bool Preserve(Button A){
    gto(A.x,A.y),color(A.color),printf("%s",A.name);
    POINT pt;
    GetPos(pt);
    if(pt.y==A.x&&(pt.x>=A.y&&pt.x<=A.y+A.len/2)){
        gto(A.x,A.y),printf("%s",A.name);
        if(KEY_DOWN(MOUSE_MOVED)) return 1;
    }
    return 0;
}
double money = 0;
double money2 = 0;
int youbiao = 0;
int ren = 0; 
int gongchang = 0;
int shangdian = 0;
int chaoshi = 0;
int m2 = 10;
int m3 = 1;
int m4 = 50;
int m5 = 2000;
int m6 = 2; 
int m7 = 1;
int m8 = 100;
int m9 = 2500;
int a[10] = {0, 0, 20, 200, 10000, 1000000, 0, 0, 0, 0};
int b[10] = {0, 50, 10000, 3000, 200000, 0, 0, 0, 0, 0};
bool h[10];
bool h2[10];
Button z[10];
Button q[10];

void maiyou(){
	if(money >= m2) {
		cout << "*";
	}
	z[2] = NewButton(2, 1, 7, "游标(饼干+1):"); 
	cout << "                  " << youbiao << "  当前价格:" << m2 << endl; 
}

void mairen(){
	if(money2 >= m4) {
		cout << "*";
	}
	z[3] = NewButton(3, 1, 7, "人(饼干+20):"); 
	cout << "                  " << ren << "  当前价格(钱):" << m4 << endl; 
}

void maigong(){
	if(money2 >= m5) {
		cout << "*";
	}
	z[4] = NewButton(4, 1, 7, "工厂(饼干+500):"); 
	cout << "                    " << gongchang << "  当前价格(钱):" << m5 << endl; 
}

void maishang(){
	if(money >= m8) {
		cout << "*                         " << shangdian << "  当前价格:" << m8 << endl;
	}else{
		cout << "                          " << shangdian << "  当前价格:" << m8 << endl; 
	}
	q[1] = NewButton(5, 1, 7, "商店(饼干-10 钱+3):"); 
}

void maichao(){
	if(money2 >= m9) {
		cout << "*                           " << chaoshi << "  当前价格(钱):" << m9 << endl;
	}else{
		cout << "                            " << chaoshi << "  当前价格(钱):" << m9 << endl; 
	}
	q[2] = NewButton(6, 1, 7, "超市(饼干-2000 钱+700):"); 
}

void buyyou(){
	if(money >= m2){
		youbiao += 1;
		money -= m2;
		m2 += youbiao * 2;
	}
}

void buyren(){
	if(money2 >= m4){
		ren += 1;
		money2 -= m4;
		m4 += ren * 5;
	}
}

void buygong(){
	if(money2 >= m5){
		gongchang += 1;
		money2 -= m5;
		m5 += gongchang * 100;
	}
}

void buyshang(){
	if(money >= m8){
		shangdian += 1;
		money -= m8;
		m8 += shangdian * 10;
	}
}

void buychao(){
	if(money2 >= m9){
		chaoshi += 1;
		money2 -= m9;
		m9 += chaoshi * 200;
	}
}

void jieyou(){
	if(money >= a[2] && m6 >= 2){
		h[2] = true;
		money -= a[2];
		m6++;
	}
}

void jieren(){
	if(money >= a[3] && m6 >= 3){
		h[3] = true;
		money -= a[3];
		m6++;
	}
}

void jiegong(){
	if(money >= a[4] && m6 >= 4){
		h[4] = true;
		money -= a[4];
		m6++;
	}
}

void jieshang(){
	if(money >= b[1] && m6 >= 3){
		h2[1] = true;
		money -= b[1];
		m7++;
	}
}

void jiechao(){
	if(money >= b[2] && money2 >= b[3] && m7 >= 2){
		h2[2] = true;
		money -= b[2];
		money2 -= b[3];
		m7++;
	}
}

int main( ){
	cout << "您想把本次游戏的初始资金设为所少?" << endl;
	int m1;
	p1:cout << "饼干(0~200)";
	cin >> m1;
	if(m1 < 0 || m1 > 200){
		cout << "您的设置超出了我们的设定范围" << endl;
		goto p1; 
	}
	money = m1;
	p2:cout << "钱(0~40)";
	cin >> m1;
	if(m1 < 0 || m1 > 40){
		cout << "您的设置超出了我们的设定范围" << endl;
		goto p2; 
	}
	money2 = m1;
	while(true){
		cout << "饼干:" << money << "     钱:" << money2 << endl;
		z[1] = NewButton(1, 1, 7, "点击");
		cout << endl;
		if(m6 >= 2){
			if(!h[2]){
				if(money >= a[2]){
					cout << "*"; 
				}
				z[2] = NewButton(2, 1, 7, "游标(饼干+1)解锁:"); 
				cout << "                        " << a[2] << endl;
			}else{
				maiyou();
			}
		}else{
			z[2] = NewButton(2, 1, 7, "??(??)解锁:"); 
		}
		if(m6 >= 3){
			if(!h[3]){
				if(money >= a[3]){
					cout << "*"; 
				}
				z[3] = NewButton(3, 1, 7, "人(饼干+20)解锁:"); 
				cout << "                     " << a[3] << endl;
			}else{
				mairen();
			}
		}else{
			z[3] = NewButton(3, 1, 7, "?(??)解锁:"); 
			cout << endl;
		}
		
		if(m6 >= 4){
			if(!h[4]){
				if(money >= a[4]){
					cout << "*"; 
				}
				z[4] = NewButton(4, 1, 7, "工厂(饼干+500)解锁:"); 
				cout << "                        " << a[4] << endl;
			}else{
				maigong();
			}
		}else{
			z[4] = NewButton(4, 1, 7, "??(??)解锁:"); 
			cout << endl;
		}
		if(m6 >= 3){
			if(!h2[1]){
				if(money >= b[1]){
					cout << "*                             " << b[1] << endl;
				}else{
					cout << "                              " << b[1] << endl;
				}
				q[1] = NewButton(5, 1, 7, "商店(饼干-10 钱+3)解锁:");
			}else{
				maishang();
			}
		}else{
			q[1] = NewButton(5, 1, 7, "??(??)解锁:"); 
			cout << endl;
		}
		if(m7 >= 2){
			if(!h2[2]){
				if(money >= b[2] && money2 >= b[3]){
					cout << "*                               " << b[2] << "  钱:" << b[3] << endl;
				}else{
					cout << "                                " << b[2] << "  钱:" << b[3] << endl;
				}
				q[2] = NewButton(6, 1, 7, "超市(饼干-2000 钱+700)解锁:");
			}else{
				maichao();
			}
		}else{
			q[2] = NewButton(6, 1, 7, "??(??)解锁:"); 
			cout << endl;
		}
		if(m6 >= 5 && m7 >= 3) {
			if(money >= a[5] && money2 >= b[4]){
				cout << "*";
			}
			z[5] = NewButton(7, 1, 7, "选择梦想职业!"); 
			cout << "                 饼干:" << a[5] << "   钱:" << b[4] << endl;
		}else{
			z[5] = NewButton(7, 1, 7, "??(??)解锁:"); 
		}
		if(Preserve(z[1])){
			money += m3;
		}else if(Preserve(z[2])){
			if(!h[2]){
				jieyou();
			}else{
				buyyou();
			}
		}else if(Preserve(z[3])){
			if(!h[3]){
				jieren();
			}else{
				buyren();
			}
		}else if(Preserve(z[4])){
			if(!h[4]){
				jiegong();
			}else{
				buygong();
			}
		}else if(Preserve(q[1])){
			if(!h2[1]){
				jieshang();
			}else{
				buyshang();
			}
		}else if(Preserve(q[2])){
			if(!h2[2]){
				jiechao();
			}else{
				buychao();
			}
		}else if(Preserve(z[5])){
			if(money >= a[5] && money2 >= b[4]){
				Sleep(1000);
				break;
			}
		}
		money += (double)youbiao / 10.0;
		money += ren * 2;
		money += gongchang * 50;
		if(money >= shangdian * 10){
			money -= shangdian;
			money2 += (double)shangdian * 3 / 10;
		}
		if(money >= chaoshi * 2000){
			money -= chaoshi * 200;
			money2 += chaoshi * 70;
		}
		Sleep(100);
		system("cls");
	}
	Sleep(3000);
	system("cls");
	cout << "游戏挑战成功!";
	Sleep(1000);
	block(4, 3);
	cout << "本次游戏记录:";
	block(8, 4);
	cout << "饼干:" << money;
	block(8, 5);
	cout << "游标:" << youbiao;
	block(8, 6);
	cout << "商店:" << shangdian;
	block(8, 7);
	cout << "钱:" << money2;
	block(8, 8);
	cout << "人:" << ren;
	block(8, 9);
	cout << "超市:" << chaoshi;
	block(8, 10);
	cout << "工厂:" << gongchang;
	block(8, 11);
	cout <<"总得分:" << (long long)(money + money * 2 + youbiao * 10 + ren * 400 + gongchang * 14000 + shangdian * 150 + chaoshi * 20000);
	block(4, 13);
	cout << "排行榜:";
	block(8, 14);
	cout << "排行有空,欢迎来添加!"; 
	Sleep(10000);
	return 0;
}
/*
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1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