黑客24小时在线接单网站

电脑高手24在线咨询,黑客24小时在线接单网站,黑客接单平台,黑客网站找人,黑客在线qq接单

代码编程游戏可复制(自制代码游戏)

本文目录一览:

c++编程小游戏代码

以下是贪吃蛇源代码:

 

#includeiostream.h

#includewindows.h

#includetime.h

#includestdlib.h

#includeconio.h

#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;iN+2;i++)

{

for(j=0;jN+2;j++)

{

if(wall[i][j])

cout"■";

else cout"□" ;

}

coutendl;

}

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;ilen;i++)

snake[i]=(int*)malloc(sizeof(int)*2);

for(i=0;ilen;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;i0;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);

coutscoreendl;

}

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;ilen;i++)

free(snake[i]);

Sleep(INFINITE);

exit(0);

}

}

return 0;

}

爱丽丝疯狂回归躲闪编程不小心复制成打开雨伞了!谁能发给我躲闪的编程代码!

需锁定目标才能打开防御雨伞 默认键位也就是按 Caps Lock 锁定怪物 E 键打开防御雨伞 Tab可切换锁定目标

最浪漫的编程代码可复制有哪些?

最浪漫的编程代码可复制的编程代码有如下:

?php

for($t=0;$t360;$t++)

{

$y=2*cos($t)-cos(2*$t);//笛卡尔心形曲线函数

$x=2*sin($t)-sin(2*$t);

$x+=3;

$y+=3;

$x*=70;

$y*=70;

$x=round($x);

$y=round($y);

$str[]=$x;

$y=$y+2*(180-$y);//图像上下翻转

$x=$y;

$str[]=$x;

}

前面这段代码是用函数构造图形

$im=imagecreate(500,500);//创建图形500*500

$black=imagecolorallocate($im,0,0,0);

$red=imagecolorallocate($im,255,0,0);//设置图形颜色

imagepolygon($im,$str,360,$red);

imagestring($im,5,190,190,"love",$red);//输出字符串

header('Content-type:image/gif');//通知浏览器输出的是gif图片

imagegif($im);//输出图片

imagedestroy($im);//销毁

?

编程是编定程序的中文简称,就是让计算机代码解决某个问题,对某个计算体系规定一定的运算方式,使计算体系按照该计算方式运行,并最终得到相应结果的过程。

为了使计算机能够理解人的意图,人类就必须将需解决的问题的思路、方法和手段通过计算机能够理解的形式告诉计算机,使得计算机能够根据人的指令一步一步去工作,完成某种特定的任务。这种人和计算体系之间交流的过程就是编程。

c语言小游戏代码

“贪吃蛇”C代码,在dev C++试验通过(用4个方向键控制)

#include stdio.h

#include stdlib.h

#include conio.h

#include time.h

#include Windows.h

#define W 78  //游戏框的宽,x轴

#define H 26  //游戏框的高,y轴

int dir=3;    //方向变量,初值3表示向“左”

int Flag=0;   //吃了食物的标志(1是0否)

int score=0;  //玩家得分

struct food{ int x;  //食物的x坐标

                 int y;  //食物的y坐标

                }fod;  //结构体fod有2个成员

struct snake{ int len;      //蛇身长

                   int speed;  //移动速度

                   int x[100];  //蛇身某节x坐标

                   int y[100];  //蛇身某节y坐标

                  }snk;   //结构体snk有4个成员

void gtxy( int x,int y)  //控制光标移动的函数

