admin管理员组文章数量:1794759
小学生python编程小游戏,三子相连算赢
import turtle turtle.bgcolor("black") turtle.pencolor("white") turtle.pensize(3) turtle.penup() turtle.goto(-200,80) turtle.pendown() turtle.goto(200,80) turtle.penup() turtle.goto(-200,-80) turtle.pendown() turtle.goto(200,-80) turtle.penup() turtle.goto(-80,200) turtle.pendown() turtle.goto(-80,-200) turtle.penup() turtle.goto(80,200) turtle.pendown() turtle.goto(80,-200) x=[-140,0,140,-140,0,140,-140,0,140] y=[140,140,140,0,0,0,-140,-140,-140] def huayuan1(a): turtle.penup() turtle.goto(x[a],y[a]-30) turtle.pendown() turtle.circle(30) def huayuan2(a): turtle.penup() turtle.goto(x[a],y[a]-30) turtle.pendown() turtle.begin_fill() turtle.color("white") turtle.circle(30) turtle.end_fill() begin=1#游戏开始 b=[2,3,4,5,6,7,8,9,10] while begin==1: print("请输入白棋下的位置:0-8") i=int(input()) b[i]=0 huayuan2(i) print("请输入黑棋下的位置:0-8") j=int(input()) b[j]=1 huayuan1(j) if b[0]==b[1] and b[1]==b[2]: begin=0 if b[0]==0: print("白棋胜") else: print("黑棋胜") if b[0]==b[4] and b[4]==b[8]: begin=0 if b[0]==0: print("白棋胜") else: print("黑棋胜") if b[0]==b[3] and b[3]==b[6]: begin=0 if b[0]==0: print("白棋胜") else: print("黑棋胜") if b[6]==b[7] and b[7]==b[8]: begin=0 if b[6]==0: print("白棋胜") else: print("黑棋胜") if b[2]==b[5] and b[5]==b[8]: begin=0 if b[2]==0: print("白棋胜") else: print("黑棋胜") if b[2]==b[4] and b[4]==b[6]: begin=0 if b[2]==0: print("白棋胜") else: print("黑棋胜") turtle.done()
turtle.fillcolor(colorstring) 绘制图形的填充颜色
turtle.begin_fill() 准备开始填充图形
turtle.end_fill() 填充完成
turtle.hideturtle() 隐藏画笔的turtle形状
turtle.showturtle() 显示画笔的turtle形状
urtle.pendown() 移动时绘制图形,缺省时也为绘制
turtle.goto(x,y) 将画笔移动到坐标为x,y的位置
turtle.penup() 提起笔移动,不绘制图形,用于另起一个地方绘制
turtle.circle() 画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆
if语句
while语句
版权声明:本文标题:小学生python编程小游戏,三子相连算赢 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686834242a108277.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论