Python与屠呦呦的游戏

2024-04-19 09:05:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为一个班级作业做一个Tictakoe游戏,有些地方我被困了,需要一些帮助…游戏应该能够在网格中绘制Xs和Os,并执行一个完整的游戏 这是我的密码

import turtle
import math 
import random 

cellSize = 100
turtleWidth =10
gridColor  = 'Black'
xColor = 'Blue'
oColor = 'Red'
winColor = 'green'
drawColor = 'Gray'

winninTriples = ((0,1,2)

def onclick(x, y):
    print x, y

turtle.Screen().onscreenclick(onclick)
  #the grid is here 
def drawGrid(pen, length, xcoor, ycoor):
      startX = [xcoor,xcoor,xcoor+length, xcoor+(2*length)]
      endX = [xcoor+(3*length), xcoor+(3*length), xcoor+(length),xcoor+(2*length)]
      startY = [ycoor+(2*length),ycoor+length, ycoor, ycoor]
      endY = [ycoor+(2*length), ycoor+length, ycoor+(3*length),ycoor+(3*length)]
      for grid in range(4):
          p.up()
          p.goto(startX[grid],startY[grid])
          p.down()
          p.goto(endX[grid],endY[grid])

     pen = turtle.Turtle()       
     pen.width(5)
     drawGrid(pen,100,-40,-50)

     board = [0,1,2,
              3,4,5,
              6,7,8]


    def theWinnner(grid0,grid1,grid2,grid3,grid4,grid5,grid6,grid7,grid8):
        X = 'X wins'
        O = 'O wins'
        No = 'Draw'
        #this was a code that was given, I am supposed to add on to it and I am not sure how it can be modified and what should I put as the parameters when executing it? 
   def drawX(t,x,y,size):
       drawLine(t, x + size/4, y + size/4, x - size/4, y - size/4)
       drawLine(t, x - size/4, y + size/4, x + size/4, y - size/4)
   def drawO(t,x,y,size):
       t.cirle(size)


   def Move():
       y = input("Please choose a row:")
       x = input("Now please choose a column:")
       if x in ['0','1','2']  and y in ['0','1','2']:
          return("Your destination is " + y + " " + "and " + x)
       else:
          return("One or more of your dimensions is out of bounds")

我下一步要做的就是这样。在


Tags: andinimport游戏sizeisdefit
1条回答
网友
1楼 · 发布于 2024-04-19 09:05:20

我接受了代码,使之生效,并想出了下一步该怎么做。 我要做的第一件事是使用Turtle()函数设置一个板。我将使用Turtle.ht()隐藏海龟,然后画线,并计算出每个正方形所在的区域。使用if循环,生成“button”或空格,如果按下,将是XO。 然后使用Turtle.forward()Turtle.right()Turtle.back()、和{}制作X和{}。同时,修复你的缩进,这将抛出几个错误,并添加from turtle import *。在

相关问题 更多 >