{ COORD coord;

coord.X=x;

coord.Y=y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

void gtxy( int x,int y);  //以下声明要用到的几个自编函数

void csh( );  //初始化界面

void keymove( ); //按键操作移动蛇

void putFod( );  //投放食物

int  Over( );   //游戏结束(1是0否)

void Color(int a);  //设定显示颜色的函数

int main( )   //主函数

{ csh( );

  while(1)

    { Sleep(snk.speed);

      keymove( );

      putFod( );

     if(Over( ))

      { system(“cls”);

       gtxy(W/2+1,H/2); printf(“游戏结束!T__T”);

       gtxy(W/2+1,H/2+2); printf(“玩家总分:%d分”,score);

       getch( );

       break;

      }

  }

  return 0;

}

void csh( )   //初始化界面

{ int i;

gtxy(0,0);

CONSOLE_CURSOR_INFO cursor_info={1,0};  //以下两行是隐藏光标的设置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),cursor_info);

for(i=0;i=W;i=i+2)  //横坐标要为偶数,因为这个要打印的字符占2个位置

{Color(2);   //设定打印颜色为绿色

   gtxy(i,0);  printf("■");  //打印上边框

   gtxy(i,H); printf("■");  //打印下边框

}

for(i=1;iH;i++)

{ gtxy(0,i); printf("■");  //打印左边框

   gtxy(W,i); printf("■");  //打印右边框

}

while(1)

  { srand((unsigned)time(NULL));  //初始化随机数发生器srand( )

fod.x=rand()%(W-4)+2;  //随机函数rand( )产生一个从0到比”(W-4)”小1的数再加2

fod.y=rand()%(H-2)+1;  //随机函数rand( )产生一个从0到比”(H-2)”小1的数再加1

if (fod.x%2==0) break;  //fod.x是食物的横坐标,要是2的倍数(为偶数)

}

Color(12);   //设定打印颜色为淡红

gtxy(fod.x,fod.y); printf("●");  //到食物坐标处打印初试食物

snk.len=3;      //蛇身长初值为3节

snk.speed=350;  //刷新蛇的时间,即移动速度初值为350毫秒

snk.x[0]=W/2+1;  //蛇头横坐标要为偶数(因为W/2=39)

snk.y[0]=H/2;    //蛇头纵坐标

Color(9);   //设定打印颜色为淡蓝

gtxy(snk.x[0], snk.y[0]);  printf("■");   //打印蛇头

for(i=1;isnk.len;i++)

   { snk.x[i]=snk.x[i-1]+2;  snk.y[i]=snk.y[i-1];

     gtxy(snk.x[i],snk.y[i]);  printf("■");   //打印蛇身

   }

Color(7, 0);   //恢复默认的白字黑底

return;

}

void keymove( )  //按键操作移动蛇

{ int key;

if( kbhit( ) )    //如有按键输入才执行下面操作

{ key=getch( );

   if (key==224)  //值为224表示按下了方向键,下面要再次获取键值

     { key=getch( );

       if(key==72dir!=2)dir=1;  //72表示按下了向上方向键

       if(key==80dir!=1)dir=2;  //80为向下

       if(key==75dir!=4)dir=3;  //75为向左

       if(key==77dir!=3)dir=4;  //77为向右

     }

  if (key==32)

    { while(1) if((key=getch( ))==32) break; }  //32为空格键,这儿用来暂停

}

if (Flag==0)   //如没吃食物,才执行下面操作擦掉蛇尾

   { gtxy(snk.x[snk.len-1],snk.y[snk.len-1]);  printf("  "); }

int i;

for (i = snk.len - 1; i 0; i--)  //从蛇尾起每节存储前一节坐标值(蛇头除外)

{ snk.x[i]=snk.x[i-1];  snk.y[i]=snk.y[i-1]; }

switch (dir)  //判断蛇头该往哪个方向移动,并获取最新坐标值

{ case 1: snk.y[0]--; break;   //dir=1要向上移动

  case 2: snk.y[0]++; break;  //dir=2要向下移动

  case 3: snk.x[0]-=2; break;  //dir=3要向左移动

  case 4: snk.x[0]+=2; break;  //dir=4要向右移动

}

Color(9);

gtxy(snk.x[0], snk.y[0]); printf("■");   //打印蛇头

if (snk.x[0] == fod.x snk.y[0] == fod.y)   //如吃到食物则执行以下操作

   { printf("\7"); snk.len++; score += 100; snk.speed -= 5; Flag = 1; } //7是响铃

else Flag = 0;   //没吃到食物Flag的值为0

if(snk.speed150) snk.speed= snk.speed+5;   //作弊码,不让速度无限加快

}

void putFod( )  //投放食物

{ if (Flag == 1)  //如吃到食物才执行以下操作,生成另一个食物

  { while (1)

  { int i,n= 1;

   srand((unsigned)time(NULL));  //初始化随机数发生器srand( )

   fod.x = rand( ) % (W - 4) + 2;  //产生在游戏框范围内的一个x坐标值

   fod.y = rand( ) % (H - 2) + 1;  //产生在游戏框范围内的一个y坐标值

   for (i = 0; i snk.len; i++)   //随机生成的食物不能在蛇的身体上

 { if (fod.x == snk.x[i] fod.y == snk.y[i]) { n= 0; break;} }

   if (n fod.x % 2 == 0) break;  //n不为0且横坐标为偶数,则食物坐标取值成功

  }

     Color(12);  //设定字符为红色

     gtxy(fod.x, fod.y);  printf("●");   //光标到取得的坐标处打印食物

  }

return;

}

int Over( )  //判断游戏是否结束的函数

{ int  i;

Color(7);

gtxy(2,H+1); printf(“暂停键:space.”);  //以下打印一些其它信息

gtxy(2,H+2); printf(“游戏得分:%d”,score);

if (snk.x[0] == 0 || snk.x[0] == W) return 1;  //蛇头触碰左右边界

if (snk.y[0] == 0 || snk.y[0] == H) return 1;  //蛇头触碰上下边界

for (i = 1; i snk.len; i++)

{ if (snk.x[0] == snk.x[i] snk.y[0] == snk.y[i]) return 1; }  //蛇头触碰自身

return 0;    //没碰到边界及自身时就返回0

}

void Color(int a)   //设定颜色的函数

{  SetConsoleTextAttribute(GetStdHandle( STD_OUTPUT_HANDLE ),a );  }  

用C++编写的小游戏源代码

五子棋的代码:

#includeiostream

#includestdio.h

#includestdlib.h

#include time.h

using namespace std;

const int N=15;                 //15*15的棋盘

const char ChessBoardflag = ' ';          //棋盘标志

const char flag1='o';              //玩家1或电脑的棋子标志

const char flag2='X';              //玩家2的棋子标志

typedef struct Coordinate          //坐标类

int x;                         //代表行

int y;                         //代表列

}Coordinate;

