当前位置: 首页 » 网络黑客 » 可复制代码做小游戏_自制小游戏代码

可复制代码做小游戏_自制小游戏代码

作者:hacker 时间:2022-12-23 阅读数:114人阅读

文字简介:

自己如何 *** 小游戏?

*** 小游戏需要学相关的编程知识。不同的游戏需要不同的编程代码。

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

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

执行原理:

计算机对除机器语言以外的源程序不能直接识别、理解和执行,都必须通过某种方式转换为计算机能够直接执行的。

这种将高级程序设计语言编写的源程序转换到机器目标程序的方式有两种:解释方式和编译方式。

解释方式下,计算机对高级语言书写的源程序一边解释一边执行,不能形成目标文件和执行文件。

编译方式下,首先通过一个对应于所用程序设计语言的编译程序对源程序进行处理,经过对源程序的词法分析、语法分析、语意分析、代码生成和代码优化等阶段将所处理的源程序转换为用二进制代码表示的目标程序。

然后通过连接程序处理将程序中所用的函数调用、系统功能调用等嵌入到目标程序中,构成一个可以连续执行的二进制执行文件。

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;

}

用VB写一个和电脑猜石头剪刀布的小游戏(要代码)

如你所说

1、建立三个按钮command1,command2,command3

2、建立两个标签label1,label2

3、复制代码,运行

Dim a As Long

Dim b As Long

Dim c As Long

Dim e As Long

Private Sub Command1_Click()

c = 1

Call check(c)

End Sub

Private Sub Command2_Click()

c = 2

Call check(c)

End Sub

Private Sub Command3_Click()

c = 3

Call check(c)

End Sub

Private Sub Form_Load()

Command1.Caption = "石头"

Command2.Caption = "剪刀"

Command3.Caption = "布"

Label1.Caption = ""

a = 0

b = 0

e = 0

Call printt(a, b, e, 0)

End Sub

Sub check(temp As Long)

Dim d As Long

Randomize

d = Int(Rnd * 3 + 1)

If d = temp Then

e = e + 1

Call printt(a, b, e, d)

Else

Select Case d

Case 1

If temp = 2 Then

a = a + 1

Call printt(a, b, e, d)

ElseIf temp = 3 Then

b = b + 1

Call printt(a, b, e, d)

End If

Case 2

If temp = 1 Then

b = b + 1

Call printt(a, b, e, d)

ElseIf temp = 3 Then

a = a + 1

Call printt(a, b, e, d)

End If

Case 3

If temp = 1 Then

a = a + 1

Call printt(a, b, e, d)

ElseIf temp = 2 Then

b = b + 1

Call printt(a, b, e, d)

End If

End Select

End If

End Sub

Sub printt(temp1 As Long, temp2 As Long, temp3 As Long, temp4 As Long)

Label2.Caption = "电脑赢" temp1 "次," "你赢" temp2 "次," "平局" temp3 "次。"

Select Case temp4

Case 1

Label1.Caption = "石头"

Case 2

Label1.Caption = "剪刀"

Case 3

Label1.Caption = "布"

Case 0

Label1.Caption = "电脑还未出"

End Select

End Sub

c语言小游戏代码

最基础的贪吃蛇的代码

#includestdio.h

#includewindows.h//基本型态定义。支援型态定义函数。使用者界面函数 图形装置界面函数。

#includeconio.h //用户通过按键盘产生的对应操作 (控制台)

#includestdlib.h

#includetime.h //日期和时间头文件

#define LEN 30

#define WID 25

int Snake[LEN][WID] = {0}; //数组的元素代表蛇的各个部位

char Sna_Hea_Dir = 'a';//记录蛇头的移动方向

int Sna_Hea_X, Sna_Hea_Y;//记录蛇头的位置

int Snake_Len = 3;//记录蛇的长度

clock_t Now_Time;//记录当前时间,以便自动移动

int Wait_Time ;//记录自动移动的时间间隔

int Eat_Apple = 1;//吃到苹果表示为1

int Level ;

int All_Score = -1;

int Apple_Num = -1;

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //获取标准输出的句柄 windows.h

//句柄 :标志应用程序中的不同对象和同类对象中的不同的实例 方便操控,

void gotoxy(int x, int y)//设置光标位置

