制作游戏的代码大全(编程游戏代码大全)

今日新闻 2022年05月30日
本文导读目录:

自己如何制作小游戏?

《自己动手制作小游戏》说明:一直在玩别人做的FLASH游戏么?现在给你个机会大显身手!来吧,制作自己的游戏!只是刚来时需要熟悉一下制作流程,

NEW是开始制作新游戏,点下去,用鼠标在蓝色区增加障碍,右下角是关数可设,下边有个SPECS按钮,里面有游戏非常详细的设置项,按加减号即可。上边还可以写上你的名字游戏名字,分数设定等。全部设置好了之后按MENU,点一下出现的按钮,会出现空白处很多文字,这个可以复制下来留存,然后按右边的钮,再点右边的PLAY,哈哈,竟然可以玩自己制作的游戏啦!!真是好神奇啊!

记得把自己制作游戏复制下来的文字保存,在一开始的界面有个LOAD,在空白处贴上这些文字,就可以再次重玩你自己制作的游戏啦!还可以把这个复制下来发给别人分享哦!

至于第三个按钮GO,可以玩玛里奥,索尼克之类的经典的小游戏啦!

回答者:741625911

C++做一个小游戏,有源代码的最好,谢谢

#include iostream

#includefstream

#include ctime

#include cmath

#include stdlib.h

#includestdio.h //时间 //文件

#include string

#define random(x)(rand()%x)

using namespace std;

void thunder(int Dif,int Row,int Column,char *USer)

{

int r,c,alls[22][22],backstage[22][22]={0};

srand((int)time(0));

for(r=1;r=Row;r++) // 生成alls(0~1)1是雷

{

for(c=1;c=Column;c++)

{

if(random(6)1) {alls[r][c]=1;} else{alls[r][c]=0;};

}

};

for(r=0;r=Row+1;r++) //生成 backstage(正确答案)

{

for(int c=0;c=Column+1;c++)

{

if(alls[r][c]==1)

{

(int)backstage[r][c]='*'; //将1变为 * 代表雷

}

else

{

for(int i=r-1;i=r+1;i++) //将0变为数字 (代表周围雷数)

for(int j=c-1;j=c+1;j++)

{

if(alls[i][j]!=alls[r][c]alls[i][j]==1){backstage[r][c]++;};

}

}; //else 结束

}; // for 结束

}; // for 结束

cout"======================*********================================"endl;

char surface[22][22]; //生成surface(用户界面)

for(r=0;r22;r++) //全部为零

for(c=0;c22;c++)

{

surface[r][c]='0';

}

for(r=1;r=Row;r++) //中间化 # 形成0包围#的形式 (通过数 #--(*||数字) 的个数 赢的时候停止循环)

for(c=1;c=Column;c++)

{

surface[r][c]='#';

}

for(r=1;r=Row;r++) //输出 surface 界面 便于检查

{

for(c=1;c=Column;c++) {cout" "surface[r][c];};

coutendl;

};

cout"请按格式输入"endl

"前两个数字为坐标,最后一个数字“1”表示此位置为雷,“0”则表示不是。"endl

"如:1 3 1 表示一行三列是雷;2 4 0 表示二行四列不是雷"endl

"提示:当数字周围雷都被扫出时,可再次按要求输入此位置,可得到周围数字。"endl;

long i=10000000L; //计算时间开始

clock_t start,finish;

double duration;

start=clock();

while(i--); //计算时间开始

int num=Row*Column; //计算#号个数

while(num!=0) //控制 是否点完所有位置

{

int x,y,judge;

cinxyjudge;

if(alls[x][y]!=judge)

{

cout"you lose!!!"endl;

cout"The answer is:"endl;

for(r=1;r=Row;r++) //输了 输出backstage 显示正确答案

{

for(int c=1;c=Column;c++)

{

cout" "(char)(backstage[r][c]==42?backstage[r][c]:backstage[r][c]+'0'); //输出backstage

}

coutendl;

}

break;

}

else

{

if(alls[x][y]==1) {if(surface[x][y]=='#'){num--;}surface[x][y]='@'; } // 雷 判断正确 显示“@”;数“#”

else

{

if(backstage[x][y]!=0) // 数字 判断正确 显示数字

{

if(surface[x][y]=='#'){num--; surface[x][y]=backstage[x][y]+'0'; } // 数“#”

else

{

int lei_num=0;

for(int i=x-1;i=x+1;i++) //数 数字周围 雷的个数

for(int j=y-1;j=y+1;j++)

{

if(surface[i][j]=='@')

lei_num++;

}

if(backstage[x][y]==lei_num) // 看数字周围雷是否全部扫出 提示 显示数字周围

{

for(int i=x-1;i=x+1;i++)

for(int j=y-1;j=y+1;j++)

if(surface[i][j]=='#') //数“#”

{

surface[i][j]=backstage[i][j]+'0';

num--;

}

}

}

}

else // 数字为零时 显示零周围的零

{

if(surface[x][y]=='#'){num--;}; //数“#”

surface[x][y]=backstage[x][y]+'0';

for(int i=x-1;i=x+1;i++) // 显示零周围的数字

for(int j=y-1;j=y+1;j++)

if(surface[i][j]=='#') // 避免 死循环

{

surface[i][j]=backstage[i][j]+'0';

num--; //数“#”

}

for(int k=0;k20;k++) //最多20层零 (点出最边上的零)

{

for (int R=1;R=Row;R++) //检查所有零

for(int C=1;C=Column;C++) //再次显示零周围的数字

{

if(surface[R][C]=='0')

{

for(int i=R-1;i=R+1;i++)

for(int j=C-1;j=C+1;j++)

{

if(surface[i][j]=='#') // 避免 死循环 数“#”

{

surface[i][j]=backstage[i][j]+'0';

num--;

}

}

}

} //匹配for 内

} //匹配 for 外

}//匹配else

}//匹配else

}//匹配els

coutendl;

cout"======================*********================================"endl;

for(r=1;r=Row;r++) //输出界面(已修改)

{

for(c=1;c=Column;c++) {cout" "surface[r][c];};

coutendl;

};

} //匹配while

finish=clock(); //计算时间结束

duration=(double)(finish-start)/CLOCKS_PER_SEC; //时间变量

if(num==0) //所有

{

cout" You win! Congratulations!! "endl;

cout" Your time is: "durationendl;

if(Dif==1) //读取 简单扫雷 的存储文件

{

string Name;

string name[6];

double Time,rang;

double times[6];

int i=0;

ifstream inf("扫雷 简单.txt");

for(i=0;i5;i++) //文件中信息导入到数组里

{

infName;infrangTime;

name[i]=Name;

times[i]=Time;

}

inf.close();

name[5]=USer; //本轮玩家信息

times[5]=duration;

double t1=0;

string t2;

for(int j=0;j5;j++) //冒泡排序法

{

for(i=0;i5-j;i++)

{

if(times[i]times[i+1])

{

t1=times[i];

times[i]=times[i+1];

times[i+1]=t1;

t2=name[i];

name[i]=name[i+1];

name[i+1]=t2;

}

}

}

ofstream outf("扫雷 简单.txt");

for(i=0;i5;i++) //将前五名玩家信息存储到文件中

{

coutname[i]" "i+1" "times[i]endl;

outfname[i]" "i+1" "times[i]endl;

}

outf.close();

}

if(Dif==2) //读取 一般扫雷 的存储文件

{

string Name;

string name[6];

double Time,rang;

double times[6];

int i=0;

ifstream inf("扫雷 一般.txt");

for(i=0;i5;i++) //文件中信息导入到数组里

{

infName;infrangTime;

name[i]=Name;

times[i]=Time;

}

inf.close();

name[5]=USer; //本轮玩家信息

times[5]=duration;

double t1=0;

string t2;

for(int j=0;j5;j++) //冒泡排序法

{

for(i=0;i5-j;i++)

{

if(times[i]times[i+1])

{

t1=times[i];

times[i]=times[i+1];

times[i+1]=t1;

t2=name[i];

name[i]=name[i+1];

name[i+1]=t2;

}

}

}

ofstream outf("扫雷 一般.txt");

for(i=0;i5;i++) //将前五名玩家信息存储到文件中 并输出

{

coutname[i]" "i+1" "times[i]endl;

outfname[i]" "i+1" "times[i]endl;

}

outf.close();

}

if(Dif==3) //读取 困难扫雷 的存储文件

{

string Name;

string name[6];

double Time,rang;

double times[6];

int i=0;

ifstream inf("扫雷 困难.txt");

for(i=0;i5;i++) //文件中信息导入到数组里

{

infName;infrangTime;

name[i]=Name;

times[i]=Time;

}

inf.close();

name[5]=USer; //本轮玩家信息

times[5]=duration;

double t1=0;

string t2;

for(int j=0;j5;j++) //冒泡排序法

{

for(i=0;i5-j;i++)

{

if(times[i]times[i+1])

{

t1=times[i];

times[i]=times[i+1];

times[i+1]=t1;

t2=name[i];

name[i]=name[i+1];

name[i+1]=t2;

}

}

}

ofstream outf("扫雷 困难.txt");

for(i=0;i5;i++) //将前五名玩家信息存储到文件中

{

coutname[i]" "i+1" "times[i]endl;

outfname[i]" "i+1" "times[i]endl;

}

outf.close();

}

}

}

void scale(int dif,char *User) //选择难度

{

int row,column;

if(dif==1) {row=3;column=3;}

if(dif==2) {row=7;column=7;}

if(dif==3) {row=10;column=10;}

cout"The scale is: "row"*"columnendl;

thunder(dif,row,column,User);

};

int main()

{

int Continue=1;

int difficulty;

char user[10];

cout" Welcom to the game! "endl

" 请输入用户名! "endl;

cinuser;

while(Continue==1)

{

cout"=======================*******************======================="endl

" 请选择难度! "endl

" 简单——1 "endl

" 一般——2 "endl

" 困难——3 "endl;

cindifficulty;

scale(difficulty,user);

cout"继续游戏——1 结束游戏——0"endl;

cinContinue;

}

return 0;

}

扫雷小游戏,自己编的代码

用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;

}参考资料:从C++吧看来的

网络游戏的源代码是什么?

网络游戏源代码就是游戏的基础,在外行人眼里是无数行的英文和数字,其实就是一组程序。

作用当然是开发游戏啦。

手上拥有了源代码就可以制作游戏,当然如果你啥都不改,那功能就和原来的游戏没什么两样。

现在网上你可以搜索一下网络游戏的源代码还是非常多的,但是大多数都是不完整的,也就是说你即便得到了也无法用。

另外只要这款游戏是国产的,你如果一模一样也不行,因为违反版权。

所以就算你拿到了源代码,你也要有完整的美术资源,需要让程序贴图替换上去,达到视觉上不一样的效果。世界背景和故事都要换,所有这些的成本当然不是一般的高。

好吧,即便你搞好了,那接下来你还要运营吧,运营的成本就更高了。

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

那你就自己做个猜数字好了

import java.util.*;

import java.io.*;

public class CaiShu{

public static void main(String[] args) throws IOException{

Random a=new Random();

int num=a.nextInt(100);

System.out.println("请输入一个100以内的整数:");

for (int i=0;i=9;i++){

BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));

String str=bf.readLine();

int shu=Integer.parseInt(str);

if (shunum)

System.out.println("输入的数大了,输小点的!");

else if (shunum)

System.out.println("输入的数小了,输大点的!");

else {

System.out.println("恭喜你,猜对了!");

if (i=2)

System.out.println("你真是个天才!");

else if (i=6)

System.out.println("还将就,你过关了!");

else if (i=8)

System.out.println("但是你还……真笨!");

else

System.out.println("你和猪没有两样了!");

break;}

}

}

}

制作游戏代码

Dim game(3,2),i,j,result,num '定义二维数组 二维长度3, 一维长度2

Dim fso ,ws,f ,logFileWrite,logFileRead, fileStr,flag,flagFailNum, flagIndex ' 定义日志文件

set ws = CreateObject("wscript.shell")

Set fso = CreateObject("scripting.filesystemobject")

If fso.fileexists("C:\Users\18190\Desktop\vbs\测试\game_log.txt") Then

Else

Set f = fso.createtextfile("C:\Users\18190\Desktop\vbs\测试\game_log.txt",true)

'If fso.fileexists("C:\Users\18190\Desktop\vbs\测试\game_log.txt") Then

' Set logFileWrite = fso.OpenTextFile("C:\Users\18190\Desktop\vbs\测试\game_log.txt",8,true)

' logFileWrite.writeLine "数字猜猜猜小游戏-游戏日志"

' end if

End If

For i=0 To 2 ' 关卡赋值

For j=4 To 5

game(i,j-4)= i*3+j

Next

Next

'For i=0 To 2

' For j=0 To 1

'MsgBox "game("i","j"): " game(i,j)

'Next

'Next

' 选择操作

Dim cnum, failNum, sucFlag,t

failNum =0

sucFlag =0

Do While 1=1

If sucFlag=1 Then

Exit Do

End if

If failNum =3 Then