class GoBang                    //五子棋类

{

public:

GoBang()                //初始化

{

InitChessBoard();

}

void Play()               //下棋

{

Coordinate Pos1;      // 玩家1或电脑

Coordinate Pos2;      //玩家2

int n = 0;

while (1)

{

int mode = ChoiceMode();

while (1)

{

if (mode == 1)       //电脑vs玩家

{

ComputerChess(Pos1,flag1);     // 电脑下棋

if (GetVictory(Pos1, 0, flag1) == 1)     //0表示电脑,真表示获胜

break;

PlayChess(Pos2, 2, flag2);     //玩家2下棋

if (GetVictory(Pos2, 2, flag2))     //2表示玩家2

break;

}

else            //玩家1vs玩家2

{

PlayChess(Pos1, 1, flag1);     // 玩家1下棋

if (GetVictory(Pos1, 1, flag1))      //1表示玩家1

break;

PlayChess(Pos2, 2, flag2);     //玩家2下棋

if (GetVictory(Pos2, 2, flag2))  //2表示玩家2

break;

}

}

cout "***再来一局***" endl;

cout "y or n :";

char c = 'y';

cin c;

if (c == 'n')

break;

}     

}

protected:

int ChoiceMode()           //选择模式

{

int i = 0;

system("cls");        //系统调用,清屏

InitChessBoard();       //重新初始化棋盘

cout "***0、退出  1、电脑vs玩家  2、玩家vs玩家***" endl;

while (1)

{

cout "请选择:";

cin i;

if (i == 0)         //选择0退出

exit(1);

if (i == 1 || i == 2)

return i;

cout "输入不合法" endl;

}

}

void InitChessBoard()      //初始化棋盘

{

for (int i = 0; i N + 1; ++i)   

{

for (int j = 0; j N + 1; ++j)

{

_ChessBoard[i][j] = ChessBoardflag;

}

}

}

void PrintChessBoard()    //打印棋盘,这个函数可以自己调整

{

system("cls");                //系统调用,清空屏幕

for (int i = 0; i N+1; ++i)

{

for (int j = 0; j N+1; ++j)

{

if (i == 0)                               //打印列数字

{

if (j!=0)

printf("%d  ", j);

else

printf("   ");

}

else if (j == 0)                //打印行数字

printf("%2d ", i);

else

{

if (i N+1)

{

printf("%c |",_ChessBoard[i][j]);

}

}

}

cout endl;

cout "   ";

for (int m = 0; m N; m++)

{

printf("--|");

}

cout endl;

}

}

void PlayChess(Coordinate pos, int player, int flag)       //玩家下棋

{

PrintChessBoard();         //打印棋盘

while (1)

{

printf("玩家%d输入坐标:", player);

cin pos.x pos.y;

if (JudgeValue(pos) == 1)          //坐标合法

break;

cout "坐标不合法,重新输入" endl;

}

_ChessBoard[pos.x][pos.y] = flag;

}

void ComputerChess(Coordinate pos, char flag)       //电脑下棋

{

PrintChessBoard();         //打印棋盘

int x = 0;

int y = 0;

while (1)

{

x = (rand() % N) + 1;      //产生1~N的随机数

srand((unsigned int) time(NULL));

y = (rand() % N) + 1;     //产生1~N的随机数

srand((unsigned int) time(NULL));

if (_ChessBoard[x][y] == ChessBoardflag)      //如果这个位置是空的,也就是没有棋子

break;

}

pos.x = x;

pos.y = y;

_ChessBoard[pos.x][pos.y] = flag;

}

int JudgeValue(const Coordinate pos)       //判断输入坐标是不是合法

{

if (pos.x 0 pos.x = Npos.y 0 pos.y = N)

{

if (_ChessBoard[pos.x][pos.y] == ChessBoardflag)

{

return 1;    //合法

}

}

return 0;        //非法

}

int JudgeVictory(Coordinate pos, char flag)           //判断有没有人胜负(底层判断)

{

int begin = 0;

int end = 0;

int begin1 = 0;

int end1 = 0;

//判断行是否满足条件

(pos.y - 4) 0 ? begin = (pos.y - 4) : begin = 1;

(pos.y + 4) N ? end = N : end = (pos.y + 4);

for (int i = pos.x, j = begin; j + 4 = end; j++)

{

if (_ChessBoard[i][j] == flag_ChessBoard[i][j + 1] == flag

_ChessBoard[i][j + 2] == flag_ChessBoard[i][j + 3] == flag

_ChessBoard[i][j + 4] == flag)

return 1;

}

//判断列是否满足条件

(pos.x - 4) 0 ? begin = (pos.x - 4) : begin = 1;

(pos.x + 4) N ? end = N : end = (pos.x + 4);

for (int j = pos.y, i = begin; i + 4 = end; i++)

{

if (_ChessBoard[i][j] == flag_ChessBoard[i + 1][j] == flag

_ChessBoard[i + 2][j] == flag_ChessBoard[i + 3][j] == flag

_ChessBoard[i + 4][j] == flag)

return 1;

}

int len = 0;

//判断主对角线是否满足条件

pos.x pos.y ? len = pos.y - 1 : len = pos.x - 1;

if (len 4)

len = 4;

begin = pos.x - len;       //横坐标的起始位置

begin1 = pos.y - len;      //纵坐标的起始位置

pos.x pos.y ? len = (N - pos.x) : len = (N - pos.y);

if (len4)

len = 4;

end = pos.x + len;       //横坐标的结束位置

end1 = pos.y + len;      //纵坐标的结束位置

for (int i = begin, j = begin1; (i + 4 = end) (j + 4 = end1); ++i, ++j)

{

if (_ChessBoard[i][j] == flag_ChessBoard[i + 1][j + 1] == flag

_ChessBoard[i + 2][j + 2] == flag_ChessBoard[i + 3][j + 3] == flag

_ChessBoard[i + 4][j + 4] == flag)

return 1;

}

//判断副对角线是否满足条件

(pos.x - 1) (N - pos.y) ? len = (N - pos.y) : len = pos.x - 1;

if (len 4)

len = 4;

begin = pos.x - len;       //横坐标的起始位置

begin1 = pos.y + len;      //纵坐标的起始位置

(N - pos.x) (pos.y - 1) ? len = (pos.y - 1) : len = (N - pos.x);

if (len4)

len = 4;

end = pos.x + len;       //横坐标的结束位置

end1 = pos.y - len;      //纵坐标的结束位置

for (int i = begin, j = begin1; (i + 4 = end) (j - 4 = end1); ++i, --j)

{

if (_ChessBoard[i][j] == flag_ChessBoard[i + 1][j - 1] == flag

_ChessBoard[i + 2][j - 2] == flag_ChessBoard[i + 3][j - 3] == flag

_ChessBoard[i + 4][j - 4] == flag)

return 1;

}

for (int i = 1; i N + 1; ++i)           //棋盘有没有下满

{

for (int j =1; j N + 1; ++j)

{

if (_ChessBoard[i][j] == ChessBoardflag)

return 0;                      //0表示棋盘没满

}

}

return -1;      //和棋

}

bool GetVictory(Coordinate pos, int player, int flag)   //对JudgeVictory的一层封装,得到具体那个玩家获胜

{

int n = JudgeVictory(pos, flag);   //判断有没有人获胜

if (n != 0)                    //有人获胜,0表示没有人获胜

{

PrintChessBoard();

if (n == 1)                //有玩家赢棋

{

if (player == 0)     //0表示电脑获胜,1表示玩家1,2表示玩家2

printf("***电脑获胜***\n");

else

printf("***恭喜玩家%d获胜***\n", player);

}

else

printf("***双方和棋***\n");

return true;      //已经有人获胜

}

return false;   //没有人获胜

}

private:

char _ChessBoard[N+1][N+1];   

};