{

COORD pos = {x,y}; //定义一个字符在控制台屏幕上的坐标POS

SetConsoleCursorPosition(hConsole, pos); //定位光标位置的函数windows.h

}

void Hide_Cursor()//隐藏光标 固定函数

{

CONSOLE_CURSOR_INFO cursor_info = {1, 0};

SetConsoleCursorInfo(hConsole, cursor_info);

}

void SetColor(int color)//设置颜色

{

SetConsoleTextAttribute(hConsole, color);

//是API设置字体颜色和背景色的函数 格式:SetConsoleTextAttribute(句柄,颜色);

}

void Print_Snake()//打印蛇头和蛇的脖子和蛇尾

{

int iy, ix, color;

for(iy = 0; iy WID; ++iy)

for(ix = 0; ix LEN; ++ix)

{

if(Snake[ix][iy] == 1)//蛇头

{

SetColor(0xf); //oxf代表分配的内存地址 setcolor:34行自定义设置颜色的函数

gotoxy(ix*2, iy);

printf("※");

}

if(Snake[ix][iy] == 2)//蛇的脖子

{

color = rand()%15 + 1; //rand()函数是产生随机数的一个随机函数。C语言里还有 srand()函数等。

//头文件:stdlib.h

if(color == 14)

color -= rand() % 13 + 1; //变色

SetColor(color);

gotoxy(ix*2, iy);

printf("■");

}

if(Snake[ix][iy] == Snake_Len)

{

gotoxy(ix*2, iy);

SetColor(0xe);

printf("≈");

}

}

}

void Clear_Snake()//擦除贪吃蛇

{

int iy, ix;

for(iy = 0; iy WID; ++iy)

for(ix = 0; ix LEN; ++ix)

{

gotoxy(ix*2, iy);

if(Snake[ix][iy] == Snake_Len)

printf(" ");

}

}

void Rand_Apple()//随机产生苹果

{

int ix, iy;

do

{

ix = rand() % LEN;

iy = rand() % WID;

}while(Snake[ix][iy]);

Snake[ix][iy] = -1;

gotoxy(ix*2, iy);

printf("⊙");

Eat_Apple = 0;

}

void Game_Over()//蛇死掉了

{

gotoxy(30, 10);

printf("Game Over");

Sleep(3000);

system("pause nul");

exit(0);

}

void Move_Snake()//让蛇动起来

{

int ix, iy;

for(ix = 0; ix LEN; ++ix)//先标记蛇头

for(iy = 0; iy WID; ++iy)

if(Snake[ix][iy] == 1)

{

switch(Sna_Hea_Dir)//根据新的蛇头方向标志蛇头

{

case 'w':

if(iy == 0)

Game_Over();

else

Sna_Hea_Y = iy - 1;

Sna_Hea_X = ix;

break;

case 's':

if(iy == (WID -1))

Game_Over();

else

Sna_Hea_Y = iy + 1;

Sna_Hea_X = ix;

break;

case 'a':

if(ix == 0)

Game_Over();

else

Sna_Hea_X = ix - 1;

Sna_Hea_Y = iy;

break;

case 'd':

if(ix == (LEN - 1))

Game_Over();

else

Sna_Hea_X = ix + 1;

Sna_Hea_Y = iy;

break;

default:

break;

}

}

if(Snake[Sna_Hea_X][Sna_Hea_Y]!=1Snake[Sna_Hea_X][Sna_Hea_Y]!=0Snake[Sna_Hea_X][Sna_Hea_Y]!=-1)

Game_Over();

if(Snake[Sna_Hea_X][Sna_Hea_Y] 0)//吃到苹果

{

++Snake_Len;

Eat_Apple = 1;

}

for(ix = 0; ix LEN; ++ix)//处理蛇尾

for(iy = 0; iy WID; ++iy)

{

if(Snake[ix][iy] 0)

{

if(Snake[ix][iy] != Snake_Len)

Snake[ix][iy] += 1;

else

Snake[ix][iy] = 0;

}

}

Snake[Sna_Hea_X][Sna_Hea_Y] = 1;//处理蛇头

}

void Get_Input()//控制蛇的移动方向

