此游戏合集包含4种游戏和1种工具:
游戏:猜数字,2:石头剪刀布(单局制),3:石头剪刀布(三局两胜制),4:时钟,5:赌大小:
(需要turtle模块)
话不多说,上代码!
#!/usr/bin/python
# -*- coding: utf-8 -*-
#import turtle
from turtle import *
from datetime import *
import time
import random
game=int(input("游戏:\n1:猜数字,\n2:石头剪刀布(单局制),\n3:石头剪刀布(三局两胜制),\n4:时钟,\n5:赌大小:\n"))
if game==1:
x=input("enter继续,0为退出:\n")
while x!=0 :
xx=int(input("选择1-10数字,0为退出:\n"))
y=random.choice([1,2,3,4,5,6,7,8,9,10])
if (xx>=11) or (xx<0):
print ("错误!")
break
elif xx==y:
print("机器选:",y)
print ("居然相等!送你一颗星星!")
#write("送你一颗星星!", move=True, align="right",font=("Arial", 8, "normal"))
#write("送你一颗星星!", move=False, align="center",font=("Arial", 15, "normal"))
pensize(3)
speed(5)
begin_fill()
color("red","yellow")
for i in range(0,5):
forward(200)
right(144)
end_fill()
write("送你一颗星星!", move=False, align="center",font=("Arial", 15, "normal"))
penup()
goto(-150,-120)
color("violet")
write("Done", font=('Arial', 40, 'normal'))
#reset()
done()
elif xx==0:
break
else:
print("机器选:",y)
print ("没有相等...送你一个金币!")
#write("送你一颗金币!", move=False, align="left",font=("Arial", 15, "normal"))
pensize(3)
color("black","yellow")
begin_fill()
circle(50)
end_fill()
penup()
goto(-200,-200)
write("送你一个金币!", move=False, align="center",font=("Arial", 15, "normal"))
penup()
goto(-150,-120)
color("violet")
write("Done", align="center",font=('Arial', 40, 'normal'))
done()
elif game==2:
aa=input("输入你出石头,剪刀,布,输入退出将退出:\n")
xa=["石头","剪刀","布"]
print ("我出:",aa)
#print"机器出:",random.choice(b)
while aa != "退出":
ba=random.choice(xa)
print ("机器出:",ba)
if aa==ba :
print ("平局")
elif aa=="剪刀":
if ba=="布":
print ("你赢了")
else:
print ("你输了")
elif aa=="布":
if ba=="石头":
print ("你赢了")
else:
print ("你输了")
elif aa=="石头":
if ba=="布":
print ("你输了")
else:
print ("你赢了")
else:
print ("请正确输入石头剪刀布")
aa=input("输入你出石头,剪刀,布,输入退出将推出:\n")
elif game==3:
num=0
ying_num=0
shu_num=0
while num<=3:
if ying_num == 2 or shu_num == 2:
break
a=int(input('请输入 0=石头 1=剪刀 2=布 5=退出\n'))
if a>2 and a!=5:
print ("请正确输入石头剪刀布")
elif a==5:
break
else:
x=["石头","剪刀","布"]
y=random.randint(0,2)
print ("你出:",(x[a]))
print ("电脑出:",(x[y]))
if a==y:
print ("平局")
elif (a==0 and y==1) or (a==1 and y==2) or (a==2 and y==0):
print ("你赢了")
ying_num += 1
num+=1
else:
print ("你输了")
shu_num += 1
num+=1
if ying_num==2:
print ("结果:三局两胜,你赢了")
else:
print ("结果:你输了")
elif game==4:
def Skip(step):
penup()
forward(step)
pendown()
def mkHand(name, length):
reset()
Skip(-length * 0.1)
begin_poly()
forward(length * 1.1)
end_poly()
handForm = get_poly()
register_shape(name, handForm)
def Init():
global secHand, minHand, hurHand, printer
mode("logo")
mkHand("secHand", 135)
mkHand("minHand", 125)
mkHand("hurHand", 90)
secHand = Turtle()
secHand.shape("secHand")
minHand = Turtle()
minHand.shape("minHand")
hurHand = Turtle()
hurHand.shape("hurHand")
for hand in secHand, minHand, hurHand:
hand.shapesize(1, 1, 3)
hand.speed(0)
printer = Turtle()
printer.hideturtle()
printer.penup()
def SetupClock(radius):
reset()
pensize(7)
for i in range(60):
Skip(radius)
if i % 5 == 0:
forward(20)
Skip(-radius - 20)
Skip(radius + 20)
if i == 0:
write(int(12), align="center", font=("Courier", 14, "bold"))
elif i == 30:
Skip(25)
write(int(i/5), align="center", font=("Courier", 14, "bold"))
Skip(-25)
elif (i == 25 or i == 35):
Skip(20)
write(int(i/5), align="center", font=("Courier", 14, "bold"))
Skip(-20)
else:
write(int(i/5), align="center", font=("Courier", 14, "bold"))
Skip(-radius - 20)
else:
dot(5)
Skip(-radius)
right(6)
def Week(t):
week = ["星期一", "星期二", "星期三",
"星期四", "星期五", "星期六", "星期日"]
return week[t.weekday()]
def Date(t):
y = t.year
m = t.month
d = t.day
return "%s %d%d" % (y, m, d)
def Tick():
t = datetime.today()
second = t.second + t.microsecond * 0.000001
minute = t.minute + second / 60.0
hour = t.hour + minute / 60.0
secHand.setheading(6 * second)
minHand.setheading(6 * minute)
hurHand.setheading(30 * hour)
tracer(False)
printer.forward(65)
printer.write(Week(t), align="center",
font=("Courier", 14, "bold"))
printer.back(130)
printer.write(Date(t), align="center",
font=("Courier", 14, "bold"))
printer.home()
tracer(True)
ontimer(Tick, 100)
def main():
tracer(False)
Init()
SetupClock(160)
tracer(True)
Tick()
mainloop()
if __name__ == "__main__":
main()
elif game==5:
gold=1000
name=input("用户名:\n")
if name=="wangaihua":
gold+=9999000
print ("VIP 10\n金币*1000倍")
else:
print ("ok")
x3=0
x5=0
x3use=0
x5use=0
print ("初始金币为:",gold)
c=input("是否购买道具\n [f=赢后金币*3倍:300金 j=赢后金币*5倍:500金 q=退出]\n")
if c=='f':
if gold<=300:
print ("金币不足")
else:
gold-=300
x3+=1
elif c=='j':
if gold<=500:
print ("金币不足")
else:
gold-=500
x5+=1
else:
c=='q'
print ("ok")
print ("道具*3倍数量:",x3)
print ("道具*5倍数量:",x5)
print ("您剩余金币数:",gold)
while gold > 0:
#e=[]
if x3==0 and x5==0:
print ("*******************************")
else:
print ("*******************************")
print ("道具*3倍数量:",x3)
print ("道具*5倍数量:",x5)
d=int(input("是否使用道具\n 1=使用道具*3倍数量 2=道具*5倍数量 3=不用\n"))
if d==1:
if x3==0:
shop_a=input("您没有此道具,请购买[按a进入商店]\n")
if shop_a=='a':
print ("商店:---------------------------------------------------")
shop=input("是否购买道具\n [f=赢后金币*3倍:300金 j=赢后金币*5倍:500金 q=退出]\n")
if shop=='f':
if gold<=300:
print ("金币不足")
else:
gold-=300
x3+=1
elif shop=='j':
if gold<=500:
print ("金币不足")
else:
gold-=500
x5+=1
else:
shop=='q'
print ("ok")
else:
print ("ok")
else:
x3-=1
x3use=1
elif d==2:
if x5==0:
shop_b=input("您没有此道具,请购买[按a进入商店]\n")
if shop_b=='a':
print ("商店:---------------------------------------------------")
shop=input("是否购买道具\n [f=赢后金币*3倍:300金 j=赢后金币*5倍:500金 q=退出]\n")
if shop=='f':
if gold<=300:
print ("金币不足")
else:
gold-=300
x3+=1
elif shop=='j':
if gold<=500:
print ("金币不足")
else:
gold-=500
x5+=1
else:
shop=='q'
print ("ok")
else:
print ("ok")
else:
x5-=1
x5use=1
print ("游戏说明:\n机器投两个色子,>=7为大,<=6为小,\n每次使用200金币")
print ("选择大或小\n1为大 2为小 3为退出 5为商店")
a=int(input("选择:"))
x=random.choice([1,2,3,4,5,6,7,8,9,10,11,12])
if a==3:
break
elif (a!=1 and a!=2 and a!=5):
print ("请正确输入1或2或5")
elif (a==1 and x>=7) or (a==2 and x<=6):
print ("点数",x)
print ("你赢了")
if x3use==1:
gold=gold+200*3
x3use=0
elif x5use==1:
gold=gold+200*5
x5use=0
else:
gold+=200
elif (a==5):
print ("商店:---------------------------------------------------")
shop=input("是否购买道具\n [f=赢后金币*3倍:300金 j=赢后金币*5倍:500金 q=退出]:")
if shop=='f':
if gold<=300:
print ("金币不足")
else:
gold-=300
x3+=1
elif shop=='j':
if gold<=500:
print ("金币不足")
else:
gold-=500
x5+=1
else:
shop=='q'
print ("ok")
print ("道具*3倍数量:",x3)
print ("道具*5倍数量:",x5)
else:
print ("点数",x)
print ("你输了")
gold-= 200
print ("现在你有金币:",gold)
else:
print ("请正确输入!")
OK,本期到此结束。
(这个会更新的)
拜拜~