扩展资料:

设计思路

1、进行问题分析与设计,计划实现的功能为,开局选择人机或双人对战,确定之后比赛开始。

2、比赛结束后初始化棋盘,询问是否继续比赛或退出,后续可加入复盘、悔棋等功能。

3、整个过程中,涉及到了棋子和棋盘两种对象,同时要加上人机对弈时的AI对象,即涉及到三个对象。

  • 评论列表:
  •  澄萌逐鹿
     发布于 2022-06-26 15:52:19  回复该评论
  • s.x = x;pos.y = y;_ChessBoard[pos.x][pos.y] = flag;}int JudgeValue(const Coordinate pos)       //判断输入坐标是不是合法{if (pos.x 0 pos.x = Npos.y
  •  离鸢吝吻
     发布于 2022-06-26 17:46:08  回复该评论
  • k.y[i]=snk.y[i-1];      gtxy(snk.x[i],snk.y[i]);  printf("■");   //打印蛇身    } Colo
  •  弦久鹿岛
     发布于 2022-06-26 16:14:35  回复该评论
  • flag_ChessBoard[i + 4][j] == flag)return 1;}int len = 0;//判断主对角线是否满足条件pos.x pos.y ? len = pos.y

发表评论:

Powered By

Copyright Your WebSite.Some Rights Reserved.