{

if(kbhit())

{

switch(getch())

{

case 87:

Sna_Hea_Dir = 'w';

break;

case 83:

Sna_Hea_Dir = 's';

break;

case 65:

Sna_Hea_Dir = 'a';

break;

case 68:

Sna_Hea_Dir = 'd';

break;

default:

break;

}

}

if(clock() - Now_Time = Wait_Time)//蛇到时间自动行走

{

Clear_Snake();

Move_Snake();

Print_Snake();

Now_Time = clock();

}

}

void Init()//初始化

{

system("title 贪吃毛毛蛇");

system("mode con: cols=80 lines=25");

Hide_Cursor();

gotoxy(61, 4);

printf("You Score:");

gotoxy(61, 6);

printf("You Level:");

gotoxy(61, 8);

printf("The Lenght:");

gotoxy(61, 10);

printf("The Speed:");

gotoxy(61, 12);

printf("Apple Num:");

int i;

for(i = 0; i Snake_Len; ++i)//生成蛇

Snake[10+i][15] = i+1;

int iy, ix;//打印蛇

for(iy = 0; iy WID; ++iy)

for(ix = 0; ix LEN; ++ix)

{

if(Snake[ix][iy])

{

SetColor(Snake[ix][iy]);

gotoxy(ix*2, iy);

printf("■");

}

}

}

void Pri_News()//打印信息

{

SetColor(0xe);

gotoxy(73,4);

All_Score += Level;

printf("%3d", All_Score);

gotoxy(73, 6);

printf("%3d", Level);

gotoxy(73, 8);

printf("%3d",Snake_Len);

gotoxy(73, 10);

printf("0.%3ds", Wait_Time/10);

gotoxy(73, 12);

printf("%d", Apple_Num);

}

void Lev_Sys()//等级系统

{

if(((Apple_Num-1) / 10) == Level)

{

++Level;

if(Wait_Time 50)

Wait_Time -= 50;

else

if(Wait_Time 10)

Wait_Time -= 10;

else

Wait_Time -= 1;

}

}

int main(void)

{

Init();

srand((unsigned)time(NULL));//设置随机数的种子

Now_Time = clock();

int speed1=1000,speed2,a;

printf("\n");

printf("请输入你想要的速度\n");

scanf("%d",speed2);

Level=1;

Wait_Time=speed1-speed2;

printf("请输入你想要的苹果数\n");

scanf("%d",a);

while(a--)

Rand_Apple();

while(1)

{

if(Eat_Apple)

{

++Apple_Num;

Rand_Apple();

Lev_Sys();

Pri_News();

}

Get_Input();

Sleep(10);

}

return 0;

}

求一个简单又有趣的JAVA小游戏代码

具体如下:

连连看的小源码

package Lianliankan;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组

JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮

JLabel fractionLable=new JLabel("0"); //分数标签

JButton firstButton,secondButton; //

分别记录两次62616964757a686964616fe59b9ee7ad9431333335326239被选中的按钮

int grid[][] = new int[8][7];//储存游戏按钮位置

static boolean pressInformation=false; //判断是否有按钮被选中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标

int i,j,k,n;//消除 *** 控制

代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。

对于字符和Unicode数据的位模式的定义,此模式代表特定字母、数字或符号(例如 0x20 代表一个空格,而 0x74 代表字符“t”)。一些数据类型每个字符使用一个字节;每个字节可以具有 256 个不同的位模式中的一个模式。

在计算机中,字符由不同的位模式(ON 或 OFF)表示。每个字节有 8 位,这 8 位可以有 256 种不同的 ON 和 OFF 组合模式。对于使用 1 个字节存储每个字符的程序,通过给每个位模式指派字符可表示最多 256 个不同的字符。2 个字节有 16 位,这 16 位可以有 65,536 种唯一的 ON 和 OFF 组合模式。使用 2 个字节表示每个字符的程序可表示最多 65,536 个字符。

单字节代码页是字符定义,这些字符映射到每个字节可能有的 256 种位模式中的每一种。代码页定义大小写字符、数字、符号以及 !、@、#、% 等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。

虽然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间交换数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。

如果某个数据库为来自许多不同国家的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。

  • 评论列表
  •  
    发布于 2022-12-05 12:10:01  回复
  • Game_Over(); else Sna_Hea_X = ix + 1;
  •  
    发布于 2022-12-05 06:45:54  回复
  • ake_Len; ++i)//生成蛇 Snake[10+i][15] = i+1; int iy, ix;//打印蛇 for(iy = 0; iy WID; ++iy)

发表评论: