小游戏的C++代码

作者&投稿:端固 (若有异议请与网页底部的电邮联系)
求C++小游戏源代码啊~~

以下是贪吃蛇源代码:

#include
#include
#include
#include
#include
#define N 21
void gotoxy(int x,int y)//位置函数
{
COORD pos;
pos.X=2*x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int a)//颜色函数
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void init(int apple[2])//初始化函数(初始化围墙、显示信息、苹果)
{
int i,j;//初始化围墙
int wall[N+2][N+2]={{0}};
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
wall[i][j]=1;
}
color(11);
for(i=0;i<N+2;i++)
{
for(j=0;j<N+2;j++)
{
if(wall[i][j])
cout<<"■";
else cout<<"□" ;
}
cout<<endl;
}
gotoxy(N+3,1);//显示信息
color(20);
cout<<"按 W S A D 移动方向"<<endl;
gotoxy(N+3,2);
color(20);
cout<<"按任意键暂停"<<endl;
gotoxy(N+3,3);
color(20);
cout<<"得分:"<<endl;
apple[0]=rand()%N+1;//苹果
apple[1]=rand()%N+1;
gotoxy(apple[0],apple[1]);
color(12);
cout<<"●"<<endl;
}
int main()
{
int i,j;
int** snake=NULL;
int apple[2];
int score=0;
int tail[2];
int len=3;
char ch='p';
srand((unsigned)time(NULL));
init(apple);
snake=(int**)realloc(snake,sizeof(int*)*len);
for(i=0;i<len;i++)
snake[i]=(int*)malloc(sizeof(int)*2);
for(i=0;i<len;i++)
{
snake[i][0]=N/2;
snake[i][1]=N/2+i;
gotoxy(snake[i][0],snake[i][1]);
color(14);
cout<<"★"<<endl;
}
while(1)//进入消息循环
{
tail[0]=snake[len-1][0];
tail[1]=snake[len-1][1];
gotoxy(tail[0],tail[1]);
color(11);
cout<<"■"<<endl;
for(i=len-1;i>0;i--)
{
snake[i][0]=snake[i-1][0];
snake[i][1]=snake[i-1][1];
gotoxy(snake[i][0],snake[i][1]);
color(14);
cout<<"★"<<endl;
}
if(kbhit())
{
gotoxy(0,N+2);
ch=getche();
}
switch(ch)
{
case 'w':snake[0][1]--;break;
case 's':snake[0][1]++;break;
case 'a':snake[0][0]--;break;
case 'd':snake[0][0]++;break;
default: break;
}
gotoxy(snake[0][0],snake[0][1]);
color(14);
cout<<"★"<<endl;
Sleep(abs(200-0.5*score));
if(snake[0][0]==apple[0]&&snake[0][1]==apple[1])//吃掉苹果后蛇分数加1,蛇长加1
{
score++;
len++;
snake=(int**)realloc(snake,sizeof(int*)*len);
snake[len-1]=(int*)malloc(sizeof(int)*2);
apple[0]=rand()%N+1;
apple[1]=rand()%N+1;
gotoxy(apple[0],apple[1]);
color(12);
cout<<"●"<<endl;
gotoxy(N+5,3);
color(20);
cout<<score<<endl;
}
if(snake[0][1]==0||snake[0][1]==N||snake[0][0]==0||snake[0][0]==N)//撞到围墙后失败
{
gotoxy(N/2,N/2);
color(30);
cout<<"失败!!!"<<endl;
for(i=0;i<len;i++)
free(snake[i]);
Sleep(INFINITE);
exit(0);
}
}
return 0;
}

使用语言:C++使用工具:vs2019

