一、逻辑算法
1. 用户出牌
2. 计算机出牌
3. 判断胜负方法
4. 循环步骤1到3
二、UI设计Unity部分
1、创建新的项目, 规范资源管理:在Project(项目)视图中导入并分类整理游戏资源。资源导入及文件夹创建如下:
2、在Hierarchy层级视图中新建幕布Canvas,如下图:
3、如下图,选中Panel(面板)右键在UI选项中创建四个Image(界面图片)和三个Button(用户点击事件)及text文本:
4、逐个选中Image,在Inspecter(检视图)中关联图片。如下图:
5、同理选中Button,关联图片。最后结果如下:
三、版本迭代v1
1. 场景跳转
2. 启动游戏
3. 场景设置
4.游戏主逻辑
四、完整代码
https://github.com/petergjh/shitoujiandaobu.git
五、用python实现方法一:
#!/usr/bin/env python
#coding: utf8
import random
import sys
allList = ['石头', '剪刀', '布']
gDict = {'石头':0, '剪刀':1, '布':2}
prompt = """(0)石头
(1)剪刀
(2)布
请选择对应的数字:"""
chnum = raw_input(prompt) #这里prompt可以定义为变量,同时输入的时候有提示
if chnum not in '012': #注意输入的为字符串,需要强转类型
print 'Invalid Input!'
sys.exit(1) #使用sys.exit(1)退出
uchoice = allList[int(chnum)] #在allList里面找出人工输入对应的字串
cchoice = random.choice(allList) #让电脑随机产生一个allList里面的字串
print '您选择了:',uchoice,'\n电脑选择了:',cchoice
if uchoice == cchoice: #两个字串相等就是平局
print '平局!'
elif (gDict[uchoice]-gDict[cchoice])==-1 or (gDict[uchoice]-gDict[cchoice])==2: #gDict是一个字典类型,根据字串又转换为对应的数字
print '你赢了!'
else:
print '你输了!'
方法二:
import random
items=['rock','paper','scissors'] #电脑可能出的:剪刀,石头或者布
winrounds=0; #初始化赢的局数
loserounds=0; #初始化输的局数
ifContinue='yes' #用于结束后判断是否再来一局
while ifContinue=='yes': #是yes的情况下运行
for rounds in range(1,4) : #一共3局
print("1.rock 2.paper 3.scissors.\ninput number:")
my=int(input()) #从键盘读取用户输入的数字,代表剪刀石头或者布
bot=random.choice(items); #电脑随机出
if my==1 and bot=='scissors': #下面是所有输赢情况,写的有点太繁琐,不知道日后会不会想出更加简洁的写法
print("\nround "+str(rounds)+" :\n"+str(bot)+". you win!\n")
winrounds+=1 #赢的时候,赢的局数+1,输的时候,输的局数+1,平局不计
elif my==1 and bot=='paper':
print("\nround "+str(rounds)+" :\n"+str(bot)+". you lose!\n")
loserounds+=1
elif my==1 and bot=='rock':
print("\nround "+str(rounds)+" :\n"+str(bot)+". we are even.\n")
elif my==2 and bot=='scissors':
print("\nround "+str(rounds)+" :\n"+str(bot)+". you lose!\n")
loserounds+=1
elif my==2 and bot=='paper':
print("\nround "+str(rounds)+" :\n"+str(bot)+". we are even.\n")
elif my==2 and bot=='rock':
print("\nround "+str(rounds)+" :\n"+str(bot)+". you win!\n")
winrounds+=1
elif my==3 and bot=='scissors':
print("\nround "+str(rounds)+" :\n"+str(bot)+". we are even.\n")
elif my==3 and bot=='paper':
print("\nround "+str(rounds)+" :\n"+str(bot)+". you win!\n")
winrounds+=1
elif my==3 and bot=='rock':
print("\nround "+str(rounds)+" :\n"+str(bot)+". you lose!\n")
loserounds+=1
print("game over!\nyou win "+str(winrounds)+" rounds. you lose "+ str(loserounds)+" rounds.")
if winrounds>loserounds : #3局2胜制
print("WINNER")
elif winrounds
