0
已解决
李雨彤
资深光能
资深光能
#include<iostream>
#include<string>
#include<windows.h>
using namespace std;
int main(){
//初始值设定
char a;
bool flag=false,f1;
int sum=0,b=0;//sum是余额,b是**金额
string s="",s2="...",s3="***",s4,s5;
//s:账号 s2:密码 s3:暂存新密码 s4:确认密码 s5:缓存新密码
//初始化界面
cout<<"欢迎进入**\n";
Sleep(1000);
cout<<"**加载中,请稍后";
for(int i=1;i<=6;i++){
Sleep(500);
cout<<".";
}
cout<<"\n该**目前仅供一人使用,期待后期**,使用前请注意,周围环境是否安全!!!\n";
while(1){
while(1){
//菜单展示
cout<<"请选择你需要的功能\n";
cout<<"1----创建账号\n";
cout<<"2----重置密码\n";
cout<<"3----**\n";
cout<<"4----取钱\n";
cout<<"5----查询余额\n";
cout<<"#----退出**\n";
cin>>a;
if(a=='1'){//创建账号
cout<<"请输入你想创建的账号名称(提示账号名不可有数字)\n";
getline(cin,s);//吃换行
getline(cin,s);
bool f1=true;//记录账号名是否合法
for(int i=0;i<s.size();i++){
if(s[i]<='9'&&s[i]>='0'){
f1=false;
}
}
if(f1==false){
cout<<"用户名不正确,用户创建失败\n";
break;
}
cout<<"用户名创建成功,请输入密码\n";
getline(cin,s2);
cout<<"账户创建成功,请妥善保管好账号信息,如账号丢失,后果自负 \n";
}else if(a=='2'){//重置密码
if(s.empty()){
cout<<"请先创建账号";
break;
}
cout<<"请输入当前账号的密码:\n";
getline(cin,s3);
getline(cin,s3);
if(s3!=s2){
cout<<"你不是本人,密码重置失败 \n";
break;
}
cout<<"请输入新密码:\n";
getline(cin,s3);
cout<<"请再次确认密码:\n";
getline(cin,s4);
if(s3==s4){
cout<<"密码重置成功 \n";
s2=s3;
} else{
cout<<"密码重置失败 \n";
}
system("cls");
}
else if(a=='3'){//**
if(s.empty()){
cout<<"请先创建账号 \n";
break;
}
cout<<"请输入**金额:\n";
cin>>b;
sum+=b;
cout<<"**成功,当前余额为:"<<sum<<endl;
system("cls");
}
else if(a=='4'){//取钱
if(s.empty()){
cout<<"请先创建账号 \n";
break;
}
cout<<"请输入取入取出金额:\n";
cin>>b;
sum-=b;
cout<<"取出成功,当前余额为:"<<sum<<endl;
cout<<"等待“滴”一声,请从卡槽中取走发票和线财\n";
system("cls");
}
else if(a=='5'){//查询余额
if(s.empty()){
cout<<"前先创建账号 \n";
break;
}
cout<<"当前账号余额为:"<<sum<<endl;
system("cls");
}
else if(a=='#'){//退出**
flag=true;
break;
system("cls");
}
else{//输入有误2
cout<<"输入字符为非法字符,请重新输入\n";
}
}
if(flag==true){
break;
}
cout<<"\n\n感谢使用";
}
return 0;
}
这个加了一个取钱功能
李雨彤在2021-08-27 12:53:07追加了内容
#include<iostream>
#include<conio.h>
#include<windows.h>
#include<iomanip>
#define R 10
#define C 10
using namespace std;
/*
1.表示墙体
3.表示目的地
4.表示箱子
5.表示人
0.表示空地
*/
int map[R][C];
int map1[10][10]={
{0,0,1,1,1,0,0,0},
{0,0,1,3,1,0,0,0},
{1,1,1,4,1,1,1,1},
{1,0,0,0,0,4,3,1},
{1,3,4,0,0,1,1,1},
{1,1,1,5,4,1,0,0},
{0,0,0,1,3,1,0,0},
{0,0,0,1,1,1,0,0},
};
int map2[10][10]={
{1,1,1,1,1,0,0,0,0,0},
{1,5,0,0,1,0,0,0,0,0},
{1,0,4,4,1,0,1,1,1,0},
{1,0,4,0,1,0,1,3,1,0},
{1,1,1,0,1,1,1,3,1,0},
{0,1,1,0,0,0,0,3,1,0},
{0,1,0,0,0,0,0,0,1,0},
{0,1,0,0,0,1,1,1,1,0},
{0,1,1,1,1,1,0,0,0,0},
};
int map3[10][10]={
{0,0,0,1,1,1,1,1,1,1},
{0,0,1,1,0,0,1,0,5,1},
{0,0,1,0,0,0,0,0,0,1},
{0,0,1,4,0,4,0,4,0,1},
{0,0,1,0,4,1,1,0,0,1},
{1,1,1,0,4,0,1,0,1,1},
{1,3,3,3,3,3,0,0,1,0},
{1,1,1,1,1,1,1,1,1,0},
};
int map4[10][10]={
{1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,3,0,0,1},
{1,0,0,0,4,0,0,4,0,1},
{1,3,0,1,1,1,1,5,0,1},
{1,0,0,1,0,0,1,0,0,1},
{1,0,0,1,0,0,1,1,1,1},
{1,0,0,1,1,1,1,1,1,1},
{1,0,4,0,3,0,0,0,0,1},
{1,0,0,0,0,0,0,4,3,1},
{1,1,1,1,1,1,1,1,1,1},
};
//函数声明
void Game_Menu();//初始化模块,显示游戏开始菜单
void Game_description();//初始化模块,显示游戏操作说明
int DrawMap();//画图模块,绘制地图
void Move();//移动模块,操作人物和箱子的移动
void color(int m);//判断游戏是否**成功
void setmap(int n);//游戏关卡设置
int finish();//设置文本显示时的颜色
bool flag=true;
int pass=1;//初始关卡
int main(){
Game_Menu();
Game_description();
int ch;
ch=_getch();
setmap(pass);
switch(ch){
case 'q':
case 'Q':
return 0;
case 's':
case 'S':
while(flag){
system("cls");
DrawMap();
Move();
if(finish()){
system("cls");
DrawMap();
cout<<"游戏胜利!\n";
system("pause");
pass++;
setmap(pass);
}
}
break;
}
return 0;
}
void Game_Menu(){
system("cls");
cout<<"\\*********************/\n";
cout<<"* *\n";
cout<<"* 经典小游戏 *\n";
cout<<"* 推箱子 *\n";
cout<<"* 按S或者s键开始 *\n";
cout<<"* 按Q或者q键退出 *\n";
cout<<"* *\n";
cout<<"\\*********************/\n";
Sleep(500);
}
void Game_description(){
cout<<"\\*********************/\n";
cout<<"* *\n";
cout<<"* 操作提示 *\n";
cout<<"* 操作上移:W w ↑ *\n";
cout<<"* 操作下移:S s ↓ *\n";
cout<<"* 操作左移:A a ← *\n";
cout<<"* 操作右移:D d → *\n";
cout<<"* *\n";
cout<<"* 退 出:Q q *\n";
cout<<"* *\n";
cout<<"\\*********************/\n";
_getch();
}
int DrawMap(){
cout<<"\n关卡:"<<pass<<endl;
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
switch(map[i][j]){
case 0:
color(0xF);
cout<<" ";
break;
case 1:
color(14);
cout<<"■";
break;
case 3:
color(15);
cout<<"☆";
break;
case 4:
color(9);
cout<<"□";
break;
case 5:
color(13);
cout<<"♀";
break;
case 7:
color(3);
cout<<"★";
break;
case 8:
color(12);
cout<<"♀";
break;
default:
break;
}
}
cout<<endl;
}
cout<<"\n重新开始本关请按p\n";
return 0;
}
void Move(){
int r,c;
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(map[i][j]==5||map[i][j]==8){
r=i;
c=j;
}
}
}
cout<<"您当前的坐标为:("<<r<<","<<c<<")"<<endl;
int ch;
ch=_getch();
switch(ch){
case 'W':
case 'w':
case 72:
if(map[r-1][c]==0||map[r-1][c]==3){
map[r-1][c]+=5;
map[r][c]-=5;
}
else if(map[r-1][c]==4||map[r-1][c]==7){
if(map[r-2][c]==0||map[r-2][c]==3){
map[r-2][c]+=4;
map[r-1][c]+=1;
map[r][c]-=5;
}
}
break;
case 'S':
case 's':
case 80:
if(map[r+1][c]==0||map[r+1][c]==3){
map[r+1][c]+=5;
map[r][c]-=5;
}
else if(map[r+1][c]==4||map[r+1][c]==7){
if(map[r+2][c]==0||map[r+2][c]==3){
map[r+2][c]+=4;
map[r+1][c]+=1;
map[r][c]-=5;
}
}
break;
case 'A':
case 'a':
case 75:
if(map[r][c-1]==0||map[r][c-1]==3){
map[r][c-1]+=5;
map[r][c]-=5;
}
else if(map[r][c-1]==4||map[r][c-1]==7){
if(map[r][c-2]==0||map[r][c-2]==3){
map[r][c-2]+=4;
map[r][c-1]+=1;
map[r][c]-=5;
}
}
break;
case 'D':
case 'd':
case 77:
if(map[r][c+1]==0||map[r][c+1]==3){
map[r][c+1]+=5;
map[r][c]-=5;
}
else if(map[r][c+1]==4||map[r][c+1]==7){
if(map[r][c+2]==0||map[r][c+2]==3){
map[r][c+2]+=4;
map[r][c+1]+=1;
map[r][c]-=5;
}
}
break;
case 'Q':
case 'q':
flag=false;
break;
case 'p':
setmap(pass);
break;
default:
break;
}
}
int finish(){
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(map[i][j]==4){
return 0;
}
}
}
return 1;
}
void setmap(int n){
if(n==1){
memcpy(map,map1,sizeof(map1));
}
if(n==2){
memcpy(map,map2,sizeof(map2));
}
if(n==3){
memcpy(map,map3,sizeof(map3));
}
if(n==4){
memcpy(map,map4,sizeof(map4));
}
}
void color(int m){
HANDLE consolehend;
consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consolehend,m);
return ;
}
李雨彤在2021-08-28 10:11:31追加了内容
#include "iostream"
#include "windows.h"
using namespace std;
int MAX=6,MIN=1;
int jf=0;
bool n=1;
int a,b,c;
int x,y,z;
int main(){
cout <<"-----掷色子小游戏-----\n" << endl;
cout<<"你有3个色子,对手也有3个\n";
cout<<endl;
cout<<"开始!\n";
a=MIN+rand()%(MAX-MIN+1);
b=MIN+rand()%(MAX-MIN+1);
c=MIN+rand()%(MAX-MIN+1);
x=MIN+rand()%(MAX-MIN+1);
y=MIN+rand()%(MAX-MIN+1);
z=MIN+rand()%(MAX-MIN+1);
Sleep(1000);
cout<<"你的色子:\n";
cout<<a<<" "<<b<<" "<<c<<"\n";
cout<<"对手的色子:\n";
cout<<x<<" "<<y<<" "<<z<<"\n";
if(a==b&&a==c){
if(x==y&&x==z){
cout<<"平局\n";
}
else{
cout<<"你赢了,积分加10!!!\n";
jf+=10;
cout<<"你的积分:"<<jf<<"\n";
}
}
else{
if(x==y&&x==z){
cout<<"你输了,积分减2\n";
}
else{
cout<<"平局\n";
cout<<"你的积分:\n"<<jf;
}
}
Sleep(5000);
cout<<"\n还想玩请再重启游戏" ;
return 0;
}
0
0
0
0
0
0
0
0
0