#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++;
elsem--;
if( m == x )
{
if( n < y )n++;
elsen--;
}
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;
}
c语言猜数字游戏源代码记忆游戏
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#define?N?10
int?main(?)
{int?i,k,n,a[N],b[N],f=0;
srand(time(NULL));
printf("?按1开始n?按0退出:_");
scanf("%d",&n);
system("cls");
while(n!=0)
{for(k=0;k<N;k++)a[k]?=?rand(?)%N;
printf("ntt[请您牢记看到颜色的顺序]nn");
for(k=0;k<N;k++)
{switch(a[k])
{case?0:system("color?90");printf("?0:淡蓝色n");break;?//淡蓝色
case?1:system("color?f0");printf("?1:白色n");break;?//白色
case?2:system("color?c0");printf("?2:淡红色n");break;?//淡红色
case?3:?system("color?d0");printf("?3:淡紫色n");break;?//淡紫色
case?4:?system("color?80");printf("?4:灰色n");?break;?//灰色
case?5:?system("color?e0");printf("?5:**n");break;?//**
case?6:?system("color?10");printf("?6:蓝色n");?break;?//蓝色
case?7:?system("color?20");printf("?7:绿色n");break;?//绿色
case?8:?system("color?30");printf("?8:浅绿色n");break;?//浅绿色
case?9:?system("color?40");printf("?9:红色n");break;?//红色
}
Sleep(1500);
system("color?f");?//单个控制?文字颜色
Sleep(100);
}
system("cls");
printf("?0:淡蓝色,1:白色,2:淡红色,3:淡紫色,4:灰色,5:**,6:蓝色7:绿色,8:浅绿色,9:红色n");
printf("nt请输入颜色的顺序:");
for(k=0;k<N;k++)scanf("%d",&b[k]);
for(k=0;k<N;k++)if(a[k]?==?b[k])?f++;
if(f==0)?printf("?你的记忆弱爆了0n");
else?if(f==1)?printf("?你的记忆有点弱1n");
else?if(f<5)?printf("?你的记忆一般<5n");
else?printf("?你的记忆力很强!n");
Sleep(2000);
system("cls");
printf("tt按0退出ntt按任意键继续游戏:n");
scanf("%d",&n);
system("cls");
}
return?0;
}
注:DEVc++运行通过,每输入一个数字要加入一个空格 。
小游戏2048:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
int ?jsk( ); ?//计算空格数
void rsgm( ); ?//重置游戏
void inkey( );? //按键输入
void left( ); ?//向左移动
void right( ); ?//向右移动
void up( );? //向上移动
void down( );? //向下移动
void show( ); ?//输出界面
void adnum( ); //添加随机数
void yes( );//游戏是否结束(1是0否)
void gtxy(int x, int y); //控制光标位置的函数
int a[4][4];//存储16个格子中的数字
int score = 0;? //每局得分
int best = 0;? //最高得分
int ifnum;? //是否需要添加数字(1是0否)
int over; ?//游戏结束标志(1是0否)
int i,j,k;
int main( )
{ rsgm( ); ?//重置游戏
? inkey( ); ?//按键输入
? return 0;
}
void Color(int a) ? //设定字符颜色的函数(a应为1-15)
{? SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);? } ?
void rsgm( ) ? //重置游戏
{ score = 0; ifnum = 1; over = 0; srand((unsigned)time(0));? //启动随机数发生器
int n = rand( ) % 16; ? //随机函数产生0-15的数字
for (i = 0; i < 4; i++)
{for (j = 0; j < 4; j++)
{ if (n == 0) { int k = rand( ) % 3; if (k == 0 || k == 1) { a[i][j] = 2; }
? else { a[i][j] = 4; } n--; }
? else { a[i][j] = 0; n--; }
}
}
adnum( );
system("cls");
CONSOLE_CURSOR_INFO gb={1,0};? //以下两行是隐藏光标的设置,gb代指光标
SetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &gb );
Color(14); ? //设置字体淡**
printf("nntt? 2048小游戏"); Color(7); ? //恢复白字黑底
printf("nt┌──────┬──────┬──────┬──────┐");
printf("nt│? │? │? │? │");
printf("nt├──────┼──────┼──────┼──────┤");
printf("nt│? │? │? │? │");
printf("nt├──────┼──────┼──────┼──────┤");
printf("nt│? │? │? │? │");
printf("nt├──────┼──────┼──────┼──────┤");
printf("nt│? │? │? │? │");
printf("nt└──────┴──────┴──────┴──────┘");
show( );
}
void show( ) ? //输出界面
{ for(i=0;i<4;i++)
for(j=0;j<4;j++)
{ gtxy(7*j+9,2*i+4); ? //gtxy(7*j+9, 2*i+4)是光标到指定位置输出数字
? if(a[i][j]==0){printf("? "); Color(7); printf("│");}
? else if(a[i][j]<10){ if (a[i][j] == 2) { Color(14); }
? else if (a[i][j] == 4) { Color(13); }
? else if (a[i][j] == 8) { Color(12); }
? printf(" ?%d? ", a[i][j]); Color(7 ); printf("│");
}
? else if (a[i][j] < 100){if (a[i][j] == 16) { Color(12); }
else if (a[i][j] == 32) { Color(10); }
else if (a[i][j] == 64) { Color(2 ); }
printf("? %d? ", a[i][j]); Color(7); printf("│");
? }
else if (a[i][j] < 1000) {if (a[i][j] == 128) { Color(9); }
else if (a[i][j] == 256) { Color(1); }
else if (a[i][j] == 512) { Color(13); }
printf("? %d ", a[i][j]); Color(7); printf("│");
? }
? else if (a[i][j] < 10000) {if (a[i][j] == 1024) { Color(5); }
? else { Color(15); }
? printf(" %d ", a[i][j]); Color(7); printf("│");
}
}
if (jsk( ) == 0)
{? yes( );? if (over) { gtxy(9,12); Color(10);
? printf("nn? 游戏结束!是否继续? [ Y/N ]:"); }
}
}
void inkey( ) ? //按键输入
{ int key;
while (1)
? { key = getch( );
if (over) { if (key == 89|| key == 121) { rsgm( ); continue; }
else ?if (key == 78|| key == 110) { return; }
else ?continue; }
ifnum = 0;
? if(key==224)key=getch( );
? switch (key)
? { case 75: left( ); break;
case 77: right( ); break;
case 72: up( ); break;
case 80: down( );break;
}
if (score > best) { best = score; }
if (ifnum) { adnum( ); show( ); }
}
}
int jsk( ) ? //计算空格数
{ int n = 0;
for (i = 0; i < 4; i++)
{ for (j = 0; j < 4; j++) { if ( a[i][j] == 0) {n++;}? } ? }
return n;
}
void left( ) ? //向左移动
{ for (i = 0; i < 4; i++)
{for (j = 1, k = 0; j < 4; j++)
? { if (a[i][j] > 0)
{ if ( a[i][k] == a[i][j])
? { a[i][k] *= 2;? k++;
? score = score + 2 * a[i][j];
? a[i][j] = 0; ?ifnum = 1; }
else if ( a[i][k] == 0) { a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }
else { a[i][k + 1] = a[i][j]; if ((k + 1) != j) { a[i][j] = 0; ifnum = 1; }
k++; }
}
? }
}
}
void right( ) ? //向右移动
{for (i = 0; i < 4; i++)
{for (j = 2, k = 3; j >= 0; j--)
? {if (a[i][j] > 0)
? { if (a[i][k] == a[i][j])
{a[i][k] *= 2; k--; score = score + 2 * a[i][j]; a[i][j] = 0; ifnum = 1; }
else if ( a[i][k] == 0) {a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }
else { a[i][k - 1] = a[i][j]; if ((k - 1) != j) { a[i][j] = 0; ifnum = 1; } k--; }
}
? }
}
}
void up( ) ? //向上移动
{for (i = 0; i < 4; i++)
{for (j = 1, k = 0; j < 4; j++)
? {if (a[j][i] > 0)
? {if ( a[k][i] == a[j][i]) { a[k][i] *= 2; k++;score = score + 2 * a[j][i];
a[j][i] = 0; ifnum = 1; }
else if ( a[k][i] == 0) { a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }
else { a[k + 1][i] = a[j][i]; if ((k + 1) != j) { a[j][i] = 0; ifnum = 1; }
k++; }
}
? }
}
}
void down( ) ? //向下移动
{ for (i = 0; i < 4; i++)
{for (j = 2, k = 3; j >= 0; j--)
{if (a[j][i] > 0)
? {if (a[k][i] == a[j][i])
{a[k][i] *= 2; k--;score = score + 2 * a[j][i]; a[j][i] = 0; ifnum = 1; }
else if (a[k][i] == 0) {a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }
else {a[k - 1][i] = a[j][i];
? if ((k - 1) != j) {a[j][i] = 0; ifnum = 1; } k--; }
}
}
}
}
void adnum( ) ? //添加随机数
{ srand(time(0)); int n = rand( ) % jsk( );
for (int i = 0; i < 4; i++)
{for (int j = 0; j < 4; j++)
{ if (a[i][j] == 0) {if (n != 0) { n--; }
? else {int k = rand( ) % 3;
? if (k == 0 || k == 1) {a[i][j] = 2; return; }
? else {a[i][j] = 4; return; } }
}
}
}
}
void yes( ) ? //游戏是否结束
{ for (int i = 0; i < 4; i++)
{for (int j = 0; j < 3; j++)
? {if (a[i][j] == a[i][j + 1] || a[j][i] == a[j + 1][i]) {over = 0; return; }}
}
over = 1;
}
void gtxy(int x, int y) ? //控制光标位置的函数
{ COORD zb; ? //zb代指坐标
zb.X = x;
zb.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), zb);
【小游戏的C++代码】
}
- 微信小游戏在哪找
- 一个九宫格上面画x和o游戏的玩法?
- 熊出没之熊大快跑这款游戏的规则及画面等方面怎么样?
- 哪个网站有。所有所有游戏的源代码
- dota入门教程介绍游戏的一些打法参考攻略
- 戏的开头四字成语?
- 80后游戏卡摔跤名字
- 最强蜗牛最新小游戏合集和获取方法一览
- 构成游戏的四个基本元素
- 梦见我在游戏机室玩游戏的预兆