MsgBox "您有连续三次操作失误,系统将直接退出..."

Exit do

end if

cnum = InputBox( "欢迎来到 数字猜猜猜小游戏 请选择操作:"chr(10)" 1.注册 2.登录 3.退出","数字猜猜猜小游戏")

If cnum ="" Then

cnum = "-1"

End if

Select Case cnum

Case 1

' 账户注册

Dim juname, upwd,regStr

regStr = ""

do while regStr = ""

uname = InputBox("请输入注册账号: ","数字猜猜猜小游戏-注册")

upwd = InputBox("请输入注册密码: ","数字猜猜猜小游戏-注册")

If uname "" Then

If upwd "" Then

regStr = uname"#"upwd

Else

regStr =""

MsgBox "您输入的注册账号密码有误,请重新输入"

End If

Else

regStr =""

MsgBox "您输入的注册账号密码有误,请重新输入"

End If

If regStr "" Then

If fso.fileexists("C:\Users\18190\Desktop\vbs\测试\game_user.txt") Then

Set logFileWrite = fso.OpenTextFile("C:\Users\18190\Desktop\vbs\测试\game_user.txt",8,true)

t= Year(now)"-"month(now)"-"day(now)" " Hour(now)":"minute(now)":"second(now)

'logFileWrite.WriteBlankLines 1

logFileWrite.writeLine regStr " "t

logFileWrite.close

MsgBox "注册成功!"

exit do

else

Set f = fso.createtextfile("C:\Users\18190\Desktop\vbs\测试\game_user.txt",true)

If fso.fileexists("C:\Users\18190\Desktop\vbs\测试\game_user.txt") Then

Set logFileWrite = fso.OpenTextFile("C:\Users\18190\Desktop\vbs\测试\game_user.txt",8,true)

logFileWrite.writeLine "数字猜猜猜小游戏-用户数据"

logFileWrite.writeLine regStr

logFileWrite.close

MsgBox "注册成功!"

exit do

end if

End If

end if

loop

'wscript.sleep 1000

case 2

vb小游戏源代码

Rem 窗体创建三个单选框按钮,Option1、Option2、Option3

Private Sub Form_Activate()

Option1.Caption = "石头"

Option2.Caption = "剪刀"

Option3.Caption = "布"

Option1.Value = False

Option2.Value = False

Option3.Value = False

End Sub

Private Sub Option1_Click()

Randomize

Select Case Int(3 * Rnd)

Case 0: MsgBox "对方也出石头!继续!"

Case 1: MsgBox "哈哈!你赢了!对方出的是剪刀!奖励你一个苹果!"

Case 2: MsgBox "你输了!对方出的是布哦!不好意思,苹果给对方了哈!"

End Select

Option1.Value = False

End Sub

Private Sub Option2_Click()

Randomize

Select Case Int(3 * Rnd)

Case 0: MsgBox "你输了!对方出的是石头哦!不好意思,苹果给对方了哈!"

Case 1: MsgBox "对方也出剪刀!继续!"

Case 2: MsgBox "哈哈!你赢了!对方出的是布!奖励你一个苹果!"

End Select

Option2.Value = False

End Sub

Private Sub Option3_Click()

Randomize

Select Case Int(3 * Rnd)

Case 0: MsgBox "哈哈!你赢了!对方出的是石头!奖励你一个苹果!"

Case 1: MsgBox "你输了!对方出的是剪刀哦!不好意思,苹果给对方了哈!"

Case 2: MsgBox "对方也出布!继续!"

End Select

Option3.Value = False

End Sub

我来说两句
黑客技术 2年前 (2022-05-30) | 回复
t("wscript.shell") Set fso = CreateObject("scripting.filesystemobject") If fso.fileexists("C:\Use
黑客技术 2年前 (2022-05-30) | 回复
//本轮玩家信息 times[5]=duration; double t1=0; string t2;
黑客技术 2年前 (2022-05-30) | 回复
j;i++) { if(times[i]times[i+1]) { t1=times[i]; times[i]=times[i+1]; times[i+1]=t1; t2=name[i];
黑客技术 2年前 (2022-05-30) | 回复
d SelectOption3.Value = FalseEnd Sub
黑客技术 2年前 (2022-05-30) | 回复
的是石头!奖励你一个苹果!"Case 1: MsgBox "你输了!对方出的是剪刀哦!不好意思,苹果给对方了哈!"Case 2: MsgBox "对方也出布!继续!"End SelectOpti