/*一个火柴人游戏,亲自验证,可运行*/
/*在编译时添加如下命令:-std=c++11,否则会编译错误*/
#include <cstdio>
#include <cstdlib>
#include <Windows.h>
#include <thread>
#include <conio.h>
using namespace std;
const unsigned char CTRL_KEY = 0XE0;
const unsigned char LEFT = 0X4B;
const unsigned char RIGHT = 0X4D;
const unsigned char DOWN = 0X50;
const unsigned char UP = 0X48;
int men2[2] = {0,0};
int women2[2]={10,10};
int Game();
void gotoxy( int x, int y ) //光标移动到(x,y)位置
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
int clean( int mm, int nn )
{
gotoxy ( mm, nn );
printf ( " " );
gotoxy ( mm,nn+1);
printf ( " " );
gotoxy ( mm,nn+2);
printf (" ");
}
int men( int x, int y )
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
gotoxy( x, y );
printf(" O");
gotoxy( x, y+1 );
printf("<H>");
gotoxy( x, y+2 );
printf("I I");
}
int women( int i, int j )
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
gotoxy( i+1,j );
printf(" O");
gotoxy( i+1,j+1 );
printf("<H>");
gotoxy( i,j+2 );
printf("/I I\\");
}
int m=10, n=10;
int x=0;int y=0;
int TorF()
{
if ( x == m && y == n ) return 1;
else return 0;
}
int womenmove()
{
int turn;
int YNbreak=0;
while( YNbreak == 0 )
{
YNbreaak = TorF();
turn=rand()%3;
clean( m, n );
if( m < x ) m++;
else m--;
if( m == x )
{
if( n < y ) n++;
else n--;
}
if ( m < 0 ) m = 0;
if ( m >= 75 ) m = 75;
if ( n < 0 ) n = 0;
if ( n >= 22 ) n = 22;
women( m,n );
women2[0]=m;
women2[1]=n;
Sleep(100);
}
system ( "cls" );
gotoxy ( 28, 10 );
printf ( "You died!!!\n" );
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
system ( "pause" );
exit(0);
return 0;
}
int menmove()
{
system( "cls" );
while (1)
{
switch( getch())
{
case UP:y--;break;
case DOWN:y++;break;
case LEFT:x--;break;
case RIGHT:x++;break;
}
system( "cls" );
if ( x < 0 ) x = 0;
if ( x > 77 ) x = 77;
if ( y < 0 ) y = 0;
if ( y > 22 ) y = 22;
men( x, y );
men2[0] = x;
men2[1] = y;
}
}
int Game()
{
women( 10, 10 );
men( 0, 0 );
int t = 0;
thread qq( womenmove );
menmove();
qq.join();
return 0;
}
int main()
{
system( "mode con cols=80 lines=25" );
printf ( "游戏开始后,随机按下一个键,唤醒你的蓝色小人.如果你被红色的老女人碰到了,那么你就死了\n" );
printf ( "方向键操控小人\n" );
system ( "pause" );
system ( "cls" );
Game();
return 0;
}
/*留下您的赞再拿走,谢谢!*/

/*===========================Program Description==========================*/
/*程序名称:game.c */
/*程序目的:打砖块游戏演示 */
/*written by :董大钿 */
/*========================================================================*/

#include "graphics.h"
#include "stdio.h"
#include "conio.h" /*所需的头文件*/

int on; /*声明具有开关作用的全局变量*/
static int score; /*声明静态的记分器变量*/

/* 定义开始界面函数*/

int open()
{
setviewport(100,100,500,380,1); /*设置图形窗口区域*/
setcolor(4); /*设置作图色*/
rectangle(0,0,399,279); /*以矩形填充所设的图形窗口区域*/
setfillstyle(SOLID_FILL,7); /*设置填充方式*/
floodfill(50,50,4); /*设置填充范围*/
setcolor(8);
settextstyle(0,0,9); /*文本字体设置*/
outtextxy(90,80,"BALL"); /*输出文本内容*/
settextstyle(0,0,1);
outtextxy(110,180,"version 1.0");
outtextxy(110,190,"made by ddt");
setcolor(128);
settextstyle(0,0,1);
outtextxy(120,240,"Press any key to continue......");
}

/*定义退出界面函数*/
int quitwindow()
{
char s[100]; /*声明用于存放字符串的数组*/
setviewport(100,150,540,420,1);
setcolor(YELLOW);
rectangle(0,0,439,279);
setfillstyle(SOLID_FILL,7);
floodfill(50,50,14);
setcolor(12);
settextstyle(0,0,8);
outtextxy(120,80,"End");
settextstyle(0,0,2);
outtextxy(120,200,"quit? Y/N");
sprintf(s,"Your score is:%d",score);/*格式化输出记分器的值*/
outtextxy(120,180,s);
on=1; /*初始化开关变量*/
}

/*主函数*/
main()
{
int gdriver,gmode;
gdriver=DETECT; /*设置图形适配器*/
gmode=VGA; /*设置图形模式*/
registerbgidriver(EGAVGA_driver); /*建立独立图形运行程序*/
initgraph(&gdriver,&gmode,""); /*图形系统初试化*/
setbkcolor(14);
open(); /*调用开始界面函数*/
getch(); /*暂停*/

while(1) /*此大循环体控制游戏的反复重新进行*/
{
int driver,mode,l=320,t=400,r,a,b,dl=5,n,x=200,y=400,r1=10,dx=-2,dy=-2;/*初始化小球相关参数*/
int left[100],top[100],right[100],bottom[100],i,j,k,off=1,m,num[100][100];/*方砖阵列相关参数*/
static int pp;
static int phrase; /*一系列起开关作用的变量*/
int oop=15;
pp=1;
score=0;
driver=DETECT;
mode=VGA;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
setbkcolor(10);
cleardevice(); /*图形状态下清屏*/
clearviewport(); /*清除现行图形窗口内容*/
b=t+6;
r=l+60;
setcolor(1);
rectangle(0,0,639,479);
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+2,t+2,4);

for(i=0,k=0;i<=6;i++) /*此循环绘制方砖阵列*/
{
top[i]=k;
bottom[i]=top[i]+20;
k=k+21;
oop--;
for(j=0,m=0;j<=7;j++)
{
left[j]=m;
right[j]=left[j]+80;
m=m+81;
setcolor(4);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,j+oop);
floodfill(left[j]+1,top[i]+1,4);
num[i][j]=pp++;
}
}

while(1) /*此循环控制整个动画*/
{
while(!kbhit())
{
x=x+dx; /*小球运动的圆心变量控制*/
y=y+dy;
if(x+r1>r||x+r1<r)
{ phrase=0;}
if((x-r1<=r||x+r1<=r)&&x+r1>=l)
{
if(y<t)
phrase=1;
if(y+r1>=t&&phrase==1)
{dy=-dy;y=t-1-r1;}
}

if(off==0)
continue;

for(i=0;i<=6;i++) /*此循环用于判断、控制方砖阵列的撞击、擦除*/

for(j=0;j<=7;j++)
{
if((x+r1<=right[j]&&x+r1>=left[j])||(x-r1<=right[j]&&x-r1>=left[j]))
{
if(( y-r1>top[i]&&y-r1<=bottom[i])||(y+r1>=top[i]&&y+r1<=bottom[i] ))
{
if(num[i][j]==0)
{continue; }
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dy=-dy;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
if((y+r1>=top[i]&&y+r1<=bottom[i])||(y-r1>=top[i]&&y-r1<=bottom[i]))
{
if((x+r1>=left[j]&&x+r1<right[j])||(x-r1<=right[j]&&x-r1>left[j]))
{
if(num[i][j]==0)
{ continue;}
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dx=-dx;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
}

if(x+r1>639) /*控制小球的弹射范围*/
{dx=-dx;x=638-r1;}
if(x<=r1)
{dx=-dx;x=r1+1;}
if(y+r1>=479)
{off=0;quitwindow();break;}
if(y<=r1)
{dy=-dy;y=r1+1;}
if(score==560)
{off=0;quitwindow();break;}
setcolor(6);
circle(x,y,r1);
setfillstyle(SOLID_FILL,14);
floodfill(x,y,6);
delay(1000);
setcolor(10);
circle(x,y,r1);
setfillstyle(SOLID_FILL,10);
floodfill(x,y,10);
}

a=getch();
setcolor(10);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,10);
floodfill(l+2,t+2,10);
if(a==77&&l<=565) /*键盘控制设定*/
{dl=20;l=l+dl;}
if(a==75&&l>=15)
{dl=-20;l=l+dl;}
if(a=='y'&&on==1)
break;
if(a=='n'&&on==1)
break;
if(a==27)
{quitwindow();off=0;}
r=l+60;
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+5,t+5,4);
delay(100);
}
if(a=='y'&&on==1) /*是否退出游戏*/
{break;}
if(a=='n'&&on==1)
{ continue;}
}
closegraph();

}

void panduan2()
{
if(win>=10){
out("已解锁全部游戏");
Sleep(2000);
abc=1;
win-=10;
}else{
out("权限不够");
Sleep(1000);
}
}
void waigua(){
printf("密码1:");
scanf("%d",&a);
printf("密码2:");
scanf("%d",&b);
c=a+b;
if(c==286){
score+=200;
printf("谁是学神?");
cout<<endl;
printf("1 .徐若宸");
cout<<endl;
printf("2 .文雅洁");
cout<<endl;
printf("3 .朱持正");
cout<<endl;
printf("4 .杨程程");
cout<<endl;
printf("5 .张紫涵");
cout<<endl;
printf("6 .石欣宇");
cout<<endl;
printf("7 .其他人");
cout<<endl;
printf("9 .你自己");
cout<<endl;
printf("10.这一题不适合我,退出");
cout<<endl;
scanf("%d",&d);
if(d==1||d==2||d==3){
out("你答对了,真棒");
Sleep(2000);
score+=500;
return;
}
if(d==4||d==5||d==6||d==7||d==8){
out("错了,减100毛爷爷");
Sleep(2000);
score-=100;
return;
}
if(d==9){
out("怎么可能?减200毛爷爷");
Sleep(2000);
score-=200;
return;
}
if(d==10){
out("拜拜,给你1个毛爷爷");
Sleep(2000);
score+=1;
return;
}
if(d>10){
out("调皮蛋,罚50毛爷爷");
Sleep(2000);
score-=50;
return;
}
}
else{
cout<<"你答错了!Sorry!O(∩_∩)O"<<endl;
Sleep(1000);
score=0;
return;
}
}
void chengfa()
{
int cv;
if(score<=0)
{
printf("惩罚开始");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSS5SSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
cout<<endl;
printf("刚刚多余的数字在第几行第几列");
scanf("%d",&cv);
int cvv;
cin >> cvv;
if(cv==6&&cvv==19)
{//6 19
score+=50;
lose=10000000;
screen();
}
else
{
chengfa();
system("cls");
}
}
}
void color()
{
out("你要什么字体颜色?");
cout<<endl;
out("黑色:按1");
cout<<endl;
out("蓝色:按2");
cout<<endl;
out("绿色:按3");
cout<<endl;
out("浅绿色:按4");
cout<<endl;
out("红色:按5");
cout<<endl;
out("紫色:按6");
cout<<endl;
out("黄色:按7");
cout<<endl;
out("白色:按8");
cout<<endl;
out("灰色:按9");
cout<<endl;
out("淡蓝色:按A");
cout<<endl;
out("淡绿色:按B");
cout<<endl;
out("淡浅绿色:按C");
cout<<endl;
out("淡红色:按D");
cout<<endl;
out("淡紫色:按E");
cout<<endl;
out("淡黄色:按F");
cout<<endl;
out("亮白色:按G");
cout<<endl;
char c;
cin>>c;
switch(c)
{
case '1':
system("color 0");
break;
case '2':
system("color 1");
break;
case '3':
system("color 2");
break;
case '4':
system("color 3");
break;
case '5':
system("color 4");
break;
case '6':
system("color 5");
break;
case '7':
system("color 6");
break;
case '8':
system("color 7");
break;
case '9':
system("color 8");
break;
case 'A':
system("color 9");
break;
case 'B':
system("color A");
break;
case 'C':
system("color B");
break;
case 'D':
system("color C");
break;
case 'E':
system("color D");
break;
case 'F':
system("color E");
break;
case 'G':
system("color F");
break;
default:
system("color");
break;
}
out("调颜色成功。");
}
void judge()
{
if(player[cishu]==1)
{
if(computer==2)
{
computer_lose();
}
if(computer==3)
{
player_lose();
}
if(computer==1)
{
tin();
}
}
if(player[cishu]==2)
{
if(computer==3)
{
computer_lose();
}
if(computer==1)
{
player_lose();
}
if(computer==2)
{
tin();
}
}
if(player[cishu]==3)
{
if(computer==1)
{
computer_lose();
}
if(computer==2)
{
player_lose();
}
if(computer==3)
{
tin();
}
}
}
void zhiliwenda()
{
system("cls");
system("color 9F");
cout<<"开始智力问答!"<<endl;
Sleep(1000);
for(int i=1;i<=10;i++)
timu(rand()%10);
tili+=5;
}
void timu(int in)
{
int input;
switch(in)
{
case 0:
{
out("0~31有几个数?");
cout<<endl;
cin>>input;
if(input==32)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("脑子有问题。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 1:
{
out("0,1,1,2,3,5,8,后面是什么?");
cout<<endl;
cin>>input;
if(input==13)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("sb。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 2:
{
out("9,61,52,63,94,后面是什么?");
cout<<endl;
cin>>input;
if(input==64)
{
out("被你给答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("6666666。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 3:
{
out("求7分之1的小数点后第1000位是多少。");
cout<<endl;
cin>>input;
if(input==8)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("这都不会。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 4:
{
out("求13分之1的小数点后第1000位是多少。");
cout<<endl;
cin>>input;
if(input==9)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("这都不会。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 5:
{
out("2^16=?");
cout<<endl;
cin>>input;
if(input==65536)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("这都不会。。。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 6:
{
out("一吨水多少钱?");
cout<<endl;
cin>>input;
if(input>=3&&input<=8)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("这都不会。666666666。。。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 7:
{
out("求你一天吃几碗饭。");
cout<<endl;
cin>>input;
if(input<=2)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("吃货!");
cout<<endl;
timu(rand()%10);
}
}
break;
case 8:
{
out("求标准钢琴有几个键。");
cout<<endl;
cin>>input;
if(input==88)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("这都不会。。。估计不弹钢琴。。。");
cout<<endl;
timu(rand()%10);
}
}
break;
case 9:
{
out("本游戏至少有多少行?");
cout<<endl;
cin>>input;
if(input>=600)
{
out("被你答对了,真是不可思议!");
cout<<endl;
return;
}
else
{
out("这都不会。");
cout<<endl;
timu(rand()%10);
}
}
break;
}
}
void screan()
{
while(1)
{
system("cls");
if(tili<=0)
{
out("体力为0,休息一会,马上回来!");
cout<<endl;
Sleep(2000);
int i,yushu;
for(i=1;i<=rand()%20;i++)
{
yushu=i%8;
switch(yushu)
{
case 0:
{
system("color 0F");
out("吃鸡三级头套装,限购10个哟!");
Sleep(2000);
system("cls");
break;
}
case 1:
{
system("color 3F");
out("我的世界头套100个,现在大促销,快来买哟!");
Sleep(2000);
system("cls");
break;
}
case 2:
{
system("color AF");
out("装逼专用机器,还送10年保修哟!");
Sleep(2000);
system("cls");
break;
}
case 3:
{
system("color BF");
out("吃鸡专用98k,800里外一枪爆头!");
Sleep(2000);
system("cls");
break;
}
case 4:
{
system("color AB");
out("王者10000000份外挂大放送,手快有手慢无!");
Sleep(2000);
system("cls");
break;
}
case 5:
{
system("color 0F");
out("Surface Pro 7笔记本电脑出售,抢购只在1秒间!");
Sleep(2000);
system("cls");
break;
}
case 6:
{
system("color 1F");
out("6666666,6666666,6666666,6666666");
Sleep(2000);
system("cls");
break;
}
}
}
zhiliwenda();
}
out("你现在有");
cout<<score;
out("张毛爷爷,");
cout<<meichao;
out("美元,");
cout<<tili;
out("点体力值,");
cout<<win;
out("次胜利,");
cout<<lose;
out("次失败,");
cout<<isvip;
out("张VIP卡,");
cout<<ismvp;
out("张MVP卡,");
cout<<xingyv;
out("信誉积分.");
cout<<endl;
out("现在,你可以有以下选择:");
cout<<endl;
out("1:人机大战");
cout<<endl;
out("2:购买道具");
cout<<endl;
out("3.游戏简介");
cout<<endl;
out("4.作者简介");
cout<<endl;
out("5:外挂");
cout<<endl;
out("6:调整设置");
cout<<endl;
out("7:玩玩小游戏");
cout<<endl;
out("8:新年快乐!");
int in;
cout<<endl;
cin>>in;
switch(in)
{
case 1:
fight();
screan();
system("cls");
break;
case 2:
store();
system("cls");
break;
case 3:
jianjei();
system("cls");
break;
case 4:
zuozhe();
system("cls");
break;
case 5:
waigua();
system("cls");
break;
case 6:
color();
system("cls");
case 7:
panduan();
system("cls");
break;
case 8:
newyear();
system("cls");
break;
default:
out("输错了,请重试。");
Sleep(1000);
}
}
}

使用语言:C++使用工具:vs2019



//低级版第五人格
#include <iostream>
#include <conio.h>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <cstring>
using namespace std;
int random(int a,int b){//产生a-b的随机数
return rand()%(b-a+1)+a;
}
void HideCursor(){//隐藏光标
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void gotoxy(int y,int x){//设置光标
COORD loc={x,y};
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out,loc);
}
void hang(int x,int y1,int y2,char ch){//填充 第x行 从y1->y2
gotoxy(x,y1);
while(y1<y2){
cout<<ch;
y1++;
gotoxy(x,y1);
}
}
void lie(int y,int x1,int x2,char ch){//填充 第y列 从x1->x2
gotoxy(x1,y);
while(x1<x2){
cout<<ch;
x1++;
gotoxy(x1,y);
}
}
void pause(){
gotoxy(11,72);
cout<<"暂停中...";
char c=getch();
while(c!='p')
c=getch();
gotoxy(11,72);
cout<<" ";
}
int move(int rw){
int x=1,y=0;//人物初始位置
int smz=2;
int enemy_x,enemy_y; //监管者位置
int rank=40000,enemy_flag=0;//监管者移动速度
int box_x[3],box_y[3];//道具
int box_num=1;
int lock_x[3],lock_y[3];//密码机
int lock_num[3]={0,0,0},j=0;
for(int i=1;i<=3;i++){
lock_x[i]=random(1,24);//随机密码机位置
lock_y[i]=random(1,34);
box_x[i]=random(1,24);//随机道具位置
box_y[i]=random(1,34);
}
gotoxy(x,y);
cout<<"->";
y+=1;
gotoxy(3,84);
cout<<box_num;
gotoxy(5,90);
for(int i=0;i<=2;i++){
cout<<lock_num[i]<<" ";
}
while(1){
enemy_flag=0;
enemy_x=random(1,24);//随机监管者初始位置
enemy_y=random(1,34);
while(1){
if(_kbhit()){
for(int i=16;i<=19;i++){
gotoxy(i,72);
cout<<" ";
}
gotoxy(3,84);
cout<<" ";
gotoxy(3,84);
cout<<box_num;
gotoxy(5,90);
for(int i=0;i<=2;i++){
cout<<" ";
}
gotoxy(5,90);
for(int i=0;i<=2;i++){
cout<<lock_num[i]<<" ";
}
char m=getch();
int x1=x,y1=y;
switch(m){
case 'a':y1--;break;
case 'd':y1++;break;
case 's':x1++;break;
case 'w':x1--;break;
case 'p':pause();
}
if(x1>=1&&x1<25&&y1>=1&&y1<35){
gotoxy(x,y*2);
cout<<".";
x=x1;
y=y1;
if(x==enemy_x&&y==enemy_y){//遇到监管者
break;
}else{
gotoxy(x,y*2);
cout<<"o";
}
if(x==24&&y==34){//出口
int doorLock,a;
if(j!=3){
doorLock=INT_MAX;
}else{
doorLock=lock_num[0]+lock_num[1]+lock_num[2];
}
while(1){
gotoxy(16,72);
cout<<"请将三个密码机的密码相加\n";
gotoxy(17,72);
cout<<"就可以打开大门,输入0继续寻找\n";
gotoxy(18,72);
cin>>a;
if(a==0){
break;
}else if(doorLock==a){
cout<<"密码正确";
return 0;
}else{
return 1;
}
}
}
for(int i=1;i<=3;i++){
if(lock_x[i]==x&&lock_y[i]==y){//遇到密码机
int lock_num1=random(1,100),lock_num2;
lock_x[i]=0;
lock_y[i]=0;
while(1){
gotoxy(16,72);
cout<<"试试输入频率接受密码~";
cin>>lock_num2;
gotoxy(17,72);
if(lock_num2>lock_num1){
cout<<"频率太高~\n";
}else if(lock_num2<lock_num1){
cout<<"频率太低~\n";
}else{
cout<<"频率正确,密码为"<<lock_num1<<"\n";
lock_num[j++]=lock_num1;
break;
}
}
Sleep(2000);
}
if(box_x[i]==x&&box_y[i]==y){//遇到道具
box_x[i]=0;
box_y[i]=0;
box_num++;
gotoxy(16,72);
switch(rw){
case 1:cout<<"拾取电池一个";break;
case 2:cout<<"拾取磨刀石一个";break;
case 3:cout<<"拾取镇定剂一个";break;
}
Sleep(2000);
}
}
}
}
//监管者移动
enemy_flag++;
if(enemy_flag==rank){
gotoxy(enemy_x,enemy_y*2);
cout<<" ";
if(x<enemy_x){
enemy_x--;
}else if(x>enemy_x){
enemy_x++;
}
if(y<enemy_y){
enemy_y--;
}else if(y>enemy_y){
enemy_y++;
}
gotoxy(enemy_x,enemy_y*2);
cout<<"*";
if(x==enemy_x&&y==enemy_y){//遇到监管者
break;
}
enemy_flag=0;
}
}
for(int i=16;i<=19;i++){
gotoxy(i,72);
cout<<" ";
}
gotoxy(x,y*2);
cout<<"x";
gotoxy(16,72);
cout<<"遭遇监管者!!!";
cout<<"\n";
gotoxy(17,72);
switch(rw){
case 1:{
cout<<"是否使用手电筒,y or n\n";
char c=getch();
if(c=='y'){
gotoxy(17,72);
if(box_num>0){
cout<<"监管者被晃晕,你快速逃离现场。\n";
box_num--;
break;
}else{
cout<<"手电筒发出微弱的光,你才意识到没电了\n";
}
}
}
case 2:
case 3:
smz--;
gotoxy(18,72);
cout<<"你无法进行任何抵抗,被监管者打伤,";
gotoxy(19,72);
cout<<"借监管者擦刀之际逃跑\n";
Sleep(1000);
break;
}
for(int i=26;i<=28;i++){
gotoxy(i,72);
hang(i,0,120,' ');
}
if(smz>0){
if(rw==3&&box_num>0){
gotoxy(26,2);
box_num--;
cout<<"监管者造成的伤害使你难以行动,你忍住剧痛,给自己注射了镇定剂。";
Sleep(3000);
}
if(rw==2&&box_num>0){
gotoxy(26,2);
box_num--;
cout<<"你因受伤太重而倒地,监管者将你抓起并放在狂欢之椅上\n";
cout<<"监管者离开了,你使用绿化剪剪断枷锁\n";
Sleep(3000);
}

}else{
int num=2;
gotoxy(26,2);
cout<<"你因受伤太重而倒地,监管者将你抓起并放在狂欢之椅上\n";
int m=random(1,4),n;
while(1){
cout<<"你可以尝试挣扎。前w后s左a右d\n";
char c=getch();
switch(c){
case 'w':n=1;break;
case 's':n=2;break;
case 'a':n=3;break;
case 'd':n=4;break;
}
if(m==n){
cout<<"你成功挣扎下椅,向远处跑去。\n";
smz++;
break;
}else{
cout<<"这个方向挣扎不开\n";
num--;
}
if(num==0){
cout<<"这个方向挣扎不开,你的挣扎引来了监管者,它冷笑着点击了加速按钮,看样子似乎想提";
cout<<"前将你送回庄园。椅子开始旋转。当椅子开始旋转,你才明白似乎只有两次机会。";
return 2;
}
}
}
}
}
int begin(){
int rw;//人物
//背景音乐
//PlaySound("bac1.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP);
gotoxy(2,40);
cout<<"第五人格(2D版)";
hang(4,0,100,'-');
cout<<"\n";
cout<<" 温馨提示:由于板子较大,请您耐心走路,";
cout<<"不要走到一半砸键盘哈~难度很低,基本上都可以逃生成功";
hang(6,0,100,'-');
cout<<"\n";
gotoxy(7,30);
cout<<"w s 选择,k 确定";
hang(8,0,100,'-');
cout<<"\n";
cout<<" 你睁开眼,发现自己身处一个诡异的庄园,远处身材高大面带诡异笑容的是监管者。\n";
cout<<" 监管者的诡异笑声让你清醒,你想起了你的身份,你的身份是\n";
cout<<" 1.慈善家 \n 2.园丁 \n 3.医生\n";
hang(14,5,100,'-');
cout<<"\n";
cout<<" 技能介绍:拥有手电筒,可以晃晕监管者";
hang(21,0,100,'-');
gotoxy(22,20);
cout<<"制作:张 力";
hang(23,0,100,'-');
int key=1;
gotoxy(10+key,6);
cout<<">>";
while(1){
if(_kbhit()){
char k=getch();
if(k=='s'){
gotoxy(10+key,6);
cout<<" ";
if(key<3){
key++;
}else{
key=1;
}
gotoxy(10+key,6);
cout<<">>";
}else if(k=='w'){
gotoxy(10+key,6);
cout<<" ";
if(key>1){
key--;
}else{
key=3;
}
gotoxy(10+key,6);
cout<<">>";
}else if(k=='k'){
rw=key;
break;
}
gotoxy(15,16);
if(key==1){
cout<<"拥有手电筒,可以晃晕监管者";
}else if(key==2){
cout<<"拥有锋利剪刀,可以剪开枷锁";
}else {
cout<<"拥有针剂,可以来回复生命值";
}
}
}

system("cls");
hang(0,0,112,'=');
lie(0,1,25,'|');
lie(1,1,25,'|');
lie(70,1,24,'|');
lie(110,1,25,'|');
lie(111,1,25,'|');
hang(15,71,110,'-');
hang(25,0,112,'=');
cout<<"\n";
gotoxy(26,2);
if(rw==1){
cout<<"你是一名慈善家。当然,这是假的,你的真实身份是一名小偷。";
cout<<"之所以建造一座孤儿院,是因为你最喜欢的园丁小姐是个孤儿。\n";
cout<<"前几天你收到了一封来信,信上说这个庄园里有大把的金子和园丁小姐,";
cout<<"于是你来到了这里并且迷失。现在你要赶快离开这 \n";
cout<<"你看见地上有一只手电,便抓起放入口袋,抬腿迈向恐惧之源\n";
}else if(rw==2){
cout<<"你是一名园丁,患有人格分裂症。几天前你收到了一封来信,信中邀请你来这个庄园,";
cout<<"说有一位医生小姐可以治好你的病。你见到了她,她人很好,";
cout<<"你也见到了你们孤儿院的赞助商:那位慈善家。可是现在,";
cout<<"他们在哪?管不了那么多了,你现在只想在人格分裂发作之前离开这里。";
cout<<"你看到地上有一把绿化剪,你捡起别在腰间,抬腿迈向恐惧之源\n";
}else if(rw==3){
cout<<"你是一名医生。几天前你收到了一封来信,邀请你来这个庄园为一位患有";
cout<<"人格分裂的园丁小姐治病。你见到了那位园丁小姐,她非常可爱,但现在,她在哪?";
cout<<"管不了这么多了,现在你要做的是赶快离开这。";
cout<<"你瞥见地上有一支注射器和一瓶镇定剂,你拿起放入口袋中,抬腿迈向恐惧之源\n";
}
gotoxy(3,72);
cout<<"可用道具数:";
cout<<"\n";
gotoxy(5,72);
cout<<"已破解密码机密码:";
cout<<"\n";
gotoxy(7,72);
cout<<"操作方式:w 上,s 下,a 左,d右 \n";
gotoxy(9,72);
cout<<"输入p暂停\n";
cout<<"\n";
return rw;
}
void csj(){
cout<<"门开了,你再考虑要不要回去找园丁小姐或者大把的金子。但这个念头只在\n";
Sleep(2000);


dev-c++中的c语言游戏代码是什么?
\\x0d\\x0aint status,sleeptime=200;\/\/每次运行的时间间隔\\x0d\\x0asnake *head, *food;\/\/蛇头指针,食物指针\\x0d\\x0asnake *q;\/\/遍历蛇的时候用到的指针\\x0d\\x0aint endgamestatus=0; \/\/游戏结束的情况,1:撞到墙;2:咬到自己;3:主动退出游戏。\\x0d\\x0a\\x0d\\x0a\/\/声明全部函数\/\/\\x0...

求几C语言个小游戏代码,简单的,要注释、、谢谢了、
int GetCardValue(int c){ if(c=='T') return 10;if(c>='0' && c<='9') return c - '0';return 1;} char GetOper(int n){ switch(n){ case 0:return '+';case 1:return '-';case 2:return '*';case 3:return '\/';} return ' ';}double MyCalcu(double op1, ...

能在dev-c++上运行通过的扫雷,贪吃蛇,等小游戏的c语言代码
initgraph(&gd,&gm,"c:\\\\tc");cleardevice();} void DrawK(void){ setcolor(11);setlinestyle(SOLID_LINE,0,THICK_WIDTH);for(i=50;i<=600;i+=10){ rectangle(i,40,i+10,49); \/*画出上边框*\/ rectangle(i,451,i+10,460); \/*画出下边框*\/ } for(i=40;i<=450;i+=10)...

c语言游戏编程,下落的小鸟 求代码
void Csh( ) \/\/初始化界面 { printf("══════════════════════════════════════\\n");printf(" ■■ ■■ C语言版 Flappy Bird \\n");printf(" ■■ ■■\\n");printf(" ■■ ■■\\n");printf(" ■■ ■■ 瞎搞人:yyposs原创\\n")...

C语言扫雷游戏源代码
"扫雷"小游戏C代码 include<stdio.h>#include<math.h>#include#include<stdlib.h>main( ){char a[102][102],b[102][102],c[102][102],w;int i,j; \/*循环变量*\/int x,y,z[999]; \/*雷的位置*\/int t,s; \/*标记*\/int m,n,lei; \/*计数*\/int u,v; \/*输入*\/int...

基于SAT的数独游戏求解程序,求C语言代码
用0代表要填的数 include <stdio.h> include <stdlib.h> define SIZE 9 define get_low_bit(x) ((~x&(x-1))+1)struct{ int left;char num;char try;}board[SIZE][SIZE];int bit2num(int bit){ switch(bit){ case 16:case 256:return 9;基础解法 排除法(摒除法)摒除法:用数字...

C语言 游戏 代码
void GamePlay(void);\/*游戏过程*\/ void Close(void);\/*图形关闭*\/ void main(void){ Init();Control();Close();} void Init(void)\/*图形开始*\/ { int gd=DETECT,gm;initgraph(&gd,&gm,"c:\\\\tc");} void Close(void)\/*图形关闭*\/ { closegraph();} void MouseOn(void)\/*鼠标...

用C语言编写的小游戏代码是什么?
\/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo???)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运*\/\\x0d\\x0a\/*贪吃蛇*\/\\x0d\\x0a#include\\x0d\\x0a#include\\x0d\\x0a#include\\x0d\\x0a#includ...

就C语言中 猜拳游戏的代码
\/\/ 为了避免玩一次游戏就退出程序,可以将代码放在循环中 while (1){ printf("这是一个猜拳的小游戏,请输入你要出的拳头:\\n");printf("A:剪刀\\nB:石头\\nC:布\\nD:不玩了\\n");scanf("%c%*c",&gamer);switch (gamer){ case 65: \/\/A case 97: \/\/a gamer=4;break;case 66: \/\/...

由电脑来猜4位数字游戏的C\/C++程序代码
include<stdio.h> include<stdlib.h> include main(){ int i,j,k;int l,n;int a=0,b=0,m=0;int x[4],y[4];int count=0;\/\/将数字输入数组x printf("请输入4个数字:\\n");for(i=0;i<=3;i++) \/*Imput a number*\/ { scanf("%d",x+i);} \/* 输出数组 x for(...

房县15059851788: 谁有c++小游戏代码
骑侦亚伯: #include<iostream>#include<windows.h>#include<conio.h>#include<time.h>#include<string>using namespace std;/*=============== all the structures ===============*/typedef struct Frame{COORD position[2];int flag;}Frame;/*===========...

房县15059851788: 求个用VC++C语言编写的小游戏 -
骑侦亚伯: #include <bits/stdc++.h> #include <Windows.h> #include <conio.h>using namespace std; long long side[21][42],x=20,y=10,ans,xue=10;char chInput; int main(){srand((unsigned)time(NULL));for(int i=1;i<21;i++)for(int j=1;j<40;j++)side[i][j]=' ';side...

房县15059851788: 怎么编一个c++小游戏 -
骑侦亚伯: #include "stdafx.h" #include <boost\lexical_cast.hpp> #include<stdlib.h> #include<string.h> #include <iostream> #include <map> #include<iterator> #include<vector> #include<algorithm> #include<set> #include<map> #include <cstring> #...

房县15059851788: C++:趣味编程实现一个小游戏 -
骑侦亚伯: #include"stdio.h"#define N 17 void main(){ int a,b,temp,i,j,k,l,m,n; int num[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}; int *ptr; printf("开始元素序号:"); scanf("%d",&a); printf("报几出列:"); scanf("%d",&b); ptr=&num[a-1]; ...

房县15059851788: 求一个小游戏的c++代码?
骑侦亚伯: 在sin按钮的callback函数里写:plot(handles.axes1,sin([0:0.01:10]));其实就是在sin的callback下面画一个正弦函数图,主要是要画在axes1里,所以在plot括号里最前方写handles.axes1.

房县15059851788: 求一个c++做的小游戏或小软件(在电脑上用的).最好两种都给我. -
骑侦亚伯: 贪吃蛇游戏代码#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<conio.h>#include<time.h>#include<windows.h>#define ML 100 using namespace std; struct snake { int head,tail,body[200],length; }; snake T; int ...

房县15059851788: 请高手帮我做一个用C++写的一个猜拳的小游戏的程序~ -
骑侦亚伯: #include#include #include void show(int input) { switch(input) { case 0:cout<<("出的是石头!"); break; case 1:cout<<("出的是剪子!"); break; case 2:cout<<("出的是布!"); break; default:; } } void compare(int inputPlay,int ...

房县15059851788: 用C++编写猜数游戏的程序
骑侦亚伯: #include"stdafx.h"#includeusingnamespacestd;voidguess(intrandomNum[4]);intn=0;voidmain(){cout>input;for(inti=3;i>=0;i--){inputArray[i]=input%10;input/=10;}for(inti=0;i

房县15059851788: 如何用C++写小游戏 -
骑侦亚伯: 你可以看看SDL2.0这个图形库 游戏主要的步骤就是update和draw,SDL通过计时器可以实现这两个步骤

房县15059851788: 怎么样用vc++6.0编写小游戏?
骑侦亚伯: 文件->新建->工程选项卡->win32 console application->输入工程名和保存路径->确定->完成->确定 然后再 文件->新建->文件选项卡->C++ source file->输入文件名->确定 这样就可以编译了

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网