-
c++小游戏
2020-07-21 16:44:18 -
C++小游戏
2007-07-19 21:04:41简单的游戏让你学会C++ -
RPG类C++小游戏
2021-01-01 09:26:22RPG类C++小游戏 -
c++小游戏代码
2015-06-23 11:14:10c++小游戏代码 -
C++小游戏合集
2020-08-24 16:48:37C++小游戏合集 C++小游戏:大乱斗 今天,给大家推荐一个由我自己原创编写的一个C++小游戏,游戏玩法十分简单,适合单人游戏(消遣时间),游戏并没有贴图,能力有限,希望大家见谅。好了,话不多说直接上代码: #...C++小游戏合集
全部原创,请勿抄袭!后续会进行更新。
C++小游戏(1):大乱斗
今天,给大家推荐一个由我自己原创编写的一个C++小游戏,游戏玩法十分简单,适合单人游戏(消遣时间),游戏并没有贴图,能力有限,希望大家见谅。后续会进行更新。好了,话不多说直接上代码:
#include<bits/stdc++.h> #include<conio.h> #include<windows.h> using namespace std; double shanghai[20]={0.6,1.1,2,3.16,5.5,7,10,20,50,100,146.23,254.13,312,403,601,1023}; double bosshealth[20]={2,3,4,5.9,8,14,19,32,73,157,200,403,801,1200,3630,20123}; double wj_shanghai=1,wj_health=10,wj_max_health=10,boss,wj_money; void chushihua(); void game(); void gongji(); void goumai(); void shangdian(); void zhujiemian(); void fangyu(); void cend(); void chushou(); void print(char[]); int bishou=0,caidao=0,jian=0,shenjian=0; double bishou_1=5,caidao_1=17,jian_1=58,shenjian_1=123.1; int hat=0,douhui=0,hudun=0,hunjia=0,shendun=0; double hat_1=7,douhui_1=21,hudun_1=49,hunjia_1=89,shendun_1=210.4; void cend() { system("cls"); print("GAME OVER"); exit(1); } void game() { int k; chushihua(); IO: printf("请输入对手等级 (0~15)\n"); scanf("%d",&k); if(k>15||k<0) { system("cls"); goto IO; } boss=bosshealth[k]; system("cls"); while(wj_health>=0) { srand(time(NULL)); QP: printf("1.逃跑 2.进攻\n"); char s=getch(); if(s<'1'||s>'2') { system("cls"); goto QP; } if(s=='1') { system("cls"); zhujiemian(); } system("cls"); double l=shanghai[k]*((rand()%2)+1)+fabs(double(rand()%100/100-2)); printf("对手对你造成了%lf点伤害\n",l); wj_health-=l; printf("你当前剩余血量:%lf\n",wj_health); if(wj_health<=0) cend(); double o=wj_shanghai*((rand()%2)+1)+double(rand()%10/10); boss-=o; printf("你对对手造成了%lf点伤害\n",o); printf("对手当前剩余血量:%lf\n\n",boss); if(boss<=0) { printf("胜利!\n获得%lf金币\n\n当前剩余血量:%lf\n",shanghai[k]+3,wj_health); wj_money+=shanghai[k]+3; printf("\n余额:%lf\n",wj_money); getch(); if(k==15) { printf("恭喜玩家!游戏胜利!\n"); getch(); exit(1); } system("cls"); zhujiemian(); } } } void zhujiemian() { PO: printf("1.商店 2.战斗 3.回血 4.状态\n"); char k=getch(); if(k>'4'||k<'1') { system("cls"); goto PO; } if(k=='1') { system("cls"); shangdian(); return; } if(k=='2') { system("cls"); game(); return; } if(k=='3') { system("cls"); if(wj_money>0) { wj_money=wj_money*4/5-1; chushihua(); wj_health=wj_max_health; printf("回血成功!\n"); getch(); system("cls"); goto PO; } else { printf("余额不足!\n"); getch(); system("cls"); goto PO; } } if(k=='4') { chushihua(); system("cls"); printf("生命值:%lf\n",wj_health); printf("最大生命值:%lf\n",wj_max_health); printf("攻击力:%lf\n",wj_shanghai); printf("金币:%lf\n",wj_money); getch(); system("cls"); goto PO; } if(k=='5') { string a; system("cls"); printf("输入密码!\n"); cin>>a; if(a=="songyudashuaibi"||a=="PI") { wj_money+=1000; printf("外挂生效\n"); Sleep(1000); system("cls"); goto PO; } printf("外挂失败\n"); Sleep(1000); system("cls"); goto PO; } } void shangdian() { LK: printf("1.购买 2.返回主界面\n"); char k=getch(); if(k!='1'&&k!='2') { system("cls"); goto LK; } if(k=='1') { system("cls"); goumai(); goto LK; } if(k=='2') { system("cls"); zhujiemian(); return; } } void goumai() { ML: printf("1.攻击 2.防御 3.返回主界面\n"); char k=getch(); if(k!='1'&&k!='2'&&k!='3') { system("cls"); goto ML; } if(k=='1') { system("cls"); gongji(); goto ML; } if(k=='3') { system("cls"); zhujiemian(); return; } if(k=='2') { fangyu(); } } void gongji() { OP: system("cls"); printf("0.返回上界面\n"); printf("1.返回主界面\n"); printf("2.匕首 5金币\n"); printf("3.菜刀 17金币\n"); printf("4.剑 68金币\n"); printf("5.圣剑 210金币\n"); printf("提醒:金币价格与伤害成正比\n"); char k=getch(); if(k<'0'||k>'5') { system("cls"); goto OP; } if(k=='0') { system("cls"); goumai(); return; } if(k=='1') { system("cls"); zhujiemian(); return; } if(k=='2') { if(wj_money>=bishou_1) { chushihua(); system("cls"); wj_money-=bishou_1; bishou++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); system("cls"); goto OP; } if(k=='3') { if(wj_money>=caidao_1) { chushihua(); system("cls"); wj_money-=caidao_1; caidao++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); goto OP; } if(k=='4') { if(wj_money>=jian_1) { chushihua(); system("cls"); wj_money-=jian_1; jian++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); goto OP; } if(k=='5') { if(wj_money>=shenjian_1) { chushihua(); system("cls"); wj_money-=shenjian_1; shenjian++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); goto OP; } } void fangyu() { OP: system("cls"); printf("0.返回上界面\n"); printf("1.返回主界面\n"); printf("2.帽子 7金币\n"); printf("3.头盔 21金币\n"); printf("4.护盾 49金币\n"); printf("5.盔甲 89金币\n"); printf("6.圣盾 210金币\n"); printf("提醒:金币价格与伤害成正比\n"); char k=getch(); if(k<'0'||k>'6') { system("cls"); goto OP; } if(k=='0') { system("cls"); goumai(); return; } if(k=='1') { system("cls"); zhujiemian(); return; } if(k=='2') { if(wj_money>=hat_1) { chushihua(); system("cls"); wj_money-=hat_1; hat++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); system("cls"); goto OP; } if(k=='3') { if(wj_money>=douhui_1) { chushihua(); system("cls"); wj_money-=douhui_1; douhui++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); goto OP; } if(k=='4') { if(wj_money>=hudun_1) { chushihua(); system("cls"); wj_money-=hudun_1; hudun++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); goto OP; } if(k=='5') { chushihua(); if(wj_money>=hunjia_1) { system("cls"); wj_money-=hunjia_1; hunjia++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); goto OP; } if(k=='6') { if(wj_money>=shendun_1) { chushihua(); system("cls"); wj_money-=shendun_1; shendun++; goto OP; } system("cls"); printf("余额不足!\n"); getch(); goto OP; } } void chushihua() { wj_max_health=hat*hat_1+douhui*douhui_1+hudun*hudun_1+hunjia*hunjia_1+shendun*shendun_1+10; wj_shanghai=bishou*bishou_1+caidao*caidao_1+jian*jian_1+shenjian*shenjian_1+1; } void print(char a[]) { int s=strlen(a); for(int i=0;i<s;i++) { cout<<a[i]; Sleep(400); } getch(); system("cls"); } int main() { system("title game"); print("小小阁楼原创出品:打怪小游戏"); zhujiemian(); return 0; }
C++小游戏(2):打飞机
今天给大家分享一个关于扫雷的C++小游戏,本人技术不精,游戏比较简单,如果有什么问题欢迎各位小伙伴们留言。
话不多说,直接上代码:#include<iostream> #include<windows.h> #include<conio.h> #include<time.h> #include<string> using namespace std; typedef struct Frame { COORD position[2]; int flag; } Frame; void SetPos(COORD a) { HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(out, a); } void SetPos(int i, int j) { COORD pos= {i, j}; SetPos(pos); } void HideCursor() { CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); } void drawRow(int y, int x1, int x2, char ch) { SetPos(x1,y); for(int i = 0; i <= (x2-x1); i++) cout<<ch; } void drawRow(COORD a, COORD b, char ch) { if(a.Y == b.Y) drawRow(a.Y, a.X, b.X, ch); else { SetPos(0, 25); cout<<"error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等"; system("pause"); } } void drawCol(int x, int y1, int y2, char ch) { int y=y1; while(y!=y2+1) { SetPos(x, y); cout<<ch; y++; } } void drawCol(COORD a, COORD b, char ch) { if(a.X == b.X) drawCol(a.X, a.Y, b.Y, ch); else { SetPos(0, 25); cout<<"error code 02:无法填充列,因为两个坐标的横坐标(y)不相等"; system("pause"); } } void drawFrame(COORD a, COORD b, char row, char col) { drawRow(a.Y, a.X+1, b.X-1, row); drawRow(b.Y, a.X+1, b.X-1, row); drawCol(a.X, a.Y+1, b.Y-1, col); drawCol(b.X, a.Y+1, b.Y-1, col); } void drawFrame(int x1, int y1, int x2, int y2, char row, char col) { COORD a= {x1, y1}; COORD b= {x2, y2}; drawFrame(a, b, row, col); } void drawFrame(Frame frame, char row, char col) { COORD a = frame.position[0]; COORD b = frame.position[1]; drawFrame(a, b, row, col); } void drawPlaying() { drawFrame(0, 0, 48, 24, '=', '|'); drawFrame(49, 0, 79, 4, '-', '|'); drawFrame(49, 4, 79, 9, '-', '|'); drawFrame(49, 9, 79, 20, '-', '|'); drawFrame(49, 20, 79, 24, '-', '|'); SetPos(52, 6); cout<<"得分:"; SetPos(52, 7); cout<<"称号:"; SetPos(52,10); cout<<"操作方式:"; SetPos(52,12); cout<<" a,s,d,w 控制战机移动,k攻击"; SetPos(52,14); cout<<" p 暂停游戏。"; SetPos(52,16); cout<<" e 退出游戏。"; } int random(int a, int b) { int c=(rand() % (a-b))+ a; return c; } COORD random(COORD a, COORD b) { int x=random(a.X, b.X); int y=random(a.Y, b.Y); COORD c= {x, y}; return c; } bool judgeCoordInFrame(Frame frame, COORD spot) { if(spot.X>=frame.position[0].X) if(spot.X<=frame.position[1].X) if(spot.Y>=frame.position[0].Y) if(spot.Y<=frame.position[0].Y) return true; return false; } void printCoord(COORD a) { cout<<"( "<<a.X<<" , "<<a.Y<<" )"; } void printFrameCoord(Frame a) { printCoord(a.position[0]); cout<<" - "; printCoord(a.position[1]); } int drawMenu() { SetPos(30, 1); cout<<"P l a n e W a r"; drawRow(3, 0, 79, '-'); drawRow(5, 0, 79, '-'); SetPos(28, 4); cout<<"w 和 s 选择, k 确定"; SetPos(15, 11); cout<<"1. 简单的敌人"; SetPos(15, 13); cout<<"2. 冷酷的敌人"; drawRow(20, 0, 79, '-'); drawRow(22, 0, 79, '-'); SetPos(47, 11); cout<<"简单的敌人:"; SetPos(51, 13); cout<<"简单敌人有着较慢的移动速度。"; SetPos(24, 21); cout<<"制作:小小阁楼"; int j=11; SetPos(12, j); cout<<">>"; while(1) { if( _kbhit() ) { char x=_getch(); switch (x) { case 'w': { if( j == 13) { SetPos(12, j); cout<<" "; j = 11; SetPos(12, j); cout<<">>"; SetPos(51, 13); cout<<" "; SetPos(47, 11); cout<<"简单的敌人:"; SetPos(51, 13); cout<<"简单敌人有着较慢的移动速度,比较容易对付"; } break; } case 's': { if( j == 11 ) { SetPos(12, j); cout<<" "; j = 13; SetPos(12, j); cout<<">>"; SetPos(51, 13); cout<<" "; SetPos(47, 11); cout<<"冷酷的敌人:"; SetPos(51, 13); cout<<"冷酷的敌人移动速度较快,难对付哟。"; } break; } case 'k' : { if (j == 8) return 1; else return 2; } } } } } class Game { public: COORD position[10]; COORD bullet[10]; Frame enemy[8]; int score; int rank; int rankf; string title; int flag_rank; Game (); void initPlane(); void initBullet(); void initEnemy(); void planeMove(char); void bulletMove(); void enemyMove(); void drawPlane(); void drawPlaneToNull(); void drawBullet(); void drawBulletToNull(); void drawEnemy(); void drawEnemyToNull(); void drawThisBulletToNull( COORD ); void drawThisEnemyToNull( Frame ); void Pause(); void Playing(); void judgePlane(); void judgeEnemy(); void Shoot(); void GameOver(); void printScore(); }; Game::Game() { initPlane(); initBullet(); initEnemy(); score = 0; rank = 25; rankf = 0; flag_rank = 0; } void Game::initPlane() { COORD centren= {39, 22}; position[0].X=position[5].X=position[7].X=position[9].X=centren.X; position[1].X=centren.X-2; position[2].X=position[6].X=centren.X-1; position[3].X=position[8].X=centren.X+1; position[4].X=centren.X+2; for(int i=0; i<=4; i++) position[i].Y=centren.Y; for(int i=6; i<=8; i++) position[i].Y=centren.Y+1; position[5].Y=centren.Y-1; position[9].Y=centren.Y-2; } void Game::drawPlane() { for(int i=0; i<9; i++) { SetPos(position[i]); if(i!=5) cout<<"O"; else if(i==5) cout<<"|"; } } void Game::drawPlaneToNull() { for(int i=0; i<9; i++) { SetPos(position[i]); cout<<" "; } } void Game::initBullet() { for(int i=0; i<10; i++) bullet[i].Y = 30; } void Game::drawBullet() { for(int i=0; i<10; i++) { if( bullet[i].Y != 30) { SetPos(bullet[i]); cout<<"^"; } } } void Game::drawBulletToNull() { for(int i=0; i<10; i++) if( bullet[i].Y != 30 ) { COORD pos= {bullet[i].X, bullet[i].Y+1}; SetPos(pos); cout<<" "; } } void Game::initEnemy() { COORD a= {1, 1}; COORD b= {45, 15}; for(int i=0; i<8; i++) { enemy[i].position[0] = random(a, b); enemy[i].position[1].X = enemy[i].position[0].X + 3; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; } } void Game::drawEnemy() { for(int i=0; i<8; i++) drawFrame(enemy[i].position[0], enemy[i].position[1], '-', '|'); } void Game::drawEnemyToNull() { for(int i=0; i<8; i++) { drawFrame(enemy[i].position[0], enemy[i].position[1], ' ', ' '); } } void Game::Pause() { SetPos(61,2); cout<<" "; SetPos(61,2); cout<<"暂停中..."; char c=_getch(); while(c!='p') c=_getch(); SetPos(61,2); cout<<" "; } void Game::planeMove(char x) { if(x == 'a') if(position[1].X != 1) for(int i=0; i<=9; i++) position[i].X -= 2; if(x == 's') if(position[7].Y != 23) for(int i=0; i<=9; i++) position[i].Y += 1; if(x == 'd') if(position[4].X != 47) for(int i=0; i<=9; i++) position[i].X += 2; if(x == 'w') if(position[5].Y != 3) for(int i=0; i<=9; i++) position[i].Y -= 1; } void Game::bulletMove() { for(int i=0; i<10; i++) { if( bullet[i].Y != 30) { bullet[i].Y -= 1; if( bullet[i].Y == 1 ) { COORD pos= {bullet[i].X, bullet[i].Y+1}; drawThisBulletToNull( pos ); bullet[i].Y=30; } } } } void Game::enemyMove() { for(int i=0; i<8; i++) { for(int j=0; j<2; j++) enemy[i].position[j].Y++; if(24 == enemy[i].position[1].Y) { COORD a= {1, 1}; COORD b= {45, 3}; enemy[i].position[0] = random(a, b); enemy[i].position[1].X = enemy[i].position[0].X + 3; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; } } } void Game::judgePlane() { for(int i = 0; i < 8; i++) for(int j=0; j<9; j++) if(judgeCoordInFrame(enemy[i], position[j])) { SetPos(62, 1); cout<<"坠毁"; drawFrame(enemy[i], '+', '+'); Sleep(1000); GameOver(); break; } } void Game::drawThisBulletToNull( COORD c) { SetPos(c); cout<<" "; } void Game::drawThisEnemyToNull( Frame f ) { drawFrame(f, ' ', ' '); } void Game::judgeEnemy() { for(int i = 0; i < 8; i++) for(int j = 0; j < 10; j++) if( judgeCoordInFrame(enemy[i], bullet[j]) ) { score += 5; drawThisEnemyToNull( enemy[i] ); COORD a= {1, 1}; COORD b= {45, 3}; enemy[i].position[0] = random(a, b); enemy[i].position[1].X = enemy[i].position[0].X + 3; enemy[i].position[1].Y = enemy[i].position[0].Y + 2; drawThisBulletToNull( bullet[j] ); bullet[j].Y = 30; } } void Game::Shoot() { for(int i=0; i<10; i++) if(bullet[i].Y == 30) { bullet[i].X = position[5].X; bullet[i].Y = position[5].Y-1; break; } } void Game::printScore() { if(score == 120 && flag_rank == 0) { rank -= 3; flag_rank = 1; } else if( score == 360 && flag_rank == 1) { rank -= 5; flag_rank = 2; } else if( score == 480 && flag_rank == 2) { rank -= 5; flag_rank = 3; } int x=rank/5; SetPos(60, 6); cout<<score; if( rank!=rankf ) { SetPos(60, 7); if( x == 5) title="初级飞行员"; else if( x == 4) title="中级飞行员"; else if( x == 3) title="高级飞行员"; else if( x == 2 ) title="王牌飞行员"; cout<<title; } rankf = rank; } void Game::Playing() { drawEnemy(); drawPlane(); int flag_bullet = 0; int flag_enemy = 0; while(1) { Sleep(8); if(_kbhit()) { char x = _getch(); if ('a' == x || 's' == x || 'd' == x || 'w' == x) { drawPlaneToNull(); planeMove(x); drawPlane(); judgePlane(); } else if ('p' == x) Pause(); else if( 'k' == x) Shoot(); else if( 'e' == x) { GameOver(); break; } } if( 0 == flag_bullet ) { bulletMove(); drawBulletToNull(); drawBullet(); judgeEnemy(); } flag_bullet++; if( 5 == flag_bullet ) flag_bullet = 0; if( 0 == flag_enemy ) { drawEnemyToNull(); enemyMove(); drawEnemy(); judgePlane(); } flag_enemy++; if( flag_enemy >= rank ) flag_enemy = 0; printScore(); } } void Game::GameOver() { system("cls"); COORD p1= {28,9}; COORD p2= {53,15}; drawFrame(p1, p2, '=', '|'); SetPos(36,12); string str="Game Over!"; for(int i=0; i<str.size(); i++) { Sleep(80); cout<<str[i]; } Sleep(1000); system("cls"); drawFrame(p1, p2, '=', '|'); SetPos(31, 11); cout<<"击落敌机:"<<score/5<<" 架"; SetPos(31, 12); cout<<"得 分:"<<score; SetPos(31, 13); cout<<"获得称号:"<<title; SetPos(30, 16); Sleep(1000); cout<<"继续? 是(y)| 否(n) 制作:小小阁楼"; as: char x=_getch(); if (x == 'n') exit(0); else if (x == 'y') { system("cls"); Game game; int a = drawMenu(); if(a == 2) game.rank = 20; system("cls"); drawPlaying(); game.Playing(); } else goto as; } int main() { srand((int)time(0)); HideCursor(); Game game; int a = drawMenu(); if(a == 2) game.rank = 20; system("cls"); drawPlaying(); game.Playing(); }
C++小游戏(3):扫雷
今天给大家分享一个关于扫雷的C++小游戏,本人技术不精,游戏比较简单,如果有什么问题欢迎各位小伙伴们留言。
话不多说,直接上代码:#include<stdio.h> #include<windows.h> #include<stdlib.h> #include<time.h> #include<conio.h> #include<queue> #include<ctype.h> #define A 17 //地图的高 #define B 17 //地图的宽 #define C 30 //雷的总数 using namespace std; DWORD a,b; char map[A][B],news,spare; int BoomTotalNum,floatx,floaty,flag[A][B],flagnum,mode,slect[A][B],game; //颜色属性 const WORD FORE_BLUE = FOREGROUND_BLUE; //蓝色文本属性 const WORD FORE_GREEN = FOREGROUND_GREEN; //绿色文本属性 const WORD FORE_RED = FOREGROUND_RED; //红色文本属性 //开垦地图结构体 struct node { int x; int y; }; queue <node> dui; //打印位置 void position(int x,int y) { COORD pos= {x,y}; HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(Out,pos); } //隐藏光标 void Hide() { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO CursorInfo; GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息 CursorInfo.bVisible = false; //隐藏控制台光标 SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态 } //初始化 void Beginning() { while(!dui.empty()) { dui.pop(); } game=1; //BoomTotalNum=C; floatx=A/2; floaty=B/2; flagnum=0; BoomTotalNum=C; mode=0; HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄 CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体 GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息 int x,y; srand((unsigned)time(0)); for(int i=0; i<A; i++) for(int j=0; j<B; j++) { map[i][j]=' '; flag[i][j]=0; slect[i][j]=0; } while(BoomTotalNum) { x=rand()%A; y=rand()%B; if(map[x][y]==' ') { map[x][y]='@'; BoomTotalNum--; } } SetConsoleTextAttribute(handle_out, FORE_GREEN); for(int i=0; i<A; i++) { for(int j=0; j<B; j++) printf("█"); printf("\n"); } position(floaty*2,floatx); SetConsoleTextAttribute(handle_out, FORE_RED); printf(""); //光标位置 position(44,9); printf("扫雷模式"); position(44,5); printf("剩余雷数:%d ",C-flagnum); SetConsoleTextAttribute(handle_out, FORE_GREEN); position(5,22); printf("按“空格”切换模式"); position(5,23); printf("按“Enter”确认"); position(5,24); printf("按“方向键”选择方块"); } //打印地图的一块儿 void Lump(int xx,int yy) { switch(map[xx][yy]) { case '1' : printf("①"); break; //周围雷的数量(下同) case '2' : printf("②"); break; case '3' : printf("③"); break; case '4' : printf("④"); break; case '5' : printf("⑤"); break; case '6' : printf("⑥"); break; case '7' : printf("⑦"); break; case '8' : printf("⑧"); break; case ' ' : if(xx==floatx&&yy==floaty) { if(flag[xx][yy]==0) { if(mode%2==0) printf(""); else printf(""); } else printf(""); } else { if(flag[xx][yy]==0) printf("█"); else printf(""); } break; case '@' : if(xx==floatx&&yy==floaty) { if(flag[xx][yy]==0) { if(mode%2==0) printf(""); else printf(""); } else printf(""); } else { if(flag[xx][yy]==0) printf("█"); else printf(""); } break; case 'x' : if(floatx==xx&&floaty==yy) printf(""); else printf(" "); break; //已经挖开的空白 } } //移动光标 void Move() { HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄 CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体 GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息 int xxx,yyy; xxx=floatx; yyy=floaty; switch(news) { case 72 : floatx--; break; //上 case 80 : floatx++; break; //下 case 75 : floaty--; break; //左 case 77 : floaty++; break; //右 } if(floatx==-1) floatx=A-1; floatx%=A; //两端穿模处理 if(floaty==-1) floaty=B-1; floaty%=B; position(yyy*2,xxx); SetConsoleTextAttribute(handle_out, FORE_GREEN); Lump(xxx,yyy); //删除原位置 if(map[floatx][floaty]=='x') { position(floaty*2,floatx); printf(" "); } position(floaty*2,floatx); SetConsoleTextAttribute(handle_out, FORE_BLUE); Lump(floatx,floaty); //更新新位置 } //插旗和排雷模式切换 void Mode() { HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄 CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体 GetConsoleScreenBufferInfo(handle_out, &csbi); //获得窗口缓冲区信息 mode++; SetConsoleTextAttribute(handle_out, FORE_BLUE); position(floaty*2,floatx); if(mode%2==0) printf(""); else printf(""); position(44,9); if(mode%2==0) { SetConsoleTextAttribute(handle_out, FORE_BLUE); printf("扫雷模式"); } else { SetConsoleTextAttribute(handle_out, FORE_RED); printf("插旗模式"); } } //该点周围地雷数 int Boomnum(int xx,int yy) { int num=0; if((xx-1>=0)&&(yy-1>=0)&&(map[xx-1][yy-1]=='@')) num++; if((xx-1>=0)&&(yy+0>=0)&&(map[xx-1][yy]=='@')) num++; if((xx-1>=0)&&(yy+1<B) &&(map[xx-1][yy+1]=='@')) num++; if((xx+0>=0)&&(yy-1>=0)&&(map[xx][yy-1]=='@')) num++; if((xx+0>=0)&&(yy+1<B) &&(map[xx][yy+1]=='@')) num++; if((xx+1<A)&&(yy-1>=0) &&(map[xx+1][yy-1]=='@')) num++; if((xx+1<A)&&(yy+0>=0) &&(map[xx+1][yy]=='@')) num++; if((xx+1<A)&&(yy+1<B) &&(map[xx+1][yy+1]=='@')) num++; return num; } //更新地图 void Open() { node c; node d; while(!dui.empty()) { dui.pop(); } c.x=floatx; c.y=floaty; dui.push(c); slect[c.x][c.y]=1; while(!dui.empty()) { c=dui.front(); dui.pop(); if(Boomnum(c.x,c.y)!=0) { map[c.x][c.y]=(Boomnum(c.x,c.y)+48); continue; } else { map[c.x][c.y]='x'; if((c.x-1>=0)&&(c.y-1>=0)&&(map[c.x-1][c.y-1]==' ')&&(slect[c.x-1][c.y-1]==0)) { d.x=c.x-1; d.y=c.y-1; dui.push(d); slect[d.x][d.y]=1; } if((c.x-1>=0)&&(c.y-0>=0)&&(map[c.x-1][c.y]==' ')&&(slect[c.x-1][c.y]==0)) { d.x=c.x-1; d.y=c.y-0; dui.push(d); slect[d.x][d.y]=1; } if((c.x-1>=0)&&(c.y+1<B)&&(map[c.x-1][c.y+1]==' ')&&(slect[c.x-1][c.y+1]==0)) { d.x=c.x-1; d.y=c.y+1; dui.push(d); slect[d.x][d.y]=1; } if((c.x-0>=0)&&(c.y-1>=0)&&(map[c.x][c.y-1]==' ')&&(slect[c.x][c.y-1]==0)) { d.x=c.x-0; d.y=c.y-1; dui.push(d); slect[d.x][d.y]=1; } if((c.x-0>=0)&&(c.y+1<B)&&(map[c.x][c.y+1]==' ')&&(slect[c.x][c.y+1]==0)) { d.x=c.x-0; d.y=c.y+1; dui.push(d); slect[d.x][d.y]=1; } if((c.x+1<A)&&(c.y-1>=0)&&(map[c.x+1][c.y-1]==' ')&&(slect[c.x+1][c.y-1]==0)) { d.x=c.x+1; d.y=c.y-1; dui.push(d); slect[d.x][d.y]=1; } if((c.x+1<A)&&(c.y-0>=0)&&(map[c.x+1][c.y]==' ')&&(slect[c.x+1][c.y]==0)) { d.x=c.x+1; d.y=c.y-0; dui.push(d); slect[d.x][d.y]=1; } if((c.x+1<A)&&(c.y+1<B)&&(map[c.x+1][c.y+1]==' ')&&(slect[c.x+1][c.y+1]==0)) { d.x=c.x+1; d.y=c.y+1; dui.push(d); slect[d.x][d.y]=1; } } } } int main() { freopen("排名.txt","r",stdin); Relife: //重玩处 HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄 CONSOLE_SCREEN_BUFFER_INFO csbi; //定义窗口缓冲区信息结构体 GetConsoleScreenBufferInfo(handle_out, &csbi); Hide(); Beginning(); a=GetTickCount(); while(1) { if(kbhit()!=0) { spare=getch(); if((spare!=(-32))&&(spare!=13)&&(spare!=' ')) continue; if(spare==13) { if(mode%2==0) { if(map[floatx][floaty]=='@'&&flag[floatx][floaty]==0) { break; game=0; } if(flag[floatx][floaty]==1) continue; Open(); position(0,0); SetConsoleTextAttribute(handle_out, FORE_GREEN); for(int i=0; i<A; i++) { for(int j=0; j<B; j++) Lump(i,j); printf("\n"); } position(floaty*2,floatx); SetConsoleTextAttribute(handle_out, FORE_BLUE); Lump(floatx,floaty); } else { if(map[floatx][floaty]=='x'||(map[floatx][floaty]>'0'&&map[floatx][floaty]<'9')) continue; if(flag[floatx][floaty]==0) { flagnum++; flag[floatx][floaty]=1; position(floaty*2,floatx); SetConsoleTextAttribute(handle_out, FORE_BLUE); Lump(floatx,floaty); } else { flagnum--; flag[floatx][floaty]=0; position(floaty*2,floatx); SetConsoleTextAttribute(handle_out, FORE_BLUE); Lump(floatx,floaty); } } } if(spare==' ') Mode(); if(spare==-32) { news=getch(); Move(); } for(int i=0; i<A; i++) for(int j=0; j<B; j++) if(map[i][j]=='x'||(map[i][j]>'0'&&map[i][j]<'9')) game++; if(game==A*B-C+1) break; else game=1; SetConsoleTextAttribute(handle_out, FORE_RED); position(44,5); printf("剩余雷数:%d ",C-flagnum); } else Sleep(10); b=GetTickCount(); SetConsoleTextAttribute(handle_out, FORE_RED); position(44,7); printf("用时:"); //用时 if((b-a)/60000<10) printf("0"); printf("%d:",(b-a)/60000); if(((b-a)/1000)%60<10) printf("0"); printf("%d:",((b-a)/1000)%60); if(((b-a)/10)%100<10) printf("0"); printf("%d",((b-a)/10)%100); } SetConsoleTextAttribute(handle_out, FORE_RED); position(5,5); if(game==1) printf("游戏结束!————制作者:小小阁楼"); else printf("恭喜通关!大吉大利————制作者:小小阁楼"); position(5,8); printf("任意键重玩"); scanf("%c%c",&spare,&spare); system("cls"); position(0,0); goto Relife; }
C++小游戏(4):做最后的胜利者
今天给大家带来有我原创的游戏作品,本人技术不精,如果有什么运行问题还请大家指出。
话不多说,我们直接来看代码:#include<iostream> #include<cstdlib> #include<ctime> #include<cstring> #include<windows.h> using namespace std; int i,H[3],S[3],K[3],p=1,Y,C; string P[3]; bool game=1; void a(int i) { for (; i; i--); } void help() { printf("杀手:\n生命值:100\n技能点:5\nkill:3\n"); printf("医生:\n生命值:75\n技能点:7\nkill:2\n"); printf("法师:\n生命值:144\n技能点:3\nkill:1\n"); cin>>i; } void killer() { P[p]+="杀手"; H[p]=100; S[p]=5; K[p]=3; } void doctor() { P[p]+="医生"; H[p]=75; S[p]=7; K[p]=2; } void engineer() { P[p]+="法师"; H[p]=144; S[p]=3; K[p]=1; } void e(int j) { if (j==2&&S[Y]>=2) { int w=rand()%2; if (Y==1) printf("你使用奖励\n"); else printf("电脑使用奖励\n"); K[Y]+=w; printf("杀人数+%d",w); w=rand()%5-1; w=int(1.2*(K[Y]+w)); H[C]-=w; if (H[C]<=0) game=0; if (Y==1) printf("你杀了电脑 "); else printf("你被电脑杀了 "); cout<<w; if (Y==1) printf("\n"); S[Y]-=2; } } void k(int j) { if (j==2&&S[Y]>=2) { if (Y==1) printf("你 使用奖励\n"); else printf("电脑 使用奖励\n"); int w=rand()%4+1; H[C]-=int(1.5*K[Y]+w); if (H[C]<=0) game=0; if (Y==1) printf("杀 "); else printf("你被电脑杀了 "); cout<<int(1.5*K[Y]+w); if (Y==1) printf("\n"); S[Y]-=2; } } void d(int j) { if (j==2&&S[Y]>=2) { if (Y==1) printf("你 使用奖励\n"); else printf("电脑 使用奖励\n"); int w=rand()%5; H[Y]+=K[Y]+w; if (Y==1) printf("你的生命值+"); else printf("电脑的生命值+%d",K[Y]+w); if (Y==1) printf("\n"); S[Y]-=2; } } void play() { system("cls"); printf("开始游戏!!!!!!!!!!!!!!!!"); Sleep(30); system("cls"); int r=1,j; // bool game=1; while (game) { Y=1; C=2; printf("回合%d\n",r); Sleep(3000); cout<<"The 电脑 HP:"<<H[2]<<" SP:"<<S[2]<<" kill:"<<K[2]<<"\t"<<P[2]; cout<<"\n\n你的生命:"<<H[1]<<" SP:"<<S[1]<<" kill:"<<K[1]<<"\t"<<P[1]; Sleep(3000); printf("\n你的选择:\n1.杀人(1技能点)\n2.奖励(2技能点)\n3.大杀特杀(5技能点)\n4.啥事都没(+1~3技能点)\n5.干哈(+0~2kill)\n6.尝试(3技能点)"); cin>>j; if (j==1&&S[Y]>0) { int w=rand()%5-1; S[Y]--; H[C]-=K[Y]+w; if (H[C]<=0) game=0; cout<<"你杀了电脑"<<K[Y]+w<<endl; } else { if (j==4) { int w=rand()%3+1; S[Y]+=w; cout<<"你的 技能点+"<<w<<endl; } else { if (j==5) { int w=rand()%3; K[Y]+=w; cout<<"你的杀人数+"<<w<<endl; } else { if (P[Y]=="杀手") k(j); if (P[Y]=="医生") d(j); if (P[Y]=="法师") e(j); } } } if (game) { j=rand()%6+1; C=1; Y=2; while (j!=1&&j!=2&&j!=4&&j!=5) j=rand()%6+1; if (j==1&&S[2]>1) { int w=rand()%5-1; S[2]--; H[1]-=K[2]+w; if (H[1]<=0) game=0; cout<<"你被电脑杀了"<<K[2]+w; } else { if (j==4) { int w=rand()%3+1; S[2]+=w; printf("电脑的技能点+%d",w); } else { if (j==5) { int w=rand()%3; K[2]+=w; printf("电脑杀人数+%d",w); } else { if (P[Y]=="杀手") k(j); if (P[Y]=="医生") d(j); if (P[Y]=="法师") e(j); } } } if (game) Sleep(3000); } r++; system("cls"); } } int main() { srand((unsigned)time(NULL)); printf("欢迎来到游戏!!!!!!!!!!!!\n"); Sleep(30); system("cls"); printf("请选择:\n1.杀手\n2.医生\n3.法师\n4.帮助"); cin>>i; if (i==4) help(); printf("你的选择"); if (i==1) killer(); if (i==2) doctor(); if (i==3) engineer(); cout<<P[p]<<endl; i=rand()%3+1; p++; printf("电脑的选择"); if (i==1) killer(); if (i==2) doctor(); if (i==3) engineer(); cout<<P[p]<<endl; system("pause"); play(); if (H[1]<=0) printf("你输了~~~~~~~~~~~~~~~~~"); else printf("你赢了!!!!!!!!!!!!!!!!!!!"); return 0; }
C++小游戏(5):地下城1.0
游戏游玩说明:选择去地下城战斗时输入AWSD来控制角色行动。
#include<bits/stdc++.h> #include<cstdlib> #include<windows.h> #include<conio.h> #include<string> using namespace std; char a[14][100]= {"| S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血|", "| |", "| |S-R-X|-H--M-S-R-S-S-H-M-X---| |-X|-S--H-| |", "| M | | |-S|R--| | | |", "| | |-M--X--|H-R-| |-S-| | |-M--H--| |", "| S--R--| | |--M-R| |-S|-X-| |--@ |", "| O0-|-----|R-M-S--|R-M-|--X--|S-S-M-|X-|-R-|-H-M-M---| |", "| M--S|-|-X-R---| |-|S-H| | | | | |", "| S | | | | |-X-|-M-|-H-|-MH-| |", "| H |-S--R-|-S--X-R--|-S-M--H-| | | |", "| X | | |H-|X-H-H-M-| |", "| R--M|S---H---M--M-X-|-S-M-R--S|-M-H| |", "| |"}; char b[14][100]= {"| S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血|", "| |", "| |S-R-X|-H--M-S-R-S-S-H-M-X---| |-X|-S--H-| |", "| M | | |-S|R--| | | |", "| | |-M--X--|H-R-| |-S-| | |-M--H--| |", "| S--R--| | |--M-R| |-S|-X-| M--@ |", "| O0-|-----|R-M-S--|R-M-|--X--|S-S-M-|X-|-R-|-H-M-M-M-| |", "| M--S|-|-X-R---| |-|S-H| | | | | |", "| S | | | | |-X-|-M-|-H-|-MH-| |", "| H |-S--R-|-S--X-R--|-S-M--H-| | | |", "| X | | |H-|X-H-H-M-| |", "| R--M|S---H---M--M-X-|-S-M-R--S|-M-H| |", "| |"}; int c; int shang_hai=5; int sheng_ming=5; int sheng_ming_zhi=5; int jb=0; string xing_ming; int l,j; void game_2(); void player_zi_liao(); void player(); void shop(); void zi_mu_1(); void q(); void game_1(); void s_1(); void shi_bai(); void da_guai(); void xiao_guai(); void xiao_ziyuan(); void da_ziyuan(); void hui_xue(); void sheng_li(); //S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血 void sheng_li() { q(); cout<<"恭喜你,通关了!\n"; cout<<"下次更新 英雄 技能 道具 更多战斗系统 更多武器和防具 任务系统 经验与等级 材料(合成神器)....提前预告:下个版本 小镇2.0新的危机//原创作者:小小阁楼\n"; system("pause"); } void hui_xue() { q(); if(sheng_ming<sheng_ming_zhi) { sheng_ming++; cout<<"生命值加1"; } else { cout<<"生命值已满,回不了血"; } Sleep(1000); q(); } void xiao_ziyuan() { q(); cout<<"恭喜你获得 金币+2"; jb+=2; Sleep(1000); q(); } void da_ziyuan() { q(); cout<<"恭喜你获得 金币+5"; jb+=5; Sleep(1000); q(); } void da_guai() { q(); int bguai_xue; cout<<"即将跟大怪物战斗\n"; bguai_xue=12; while(1) { if(sheng_ming<=0) { cout<<"你被大怪打死了"; Sleep(1000); q(); break; } if(bguai_xue<=0) { cout<<"你打败了大怪"; Sleep(1000); q(); break; } cout<<"\n1.攻击 2.防御(暂时获得1血)\n"; cout<<"请输入:"; cin>>c; if(c==1) { bguai_xue-=shang_hai; cout<<"\n成功造成攻击\n"; Sleep(500); cout<<"你受到伤害*5"; sheng_ming-=5; } if(c==2) { sheng_ming++; sheng_ming-=5; } cout<<"\n你的生命:"<<sheng_ming; cout<<"\n怪物的生命:"<<bguai_xue; } } void xiao_guai() { q(); int sguai_xue; cout<<"即将跟小怪物战斗\n"; sguai_xue=6; while(1) { if(sheng_ming<=0) { cout<<"你被小怪打死了"; Sleep(1000); q(); break; } if(sguai_xue<=0) { cout<<"你打败了小怪"; Sleep(1000); q(); break; } cout<<"\n1.攻击 2.防御(暂时获得1血)\n"; cout<<"请输入:"; cin>>c; if(c==1) { sguai_xue-=shang_hai; cout<<"\n成功造成攻击\n"; Sleep(500); cout<<"你受到伤害*5"; sheng_ming-=3; } if(c==2) { sheng_ming++; sheng_ming-=3; } cout<<"\n你的生命:"<<sheng_ming; cout<<"\n怪物的生命:"<<sguai_xue; } } void s_1() { cout<<"\t"; cout<<"小镇"; Sleep(500); cout<<"1.0"; Sleep(500); cout<<"地下城"; Sleep(1000); q(); zi_mu_1(); } void player_zi_liao() { q(); cout<<"\n 名字:"<<xing_ming<<endl; cout<<" 金币:"<<jb<<endl; cout<<" 伤害:"<<shang_hai<<endl; cout<<" 生命:"<<sheng_ming<<endl; Sleep(2000); game_1(); } void player() { q(); cout<<"勇士,请输入你的姓名:"; cin>>xing_ming; game_1(); } void q() { system("cls"); } void zi_mu_1() { cout<<"小镇的资源一天天流逝,直到今天,资源严重缺乏,你身为勇士,不愿看到大家一个一个被饿死,决定去地下城闯一闯\n"; system("pause"); q(); player(); } void game_1() { q(); cout<<"\n"; cout<<"\t\t小镇\n\n"; cout<<"\t1.去地下城 2.铁匠铺 3.个人资料 4.查看下个版本更新内容 \n"; cout<<"你选择:"; cin>>l; if(l==2) { shop(); } if(l==3) { player_zi_liao(); } if(l==1) { game_2(); } if(l==4) { cout<<"下次更新 英雄 技能 道具 更多战斗系统 更多武器和防具 任务系统 经验与等级 材料(合成神器)....提前预告:下个版本 小镇2.0新的危机 //游戏原创作者:小小阁楼\n"; system("pause"); game_1(); } } void shi_bai() { q(); cout<<"你死亡了(装备不掉落)"; Sleep(1000); q(); game_1(); } void game_2() { q(); int i,k; for(i=0;i<14;i++) for(k=0;k<100;k++) { a[i][k]=b[i][k]; } int x=6,y=5; for(i=0; i<=12; i++) cout<<a[i]<<endl; char ch; while(1) { if(sheng_ming<=0) { shi_bai(); } ch=getch(); if(ch=='w')//S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血 { if(a[x-1][y]=='-'||a[x-1][y]=='|'||a[x-1][y]=='R'||a[x-1][y]=='S'||a[x-1][y]=='M'||a[x-1][y]=='H'||a[x-1][y]=='X') { if(a[x-1][y]=='H') { q(); da_ziyuan(); q(); } if(a[x-1][y]=='R') { q(); xiao_ziyuan(); q(); } if(a[x-1][y]=='S') { q(); xiao_guai(); q(); } if(a[x-1][y]=='M') { q(); da_guai(); q(); } if(a[x-1][y]=='X') { q(); hui_xue(); q(); } if(a[x+1][y]!=' '||a[x-1][y]!=' ') { a[x][y]='|'; } else { a[x][y]='-'; } x--; a[x][y]='0'; q(); for(i=0; i<=12; i++) cout<<a[i]<<endl; } } if(ch=='s')//S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血 { if(a[x+1][y]=='-'||a[x+1][y]=='|'||a[x+1][y]=='R'||a[x+1][y]=='S'||a[x+1][y]=='M'||a[x+1][y]=='H'||a[x+1][y]=='X') { if(a[x+1][y]=='H') { q(); da_ziyuan(); q(); } if(a[x+1][y]=='R') { q(); xiao_ziyuan(); q(); } if(a[x+1][y]=='S') { q(); xiao_guai(); q(); } if(a[x+1][y]=='M') { q(); da_guai(); q(); } if(a[x+1][y]=='X') { q(); hui_xue(); q(); } if(a[x+1][y]!=' '||a[x-1][y]!=' ') { a[x][y]='|'; } else { a[x][y]='-'; } x++; a[x][y]='0'; q(); for(i=0; i<=12; i++) cout<<a[i]<<endl; } } if(ch=='a')//S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血 { if(a[x][y-1]=='-'||a[x][y-1]=='|'||a[x][y-1]=='R'||a[x][y-1]=='S'||a[x][y-1]=='M'||a[x][y-1]=='H'||a[x][y-1]=='X') { if(a[x][y-1]=='H') { q(); da_ziyuan(); q(); } if(a[x][y-1]=='R') { q(); xiao_ziyuan(); q(); } if(a[x][y-1]=='S') { q(); xiao_guai(); q(); } if(a[x][y-1]=='M') { q(); da_guai(); q(); } if(a[x][y-1]=='X') { q(); hui_xue(); q(); } if(a[x][y+1]!=' '||a[x][y-1]!=' ') { a[x][y]='-'; } else { a[x][y]='|'; } y--; a[x][y]='0'; q(); for(i=0; i<=12; i++) cout<<a[i]<<endl; } } if(ch=='d')//S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血 { if(a[x][y+1]=='-'||a[x][y+1]=='|'||a[x][y+1]=='R'||a[x][y+1]=='S'||a[x][y+1]=='M'||a[x][y+1]=='H'||a[x][y+1]=='X'||a[x][y+1]=='@') { if(a[x][y+1]=='H') { q(); da_ziyuan(); q(); } if(a[x][y+1]=='@') { q(); sheng_li(); break; } if(a[x][y+1]=='R') { q(); xiao_ziyuan(); q(); } if(a[x][y+1]=='S') { q(); xiao_guai(); q(); } if(a[x][y+1]=='M') { q(); da_guai(); q(); } if(a[x][y+1]=='X') { q(); hui_xue(); q(); } if(a[x][y+1]!=' '||a[x][y+1]!=' ') { a[x][y]='-'; } else { a[x][y]='|'; } y++; a[x][y]='0'; q(); for(i=0; i<=12; i++) cout<<a[i]<<endl; } } } } void shop() { q(); cout<<"欢迎光临!\n"; cout<<"请问你需要什么帮助? //更多武器敬请期待//(注意:伤害和生命值是=关系,不是+的关系,比如你现在伤害是5,买了桃木剑是把伤害变为10,而不是加10)\n"; cout<<"1.桃木剑 10伤害 20金币\n"; cout<<"2.铁剑 15伤害 30金币\n"; cout<<"3.黄金剑 30伤害 40金币\n"; cout<<"4.钻石剑 40伤害 50金币\n"; cout<<"5.x光剑 50伤害 100金币\n"; cout<<"6.皮革甲 10生命 20金币\n"; cout<<"7.铁甲 15生命 30金币\n"; cout<<"8.黄金甲 30生命 40金币\n"; cout<<"9.钻石甲 40生命 50金币\n"; cout<<"10.激光披风 50生命 100金币\n"; cout<<"11.返回\n"; cout<<"请输入:"; cin>>j; if(j==1||j==6) { if(jb>=20) { jb-=20; if(j==1) shang_hai=10; else { sheng_ming=10; sheng_ming_zhi=10; } game_1(); } else cout<<"金币不够,继续加油"; game_1(); } if(j==2||j==7) { if(jb>=30) { jb-=20; if(j==2) shang_hai=15; else { sheng_ming=15; sheng_ming_zhi=15; } game_1(); } else cout<<"金币不够,继续加油"; game_1(); } if(j==3||j==8) { if(jb>=40) { jb-=40; if(j==3) shang_hai=30; else { sheng_ming=30; sheng_ming_zhi=30; } game_1(); } else cout<<"金币不够,继续加油"; game_1(); } if(j==4||j==9) { if(jb>=50) { jb-=50; if(j==4) shang_hai=40; else { sheng_ming=40; sheng_ming_zhi=40; } game_1(); } else cout<<"金币不够,继续加油"; game_1(); } if(j==5||j==10) { if(jb>=100) { jb-=100; if(j==5) shang_hai=50; else { sheng_ming=50; sheng_ming_zhi=50; } game_1(); } else cout<<"金币不够,继续加油"; game_1(); } if(j==11) { game_1(); } } int main() { system("title 小镇1.0地下城"); s_1(); return 0; }
-
c++小游戏..
2016-05-31 09:54:19c++小游戏.. -
c++小游戏 走迷宫
2020-08-10 18:08:35c++小游戏 走迷宫 最近做了一个走迷宫,自我感觉不错。目前制作了10张地图,游玩前需先仔细阅读帮助,不然会无从下手哦!!!查看方法:运行程序,然后按h键。代码如下: #include<iostream> #include<...c++小游戏 走迷宫
最近做了一个走迷宫,自我感觉不错。目前制作了10张地图,游玩前需先仔细阅读帮助,不然会无从下手哦!!!查看方法:运行程序,然后按h键。代码如下:
#include<iostream> #include<windows.h> #include"GotoXY.h" #include <conio.h> #include <stdlib.h> #include <time.h> using namespace std; void help(); void migong(); void m(); void help() { char ch2; system("cls"); cout<<"操作说明:"<<endl; cout<<endl; cout<<"移动说明:"<<endl; cout<<"w-向上 s-向下 a-向左 d-向右"<<endl; cout<<endl; cout<<"标识说明:"<<endl; cout<<"&-炸药 @-玩家 #-墙 $-钥匙 ^-地刺 %-传送门 0-可以被炸药炸开的墙"<<endl; cout<<endl; cout<<"操作说明:"<<endl; cout<<"x-爆破(需要炸药) 移动至物品上方-捡起物品 拥有钥匙后接近传送门附近-传送(按任意键继续)"<<endl; cout<<endl; cout<<"注意事项:"<<endl; cout<<"踩到地刺会s哦,请小心"<<endl; cout<<"按任意键返回"<<endl; ch2=_getch(); m(); } void migong() { system("cls"); char ch; srand(time(NULL)); int k; int z=0; int key=0; int zx[100]; int zy[100]; int gq=0; GotoXY(60,5); cout<<"TNT x 0"; while (1) { int map[10][6][10]={ { {1,1,1,1,1,1,1,1,1,1}, {1,0,3,0,4,0,1,1,0,1}, {1,0,0,0,0,1,1,1,2,1}, {1,0,0,0,0,1,1,1,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,1,0,2,1}, {1,0,1,0,1,1,1,0,0,1}, {1,0,1,0,0,0,0,0,0,1}, {1,3,1,0,0,0,0,4,0,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,2,0,1}, {1,0,0,3,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,6,1}, {1,0,0,5,0,0,0,6,4,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,3,1,0,0,0,1,7,4,1}, {1,0,1,0,1,0,1,0,0,1}, {1,0,1,0,1,2,1,0,7,1}, {1,0,0,0,1,0,0,0,7,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,1,2,1,1,0,0,0,1,1}, {1,1,0,1,1,0,1,0,1,1}, {1,0,0,0,0,0,1,0,1,1}, {1,3,1,1,1,1,1,0,4,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,2,1,1}, {1,6,6,6,6,0,1,0,1,1}, {1,6,3,5,6,0,1,0,0,1}, {1,6,6,6,6,0,0,0,4,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,5,0,0,0,0,0,3,0,1}, {1,6,6,6,0,0,0,0,0,1}, {1,6,2,6,0,0,0,0,0,1}, {1,6,6,6,0,0,0,0,4,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,2,6,0,0,0,0,6,4,1}, {1,7,6,0,0,0,0,6,5,1}, {1,6,6,0,6,6,6,6,6,1}, {1,0,0,0,6,3,5,0,0,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,1,1,0,0,0,1}, {1,2,0,0,7,7,0,0,3,1}, {1,0,0,0,7,7,0,0,4,1}, {1,0,0,0,0,0,0,1,0,1}, {1,1,1,1,1,1,1,1,1,1} }, { {1,1,1,1,1,1,1,1,1,1}, {1,7,7,2,0,0,0,7,7,1}, {1,5,7,7,0,0,7,7,5,1}, {1,5,7,7,0,0,7,7,5,1}, {1,7,3,0,0,0,0,4,7,1}, {1,1,1,1,1,1,1,1,1,1} } }; k=rand()%10; while (1) { int e=1; int keyx,keyy; int x; int y; int dx; int dy; GotoXY(0,0); for (int i=0;i<6;i++) { for (int j=0;j<10;j++) { if (map[k][i][j]==1) { cout<<"#"; } if(map[k][i][j]==0) { cout<<" "; } if(map[k][i][j]==2) { cout<<"$"; keyx=i; keyy=j; } if (map[k][i][j]==4) { cout<<"%"; dx=i; dy=j; } if (map[k][i][j]==3) { cout<<"@"; x=i; y=j; } if (map[k][i][j]==5) { cout<<"&"; zx[e]=i; zy[e]=j; e++; } if (map[k][i][j]==6) { cout<<"O"; } if (map[k][i][j]==7) { cout<<"^"; } } cout<<endl; } if(x==keyx&&y==keyy) { key=1; GotoXY(60,4); cout<<"YOU GET THE KEY!!! "; } else if (x==dx-1&&y==dy||x==dx+1&&y==dy||x==dx&&y==dy+1||x==dx&&y==dy-1) { if (key==1) { GotoXY(60,4); cout<<"YOU WIN!!! <<<按任意键继续>>> "; ch=_getch(); key=0; break; } else { GotoXY(60,4); cout<<"NO KEY!!! "; } } for (int i=1;i<=5;i++) { if (x==zx[i]&&y==zy[i]) { z+=1; zx[i]=100; zy[i]=100; GotoXY(60,4); cout<<"YOU GET A BAG OF TNT!!! "; GotoXY(66,5); cout<<z; } } GotoXY(60,3); cout<<"第"<<gq<<"层" ; GotoXY(0,6); ch=_getch(); switch (ch) { case 'w': if (map[k][x-1][y]==1||map[k][x-1][y]==4||map[k][x-1][y]==6) { break; } else if (map[k][x-1][y]==7) { GotoXY(y,x-1); cout<<"@"; GotoXY(y,x); cout<<" "; GotoXY(60,4); cout<<"YOU LOSE!!! "; ch=_getch(); system("cls"); m(); } else { map[k][x-1][y]=3; map[k][x][y]=0; } break; case 's': if (map[k][x+1][y]==1||map[k][x+1][y]==4||map[k][x+1][y]==6) { break; } else if (map[k][x+1][y]==7) { GotoXY(y,x+1); cout<<"@"; GotoXY(y,x); cout<<" "; GotoXY(60,4); cout<<"YOU LOSE!!! "; ch=_getch(); system("cls"); m(); } else { map[k][x][y]=0; map[k][x+1][y]=3; } break; case 'a': if (map[k][x][y-1]==1||map[k][x][y-1]==4||map[k][x][y-1]==6) { break; } else if (map[k][x][y-1]==7) { GotoXY(y-1,x); cout<<"@"; GotoXY(y,x); cout<<" "; GotoXY(60,4); cout<<"YOU LOSE!!! "; ch=_getch(); system("cls"); m(); } else { map[k][x][y]=0; map[k][x][y-1]=3; } break; case 'd': if (map[k][x][y+1]==1||map[k][x][y+1]==4||map[k][x][y+1]==6) { break; } else if (map[k][x][y+1]==7) { GotoXY(y+1,x); cout<<"@"; GotoXY(y,x); cout<<" "; GotoXY(60,4); cout<<"YOU LOSE!!! "; ch=_getch(); system("cls"); m(); } else { map[k][x][y]=0; map[k][x][y+1]=3; } break; case 'x': if (z>0) { z--; GotoXY(66,5); cout<<z<<" "; for (int m=x-1;m<=x+1;m++) { for (int d=y-1;d<=y+1;d++) { if (map[k][m][d]==6) { map[k][m][d]=0; } } } } else { GotoXY(60,4); cout<<"YOU DON'T HAVE ANY TNT!!! "; } break; } } GotoXY(0,7); gq++; key=0; } } void m() { system("cls"); char ch1; system("title 迷宫-作者S_JH330206"); cout<<" 迷宫游戏"<<endl; cout<<"----------------------------------------------------------------"<<endl; cout<<endl; cout<<" [h]帮助"<<endl; cout<<" [m]游戏"<<endl; cout<<endl; cout<<"----------------------------------------------------------------"<<endl; ch1=_getch(); if (ch1=='m') { migong(); } if (ch1=='h') { help(); } else { m(); } } int main() { m(); return 0; }
用到一个自定义头文件,请和上面的文件保存在同一文件夹。代码如下:
/* 使用前务必阅读以下几点: 1、c++光标坐标从左上角输出位置(0,0)开始,先列后行,如(10,5)为左数第十列, 从上往下数第五行; 2、使用方法:在任意函数(包括自定义函数)中皆可使用,格式为GotoXY(x,y); 3、要加上#include"GotoXY.h"(注意!!!是引号!!!不是<>!!!说的 就是->#include"GotoXY.h"); 4、 该文件后缀名为.h,擅自修改后果自负!!! 5、本文件作者S_JH330206,转载请声明!!! */ #include<iostream> #include<windows.h> void GotoXY(int x, int y) // 移动 { HANDLE hout; //屏幕尺寸 变量 COORD coord={x,y}; //光标坐标 变量 光标x标 光标y标 hout=GetStdHandle(STD_OUTPUT_HANDLE); //获得屏幕尺寸 SetConsoleCursorPosition(hout,coord); //移动光标 }
看完了,点个赞再走呗❀o( ̄▽ ̄)ブ❀
-
C++小游戏BrickHit实例代码
2020-08-28 00:29:18本文通过实例代码给大家介绍了C++小游戏BrickHit的相关资料,需要的朋友可以参考下 -
c++小游戏会更新下一个
2020-11-01 21:02:59http://noi.openjudge.cn/ch0103/可以在这上面的题目中的提问找c++小游戏 -
C++小游戏,打飞机代码
2016-06-13 20:43:41C++小游戏,打飞机代码 -
c++小游戏五子棋,带AI
2016-12-25 17:41:33c++小游戏五子棋,带AI,基于qt写的,代码浅显易懂,分为人人对战和人机对战两种模式 -
C++小游戏(3):扫雷.rar
2020-08-20 16:54:00今天给大家分享一个关于扫雷的C++小游戏,本人技术不精,游戏比较简单,如果有什么问题欢迎各位小伙伴们留言。 -
菜鸟前路---c/c++小游戏
2019-01-07 09:15:58翻到开学之初写的一些小游戏,陆续给大家发出来,也便提高新手们的编程兴趣。 (在Dev,codeblocks,VC上都能运行) #include<stdio.h> #include<time.h> #include<stdlib.h...神奇的c/c++
翻到开学之初写的一些小游戏,陆续给大家发出来,也便提高新手们的编程兴趣。(已详细注释)
几个对应头文件需要注意一下,但不必太过恐慌,因为,,,很多,用的时候找需要的即可(在Dev,codeblocks,VC上都能运行)
#include<stdio.h> #include<time.h> #include<stdlib.h> #include<conio.h> #include<windows.h> //下面Sleep()函数的头文件 #include<mmsystem.h> void menu() { printf(" *****************************\n"); printf(" *****************************\n"); printf(" ************1.play***********\n"); printf(" ************0.exit***********\n"); printf(" **********2.chakan***********\n"); printf(" *********3.qingkong**********\n"); printf(" *****************************\n"); printf("请选择: \n"); } void game() { system("cls"); system ( "color 33" ); //设置颜色 FILE *fp; if((fp=fopen("D:\\caishuziyou.txt","a+"))==NULL) { printf("open file error\n"); return ; } int rand_num=rand()%100; int tmp=0,t=0; while(1) { int flag=0; printf("请输入你要猜的数字:"); scanf("%d",&tmp); if(tmp>rand_num) { printf("猜大了!\n"); flag=0; } if(tmp<rand_num) { printf("猜小了!\n"); flag=0; } if(tmp==rand_num) { printf("正确!恭喜!\n"); printf("共用了%d次\n",t+1); FILE *fp; fp=fopen("D:\\caishuziyou.txt","w"); if(fp==NULL) { printf("create file failed\n"); return ; } fprintf(fp,"%d",t+1); fclose(fp); break; } if(flag==0) t++; printf(" 你再猜:\n"); } printf("\n按任意键返回目录"); getch(); } void menu2() { system("cls"); system ( "color B6" ); //设置颜色 printf("即将登陆系统!!!\n"); getch(); for(int t=3;t>=1;t--) { system("cls"); printf("%d",t); Sleep(700); system("cls"); } } void chakan() { system("cls"); system ( "color E0" ); //设置颜色 int t=0; FILE*fp; if((fp=fopen("D:\\caishuziyou.txt","r"))==NULL) { printf("can not to open the file!\n"); exit(0); } while(fscanf(fp,"%d",&t)!=EOF)//若不到文件结尾则继续 { printf("此玩家共进行了%d次\n",t); } printf("\n按任意键返回目录"); getch(); } void qk()//清空 { FILE *fp; system("cls"); //清屏函数,不管下面是否保存数据,每次输入新数据是屏幕上只能有此次的数据 system ( "color C0" ); //设置颜色 if((fp=fopen("D:\\caishuziyou.txt","w"))==NULL) { printf("open file error\n"); return; } fclose(fp); printf("\n按任意键返回!"); getch(); } int main() { int input=0; srand((unsigned)time(NULL)); do{ //while(1) //{ system("cls"); menu(); // printf("请选择:"); scanf("%d",&input); switch(input) { case 1: menu2(); game(); break; case 2: chakan(); break; case 3: qk(); break; case 0: exit(0); break; default:printf("输入错误!请重新输入!"); } //} }while(input); return 0; }
C语言里比较重要的知识也就文件、指针、链表、结构体和数组了,本文用的文件
希望大家能将知识化为己用。。。
-
C++小游戏(1):大乱斗.rar
2020-08-20 16:52:28今天,给大家推荐一个由我自己原创编写的一个C++小游戏,游戏玩法十分简单,适合单人游戏(消遣时间),游戏并没有贴图,能力有限,希望大家见谅。 -
C++小游戏(2):打飞机.rar
2020-08-20 16:53:09今天给大家带来一个由我创作的一个C++小游戏,这是一个打飞机的游戏,能力所限,画面比较简单,还请大家见谅。 -
c++小游戏会更新下一个(有点bug)
2020-11-04 21:08:42http://noi.openjudge.cn/ch0103/可以在这上面的题目中的提问找c++小游戏 -
关于c++小游戏扫雷
2019-05-03 10:45:06c++小游戏扫雷 从数学的思想来看: 扫雷可以划分为几个阶段: ①、建立一个N×N的矩阵bool型矩阵W,其中W(m,n)=1代表(m,n)处有雷。随机在N²个位置中选取M个位置将W置1(M为雷的数量)。 ②、定义一个N×N的矩阵bool... -
C++小游戏(4)做最后的胜利者.rar
2020-08-22 17:16:47今天给大家带来有我原创的游戏作品C++小游戏(4):做最后的胜利者有兴趣的小伙伴可以试试看,若有什么问题,欢迎大家留言 -
c++小游戏小镇1.0地下城
2020-12-31 19:39:17C++小游戏一.小游戏介绍二.小游戏代码三.后言 一.小游戏介绍 主角是一个出生在一个叫卡罗特的小镇,小镇的资源一天天流逝,直到今天,资源严重缺乏,主角作为勇士,不愿看到大家一个一个被饿死,决定去地下城闯一闯... -
局域网 象棋对战 小程序 源代码 C++ 小游戏
2011-03-13 16:03:18局域网 象棋对战 小程序 源代码 C++ 小游戏 代码简单,功能齐全,易于学习,易于更改 -
C++小游戏(3):扫雷
2020-08-19 17:15:07C++小游戏(3):扫雷 今天给大家分享一个关于扫雷的C++小游戏,本人技术不精,游戏比较简单,如果有什么问题欢迎各位小伙伴们留言。 话不多说,直接上代码: #include<stdio.h> #include<windows.h> #... -
C++小游戏-扫雷
2020-12-10 19:42:47目录前言一、扫雷游戏模式二、代码实现1.绘制地图场景2.鼠标点击3.递归4.初始化游戏5.main总结及运行 前言 提示:本文是基于easyX图形库实现的,还有部分功能可以添加,仅适合新手参考。 提示:以下是本篇文章正文... -
猜数字C++小游戏
2019-02-25 19:39:06一款猜数字游戏(C++),可以猜测1000-2000的数字,猜测次数为10次,根据猜测的次数计算得分,代码可以修改猜测数据范围和显示结果。 -
C++小游戏源码
2018-06-16 11:23:35该文件夹下只放了代码部分,至于resources部分由于较大且没有必要性,所以就不放了。 总共10多个类吧,大概每个h文件都是一个类,比如人物,天空盒,地图,准星,数据库。。。 部分代码源于网上教程。... -
C++小游戏数字炸弹
2021-01-01 08:58:09这个小游戏代码是我学了半年编程打出开的第一个小游戏代码,游戏内无void以及goto. 适合给新手当一个模板。 二.代码 #include<iostream> #include<ctime> #include<windows.h> using namespace ... -
C++小游戏(2):打飞机
2020-08-19 16:52:38C++小游戏(2):打飞机 今天给大家带来一个由我创作的一个C++小游戏,这是一个打飞机的游戏,能力所限,画面比较简单,还请大家见谅。 话不多说,直接上代码: #include<iostream> #include<windows.h> #... -
一个简单的c++小游戏——2048
2020-11-27 20:17:02一个简单的c++小游戏——2048 代码 话不多说,代码如下: #include<iostream> #include<vector> #include<ctime> #include<cstdlib> using namespace std; class Game_2048 { public: Game...
收藏数
4,547
精华内容
1,818
-
单元测试UnitTest+Pytest【Selenium3】
-
批量添加、修改、删除sql语句.docx
-
【Station OS】Media模式的开机引导
-
漂亮的后台管理学系统HTML.2015.zip
-
Unity游戏开发之数字华容道
-
【数据分析-随到随学】数据可视化
-
nltk读取自带英语停用词报错
-
彻底学会正则表达式
-
【Word】去掉“项目符号/编号”之后的制表符
-
HX3603_Programmers_Guide.pdf
-
无广告播放器推荐
-
servlet项目集成sentinel和SentinelResource注解中遇到的坑爹问题
-
VS 2019中使用qt
-
SPCE061A单片机车用智能数字仪表系统的设计.doc
-
多线程(一) 线程的四种创建方式
-
华泰证券:“融券通”是何阳谋?
-
Ubuntu使用Remastersys封装制作系统ISO镜像
-
week4
-
(新)备战2021软考网络工程师培训学习套餐
-
红酒市场分析.docx