
小学生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语句