游戏代码怎么写(游戏代码怎么写好看)
python简单小游戏代码 怎么用Python制作简单小游戏
1、Python猜拳小游戏代码:
2、import random #导入随机模块
3、
4、num = 1
5、yin_num = 0
6、shu_num = 0
7、while num 2:
12、 print('不能出大于2的值')
13、 else:
14、 data = ['石头', '剪刀', '布']
15、 com = random.randint(0, 2)
16、 print(您出的是{},电脑出的是{}.format(data[user], data[com]))
17、 if user == com:
18、 print('平局')
19、 continue
20、 elif (user == 0 and com == 1) or (user == 1 and com == 2) or (user == 2 and com == 0):
21、 print('你赢了')
22、 yin_num += 1
23、 else:
24、 print('你输了')
25、 shu_num += 1
26、 num += 1
27、Python数字炸弹小游戏代码:
28、import random
29、import time
30、
31、bomb = random.randint(1, 99)
32、print(bomb)
33、start = 0
34、end = 99
35、while 1 == 1:
36、
37、 people = int(input('请输入{}到{}之间的数:'.format(start, end)))
38、 if people bomb:
39、 print('大了')
40、 end = people
41、 elif people bomb:
42、 print('小了')
43、 start = people
44、 else:
45、 print('BOOM!!!')
46、 break
47、 print('等待电脑了输入{}到{}之间的数:'.format(start, end))
48、 time.sleep(1)
49、 com = random.randint(start + 1, end - 1)
50、 print('电脑输入:{}'.format(com))
51、 if com bomb:
52、 print('大了')
53、 end = com
54、 elif com bomb:
55、 print('小了')
56、 start = com
57、 else:
58、 print('BOOM!!!')
59、 break
怎么编写游戏代码
编写游戏代码的方法如下:
1、打开Flash后,选择新建actionscript;
2、文件选择导入到舞台,将需要被测试的素材导入到舞台中;
3、点击素材后,转化为影片剪辑,并点击属性为素材命名;
4、点击新建文件,新建一个as文件用于写代码;
5、在as层的第一帧右击选择动作;
6、在动作中编写鼠标点击,鼠标弹起,鼠标按下代码后关掉;
7、按CTRL加ENTER即可对游戏进行测试即可编写代码。
如何用C++编写一个小游戏
一个用C++编程的小游戏,可以实现的功能如下:
1、随机生成数字;
2、数字消除合并;
3、判定游戏结束;
一、游戏主体:
因为用C++写的,所以用了类,棋盘用了一个二维数组,m是棋盘规格,取了4。
class game
{
public:
? int i, j;
? game() {
? ? ? count1 = 0;
? ? ? for (i = 0; i m; i++)
? ? ? ? ? for (j = 0; j m; j++)
? ? ? ? ? ? ? chessboard[i][j] = 0;
? ? ? srand((unsigned)time(NULL));
? ? ? x = rand() % m;
? ? ? y = rand() % m;
? ? ? if (count1 == 1 || count1 == 0)
? ? ? ? ? chessboard[x][y] = 2;
? ? ? else
? ? ? ? ? chessboard[x][y] = 4;
? ? ? showchessboard();
? }//构造初始棋盘
? void add(int count1);//新增数字
? void showchessboard();//显示棋盘
? void up();
? void down();
? void left();
? void right();
? bool gameover();//游戏失败
private:
? int chessboard[m][m];
? int x, y, count1, count2, temp1, temp2, k;//c1-连消,c2-空位标记,t1-判连消,t2,k-临时变量
? bool flag;//判消
};
二、随机生成数字
void game::add(int count1)
{
? for (i = 0; i m; i++)
? ? ? for (j = 0; j m; j++)
? ? ? {
? ? ? ? ? if (chessboard[i][j] == 0)
? ? ? ? ? ? ? goto loop;
? ? ? }
? showchessboard();
? return;
loop:srand((unsigned)time(NULL));
? do {
? ? ? x = rand() % m;
? ? ? y = rand() % m;
? } while (chessboard[x][y] != 0);
? if (count1 2)
? ? ? chessboard[x][y] = 2;
? else
? ? ? chessboard[x][y] = 4;
? showchessboard();
}
三、数字消除合并
void game::up()
{
? temp1 = count1;
? flag = false;
? for (j = 0; j m; j++)
? ? ? for (i = 0; i m;)
? ? ? {
? ? ? ? ? for (; i 4 chessboard[i][j] == 0; i++); // 找非零值
? ? ? ? ? if (i == 4)
? ? ? ? ? ? ? break;
? ? ? ? ? else
? ? ? ? ? {
? ? ? ? ? ? ? for (k = i + 1; k 4 chessboard[k][j] == 0; k++);//找下一个非零值
? ? ? ? ? ? ? if (k == 4)
? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? else if (chessboard[i][j] == chessboard[k][j])//匹配
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? chessboard[i][j] *= 2;
? ? ? ? ? ? ? ? ? chessboard[k][j] = 0;
? ? ? ? ? ? ? ? ? i = k + 1;
? ? ? ? ? ? ? ? ? flag = true;
? ? ? ? ? ? ? }
? ? ? ? ? ? ? else if (chessboard[i][j] != chessboard[k][j] k 4)//不匹配
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? i = k;
? ? ? ? ? ? ? }
? ? ? ? ? }
? ? ? }
? for (j = 0; j m; j++)//排列棋盘
? ? ? for (i = 0, count2 = 0; i m; i++)
? ? ? {
? ? ? ? ? if (chessboard[i][j] != 0)
? ? ? ? ? {
? ? ? ? ? ? ? temp2 = chessboard[i][j];
? ? ? ? ? ? ? chessboard[i][j] = 0;
? ? ? ? ? ? ? chessboard[count2][j] = temp2;
? ? ? ? ? ? ? count2++;
? ? ? ? ? }
? ? ? }
}
四、判断游戏结束
bool game::gameover()
{
? if (flag)
? ? ? count1++;//判连消
? if (temp1 == count1)
? ? ? count1 = 0;//未消除,连消归零
? add(count1);
? for (i = m - 1, j = 0; j m; j++)//最后一行
? {
? ? ? if (j == m - 1)//右下角
? ? ? {
? ? ? ? ? if (chessboard[i][j] == 0)
? ? ? ? ? ? ? return false;
? ? ? ? ? else if (chessboard[i][j] == 2048)
? ? ? ? ? {
? ? ? ? ? ? ? cout "You Win~\n";
? ? ? ? ? ? ? return true;
? ? ? ? ? }
? ? ? }
? ? ? else
? ? ? {
? ? ? ? ? if (chessboard[i][j] == 0 || chessboard[i][j] == chessboard[i][j + 1])
? ? ? ? ? ? ? return false;
? ? ? ? ? else if (chessboard[i][j] == 2048)
? ? ? ? ? {
? ? ? ? ? ? ? cout "You Win~\n";
? ? ? ? ? ? ? return true;
? ? ? ? ? }
? ? ? }
? }
? for (i = 0, j = m - 1; i m; i++)//最后一列
? {
? ? ? if (i == m - 1)//右下角
? ? ? {
? ? ? ? ? if (chessboard[i][j] == 0)
? ? ? ? ? ? ? return false;
? ? ? ? ? else if (chessboard[i][j] == 2048)
? ? ? ? ? {
? ? ? ? ? ? ? cout "You Win~\n";
? ? ? ? ? ? ? return true;
? ? ? ? ? }
? ? ? }
? ? ? else
? ? ? {
? ? ? ? ? if (chessboard[i][j] == 0 || chessboard[i][j] == chessboard[i + 1][j])
? ? ? ? ? ? ? return false;
? ? ? ? ? else if (chessboard[i][j] == 2048)
? ? ? ? ? {
? ? ? ? ? ? ? cout "You Win~\n";
? ? ? ? ? ? ? return true;
? ? ? ? ? }
? ? ? }
? }
? for (i = 0; i m - 1; i++)
? ? ? for (j = 0; j m - 1; j++)
? ? ? {
? ? ? ? ? if (chessboard[i][j] == 2048)
? ? ? ? ? {
? ? ? ? ? ? ? cout "You Win!\n";
? ? ? ? ? ? ? return true;
? ? ? ? ? }
? ? ? ? ? else if (chessboard[i][j] == chessboard[i][j + 1] || chessboard[i][j] == chessboard[i + 1][j] || chessboard[i][j] == 0)
? ? ? ? ? ? ? return false;
? ? ? }
? cout "Game over.\n";
? return true;
}
扩展资料:
C++语言的程序因为要体现高性能,所以都是编译型的。但其开发环境,为了方便测试,将调试环境做成解释型的。
生成程序是指将源码(C++语句)转换成一个可以运行的应用程序的过程。如果程序的编写是正确的,那么通常只需按一个功能键,即可搞定这个过程。但是该过程实际上分成两个步骤。
第一步是对程序进行编译,这需要用到编译器(compiler)。编译器将C++语句转换成机器码(也称为目标码);
第二步就是对程序进行链接,这需要用到链接器(linker)。链接器将编译获得机器码与C++库中的代码进行合并。C++库包含了执行某些常见任务的函数(“函数”是子程序的另一种称呼)。
参考资料来源:
百度百科-C++
怎样用代码玩游戏
怎样用代码玩游戏如下:
1、通过参考不同的游戏,写出你想做的游戏的剧情和剧本。有很多类型的游戏。根据自己喜欢的游戏类型,参考不同的游戏,写出自己想做的游戏的剧情。
2、根据游戏的剧情和剧本,使用手绘软件绘制游戏人物的图形和背景。
3、通过建模软件,将平面图制作成三维模型效果。建模软件有很多种,通过建模软件可以将平面图形制作成三维模型效果。比如使用常用的建模软件3dmax。
4、学习游戏制作软件的操作,让制作游戏的效率更高。游戏制作的软件有很多种,比如使用Unity3D开发游戏,熟悉游戏制作软件的操作,这样制作会更快。制作结束便可以进行游戏玩耍。
编写游戏代码的方法如下:
1、打开Flash后,选择新建actionscript。
2、文件选择导入到舞台,将需要被测试的素材导入到舞台中。
3、点击素材后,转化为影片剪辑,并点击属性为素材命名。
4、点击新建文件,新建一个as文件用于写代码。
5、在as层的第一帧右击选择动作。
6、在动作中编写鼠标点击,鼠标弹起,鼠标按下代码后关掉。
7、按CTRL加ENTER即可对游戏进行测试即可编写代码。
制作游戏代码
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