用户:
小Yiiiii查看:0 回复:3 评论:0 创建时间:2023-05-21T15:48:30
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int power(int a,double b){
double c=b;
int e=100;
for(int i=0;i<a;i++){
c*=b;
}
if(a>0)e=c*100;
return e;
}
int main() {
int g=1,xk=0,zb=100,sd=0,s,gn=5,xks=0,m,dx,k[100]={},kw,gs,x,y[100]={},j=0,d=0,zj=0,zl;
srand(clock());
while(1){
cout<<"当前等级:"<<d<<"级"<<j<<"经验"<<" 总经验:"<<zj<<"点\n";
cout<<"干什么?\n1.下矿 2.买东西 3.查看背包 4.卖东西";
zl=4;
if(d>=50){
cout<<" 5.冶炼 6.合成";
zl=6;
}
cout<<"\n";
cin>>s;
if(s>zl||s<1){
cout<<"errow!";
continue;
}else if(s==1){
if(gn<=0){
cout<<"没有镐子!";
continue;
}else{
if(g==1){
xk=1;
xks=rand()%3+1;
}else if(g==2){
xk=rand()%2+1;
if(xk==1){
xks=rand()%5+1;
}else{
xks=rand()%2+1;
}
}else if(g==3){
xk=rand()%4+1;
if(xk==1){
xks=rand()%15+1;
}else if(xk==2){
xks=rand()%5+1;
}else if(xk==3){
xks=rand()%3+1;
}else if(xk==4){
if(rand()%2==1){
xks=1;
}else{
xks=0;
}
}
}else if(g==4){
xk=rand()%5+1;
if(xk==1){
xks=rand()%25+1;
}else if(xk==2){
xks=rand()%12+1;
}else if(xk==3){
xks=rand()%6+1;
}else if(xk==4){
xks=rand()%2+1;
}else if(xk==5){
if(rand()%4==1){
xks=1;
}else{
xks=0;
}
}
}else if(g==5){
xk=rand()%5+1;
if(xk==1){
xks=rand()%12+1;
}else if(xk==2){
xks=rand()%6+1;
}else if(xk==3){
xks=rand()%3+1;
}else if(xk==4){
if(rand()%2==1){
xks=1;
}else{
xks=0;
}
}else if(xk==5){
if(rand()%16==1){
xks=1;
}else{
xks=0;
}
}
}else if(g==6){
xk=rand()%5+1;
if(xk==1){
xks=rand()%20+1;
}else if(xk==2){
xks=rand()%10+1;
}else if(xk==3){
xks=rand()%5+1;
}else if(xk==4){
xks=rand()%2+1;
}else if(xk==5){
if(rand()%5==1){
xks=1;
}else{
xks=0;
}
}
}else if(g==7){
xk=rand()%6+1;
if(xk==1){
xks=rand()%40+1;
}else if(xk==2){
xks=rand()%20+1;
}else if(xk==3){
xks=rand()%10+1;
}else if(xk==4){
xks=rand()%5+1;
}else if(xk==5){
xks=1;
}else if(xk==6){
xks=rand()%6+1;
}
}else if(g==8){
xk=rand()%6+1;
if(xk==1){
xks=rand()%80+1;
}else if(xk==2){
xks=rand()%50+1;
}else if(xk==3){
xks=rand()%20+1;
}else if(xk==4){
xks=rand()%12+1;
}else if(xk==5){
xks=rand()%3+1;
}else if(xk==6){
xks=rand()%10+1;
}
}
if(xks>0){
cout<<"恭喜得到"<<xks<<"个";
if(xk==1){
cout<<"煤炭";
k[0]+=xks;
j+=xks*3;
zj+=xks*3;
}else if(xk==2){
cout<<"铁";
k[1]+=xks;
j+=xks*10;
zj+=xks*10;
}else if(xk==3){
cout<<"黄铜";
k[2]+=xks;
j+=xks*25;
zj+=xks*25;
}else if(xk==4){
cout<<"黄金";
k[3]+=xks;
j+=xks*80;
zj+=xks*80;
}else if(xk==5){
cout<<"钻石";
k[4]+=xks;
j+=xks*200;
zj+=xks*200;
}else if(xk==6){
cout<<"钛";
k[5]+=xks;
j+=xks*75;
zj+=xks*75;
}
}else{
cout<<"很遗憾,什么也没有\n";
}
gn--;
cout<<"\n";
cout<<"镐子耐久:"<<gn<<"\n";
}
}else if(s==2){
cout<<"买什么?\n1.镐子 2.采矿机\n";
cin>>m;
if(m==1){
cout<<"当前资产:"<<zb<<"元\n";
cout<<"1.木镐 耐久:5 可采集:煤炭 价格:40元\n";
cout<<"2.石镐 耐久:10 可采集:铁 价格:100元\n";
cout<<"3.铁镐 耐久:20 可采集:黄金 价格:500元\n";
cout<<"4.金镐 耐久:40 可采集:钻石 价格:2500元\n";
cin>>dx;
if(dx==1){
if(zb<40){
cout<<"金币不够!\n";
continue;
}
if(gn<5){
zb-=40;
gn=5;
g=1;
j+=5;
zj+=5;
}
}else if(dx==2){
if(zb<100){
cout<<"金币不够!\n";
continue;
}else{
zb-=100;
gn=10;
g=2;
j+=15;
zj+=15;
}
}else if(dx==3){
if(zb<500){
cout<<"金币不够!\n";
continue;
}else{
zb-=500;
gn=20;
g=3;
j+=40;
zj+=40;
}
}else if(dx==4){
if(zb<2500){
cout<<"金币不够!\n";
continue;
}else{
zb-=2500;
gn=40;
g=4;
j+=100;
zj+=100;
}
}
}else{
}
}else if(s==3){
cout<<"煤炭:"<<k[0]<<"个\n";
cout<<"铁:"<<k[1]<<"个\n";
cout<<"黄铜:"<<k[2]<<"个\n";
cout<<"黄金:"<<k[3]<<"个\n";
cout<<"钻石:"<<k[4]<<"个\n";
cout<<"钛:"<<k[5]<<"个\n";
cout<<"钢:"<<k[20]<<"个\n";
cout<<"黄铜合金:"<<k[21]<<"个\n";
cout<<"黑金合金:"<<k[22]<<"个\n";
cout<<"钛合金:"<<k[22]<<"个\n";
}else if(s==4){
cout<<"煤炭:"<<k[0]<<"个\n";
cout<<"铁:"<<k[1]<<"个\n";
cout<<"黄铜:"<<k[2]<<"个\n";
cout<<"黄金:"<<k[3]<<"个\n";
cout<<"钻石:"<<k[4]<<"个\n";
cout<<"钛:"<<k[5]<<"个\n";
cout<<"钢:"<<k[20]<<"个\n";
cout<<"黄铜合金:"<<k[21]<<"个\n";
cout<<"黑金合金:"<<k[22]<<"个\n";
cout<<"钛合金:"<<k[22]<<"个\n";
cout<<"卖什么?\n";
cout<<"1.煤炭:10元/个\n";
cout<<"2.铁:50元/个\n";
cout<<"3.黄铜:100元/个\n";
cout<<"4.黄金:250元/个\n";
cout<<"5.钻石:800元/个\n";
cout<<"6.钛:400元/个\n";
cout<<"7.钢:160元/个\n";
cout<<"8.黄铜合金:310元/个\n";
cout<<"9.黑金合金:700元/个\n";
cout<<"10.钛合金:1100元/个\n";
cin>>kw;
if(kw<0||kw>9){
cout<<"errow!";
continue;
}
cin>>gs;
if(kw==1){
if(gs>k[0]){
cout<<"没有足够矿物!";
continue;
}else{
k[0]-=gs;
zb+=gs*10;
j+=gs*2;
zj+=gs*2;
}
}else if(kw==2){
if(gs>k[1]){
cout<<"没有足够矿物!";
continue;
}else{
k[1]-=gs;
zb+=gs*50;
j+=gs*6;
zj+=gs*6;
}
}else if(kw==3){
if(gs>k[2]){
cout<<"没有足够矿物!";
continue;
}else{
k[2]-=gs;
zb+=gs*100;
j+=gs*20;
zj+=gs*20;
}
}else if(kw==4){
if(gs>k[3]){
cout<<"没有足够矿物!";
continue;
}else{
k[3]-=gs;
zb+=gs*250;
j+=gs*50;
zj+=gs*50;
}
}else if(kw==5){
if(gs>k[4]){
cout<<"没有足够矿物!";
continue;
}else{
k[4]-=gs;
zb+=gs*800;
j+=gs*200;
zj+=gs*200;
}
}else if(kw==6){
if(gs>k[5]){
cout<<"没有足够矿物!";
continue;
}else{
k[5]-=gs;
zb+=gs*400;
j+=gs*40;
zj+=gs*40;
}
}else if(kw==7){
if(gs>k[20]){
cout<<"没有足够矿物!";
continue;
}else{
k[20]-=gs;
zb+=gs*160;
j+=gs*60;
zj+=gs*60;
}
}else if(kw==8){
if(gs>k[21]){
cout<<"没有足够矿物!";
continue;
}else{
k[21]-=gs;
zb+=gs*310;
j+=gs*100;
zj+=gs*100;
}
}else if(kw==9){
if(gs>k[22]){
cout<<"没有足够矿物!";
continue;
}else{
k[22]-=gs;
zb+=gs*700;
j+=gs*180;
zj+=gs*180;
}
}else if(kw==10){
if(gs>k[23]){
cout<<"没有足够矿物!";
continue;
}else{
k[23]-=gs;
zb+=gs*1100;
j+=gs*250;
zj+=gs*250;
}
}
cout<<"当前资产:"<<zb<<"元\n";
}else if(s==5){
for(int i=1;y[i]!=0;i++){
y[i]=0;
}
dx=0;
cout<<"煤炭:"<<k[0]<<"个\n";
cout<<"铁:"<<k[1]<<"个\n";
cout<<"黄铜:"<<k[2]<<"个\n";
cout<<"黄金:"<<k[3]<<"个\n";
cout<<"钻石:"<<k[4]<<"个\n";
cout<<"钛:"<<k[5]<<"个\n";
cout<<"钢:"<<k[20]<<"个\n";
cout<<"黄铜合金:"<<k[21]<<"个\n";
cout<<"黑金合金:"<<k[22]<<"个\n";
cout<<"钛合金:"<<k[22]<<"个\n";
cout<<"当前可以冶炼:\n";
if(k[0]>=1&&k[1]>=3){
dx++;
y[dx]=1;
cout<<dx<<".";
cout<<"钢\n";
}
if(k[0]>=1&&k[1]>=2&&k[2]>=2){
dx++;
y[dx]=2;
cout<<dx<<".";
cout<<"黄铜合金\n";
}
if(k[1]>=2&&k[2]>=1&&k[3]>=2){
dx++;
y[dx]=3;
cout<<dx<<".";
cout<<"黑金合金\n";
}
if(k[1]>=1&&k[3]>=1&&k[5]>=2){
dx++;
y[dx]=4;
cout<<dx<<".";
cout<<"钛合金\n";
}
if(dx==0){
cout<<"没有可以冶炼的东西!\n";
continue;
}else{
cout<<"请选择冶炼的序号\n";
x=dx;
cin>>dx;
if(dx>x||dx<1){
cout<<"errow!\n";
continue;
}else if(y[dx]==1){
cout<<"个数:\n";
cin>>gs;
if(gs>k[0]||gs*3>k[1]){
cout<<"冶炼失败!\n";
continue;
}else{
cout<<"冶炼成功!\n";
k[0]-=gs;
k[1]-=gs*3;
k[20]+=gs;
j+=10;
zj+=10;
}
}else if(y[dx]==2){
cout<<"个数:\n";
cin>>gs;
if(gs>k[0]||gs*2>k[1]||gs*2>k[2]){
cout<<"冶炼失败!\n";
continue;
}else{
cout<<"冶炼成功!\n";
k[0]-=gs;
k[1]-=gs*2;
k[2]-=gs*2;
k[21]+=gs;
j+=25;
zj+=25;
}
}else if(y[dx]==3){
cout<<"个数:\n";
cin>>gs;
if(gs*2>k[1]||gs*1>k[2]||gs*2>k[3]){
cout<<"冶炼失败!\n";
continue;
}else{
cout<<"冶炼成功!\n";
k[1]-=gs*2;
k[2]-=gs;
k[3]-=gs*2;
k[22]+=gs;
j+=40;
zj+=40;
}
}else if(y[dx]==4){
cout<<"个数:\n";
cin>>gs;
if(gs>k[1]||gs>k[3]||gs*2>k[5]){
cout<<"冶炼失败!\n";
continue;
}else{
cout<<"冶炼成功!\n";
k[1]-=gs;
k[3]-=gs;
k[5]-=gs*2;
k[23]+=gs;
j+=50;
zj+=50;
}
}
}
}else if(s==6){
for(int i=1;y[i]!=0;i++){
y[i]=0;
}
dx=0;
cout<<"煤炭:"<<k[0]<<"个\n";
cout<<"铁:"<<k[1]<<"个\n";
cout<<"黄铜:"<<k[2]<<"个\n";
cout<<"黄金:"<<k[3]<<"个\n";
cout<<"钻石:"<<k[4]<<"个\n";
cout<<"钢:"<<k[20]<<"个\n";
cout<<"黄铜合金:"<<k[21]<<"个\n";
cout<<"黑金合金:"<<k[22]<<"个\n";
cout<<"钛合金:"<<k[22]<<"个\n";
cout<<"当前可以合成:";
if(k[20]>=5&&k[1]>=4){
dx++;
y[dx]=1;
cout<<dx<<".";
cout<<"钢镐\n";
}
if(k[21]>=5&&k[1]>=1&&k[2]>=2){
dx++;
y[dx]=2;
cout<<dx<<".";
cout<<"黄铜镐\n";
}
if(k[22]>=5&&k[1]>=1&&k[2]>=2&&k[3]>=1){
dx++;
y[dx]=3;
cout<<dx<<".";
cout<<"黑金镐\n";
}
if(k[23]>=5&&k[1]>=1&&k[3]>=2&&k[4]>=1){
dx++;
y[dx]=4;
cout<<dx<<".";
cout<<"钛镐\n";
}
if(dx==0){
cout<<"没有可以合成的东西!\n";
continue;
}else{
cout<<"请选择合成序号\n";
x=dx;
cin>>dx;
if(dx<1||dx>x){
cout<<"errow!\n";
continue;
}else if(y[dx]==1){
if(k[20]<5||k[1]<4){
cout<<"合成失败!\n";
continue;
}else{
cout<<"合成成功!\n";
g=5;
gn=50;
k[20]-=5;
k[1]-=4;
j+=10;
zj+=10;
}
}else if(y[dx]==2){
if(k[21]<5||k[1]<1||k[2]<2){
cout<<"合成失败!\n";
continue;
}else{
cout<<"合成成功!\n";
g=6;
gn=80;
k[21]-=5;
k[1]-=1;
k[2]-=2;
j+=25;
zj+=25;
}
}else if(y[dx]==3){
if(k[22]<5||k[1]<1||k[2]<2||k[3]<1){
cout<<"合成失败!\n";
continue;
}else{
cout<<"合成成功!\n";
g=7;
gn=100;
k[22]-=5;
k[1]-=1;
k[2]-=2;
k[3]-=1;
j+=40;
zj+=40;
}
}else if(y[dx]==4){
if(k[23]<5||k[1]<1||k[3]<2||k[4]<1){
cout<<"合成失败!\n";
continue;
}else{
cout<<"合成成功!\n";
g=8;
gn=125;
k[23]-=5;
k[1]-=1;
k[3]-=2;
k[4]-=1;
j+=75;
zj+=75;
}
}
}
}
while(power(d,1.04)<=j){
j-=power(d,1.04);
d++;
}
}
return 0;
}
小鹿UUyM6,首先这个程序对mac用户非常不友好
其次万能头会拖慢运行速度,建议用:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <ctime>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <windows.h>
还有你发帖时这个排版
而且这个游戏没有存档,建议用freopen进行存档
建议不要用if else
用switch case
建议搞下地形,玩家移动,文件读取地形,可以参考下我的程序:
printf(" 请输入关喵:");
cin>>gam;
gam+=".txt";
freopen(gam.c_str(),"r",stdin);
点赞0
评论
小鹿UUyM我的程序其中的一部分核心代码
while(1){
if(a==1){
a=1;
wind();
Sleep(300);
exi(1);
}
else if(a==0){
a=2;
wind();
Sleep(300);
ch[i_1][j_1]="qi";
wind();
Sleep(300);
exi(0);
}
wind();
cha=getch();
if(ch[i_1-1][j_1]!="墙"){
if(cha=='w'||cha=='W'){
if(ch[i_1-1][j_1]=="门"){
a=1;
end=time(NULL);
continue;
}
if(ch[i_1-1][j_1]=="水"||ch[i_1-1][j_1]=="火"){
a=0;
end=time(NULL);
continue;
}
ch[i_1-1][j_1]="我";
ch[i_1][j_1]="qi";
i_1-=1;
start=time(NULL);
jump++;
}
if(time(NULL)-start>=0.2){
if(ch[i_1+jump][j_1]=="火"||ch[i_1+jump][j_1]=="水"){
a=0;
end=time(NULL);
continue;
}
if(ch[i_1+1][j_1]!="墙"&&ch[i_1+2][j_1]!="墙"){
ch[i_1+jump][j_1]="我";
ch[i_1][j_1]="qi";
i_1+=jump;
}
start=0;
jump=0;
}
}
else
ch[i_1][j_1]="我";
if(ch[i_1][j_1-1]!="墙"){
if(cha=='a'||cha=='A'){
if(ch[i_1][j_1-1]=="门"){
a=1;
end=time(NULL);
continue;
}
if(ch[i_1][j_1-1]=="水"||ch[i_1][j_1-1]=="火"){
a=0;
end=time(NULL);
continue;
}
ch[i_1][j_1-1]="我";
ch[i_1][j_1]="qi";
j_1-=1;
}
}
else
ch[i_1][j_1]="我";
if(ch[i_1+1][j_1]!="墙"){
if(cha=='s'||cha=='S'){
if(ch[i_1+1][j_1]=="门"){
a=1;
end=time(NULL);
continue;
}
if(ch[i_1+1][j_1]=="水"||ch[i_1+1][j_1]=="火"){
a=0;
end=time(NULL);
continue;
}
if(ch[i_1+1][j_1]!="墙"&&jump>0)
jump--;
ch[i_1+1][j_1]="我";
ch[i_1][j_1]="qi";
i_1+=1;
}
}
else
ch[i_1][j_1]="我";
if(ch[i_1][j_1+1]!="墙"){
if(cha=='d'||cha=='D'){
if(ch[i_1][j_1+1]=="门"){
a=1;
end=time(NULL);
continue;
}
if(ch[i_1][j_1+1]=="水"||ch[i_1][j_1+1]=="火"){
a=0;
end=time(NULL);
continue;
}
ch[i_1][j_1+1]="我";
ch[i_1][j_1]="qi";
j_1+=1;
}
}
else
ch[i_1][j_1]="我";
if(ch[i_1+1][j_1]=="水"||ch[i_1+1][j_1]=="火"){
a=0;
end=time(NULL);
continue;
}
}点赞0
评论