简体   繁体   English

乌龟的Python ticTacToe游戏

[英]Python ticTacToe game with turtle

I am working on a TicTacToe game for a class assignment, there are places where I am stuck and could use some help...the game should be able to draw Xs and Os with in grids and execute a full game here is my code 我正在为班级作业制作TicTacToe游戏,在某些地方我被困住了并且可以使用一些帮助...该游戏应该能够在网格中绘制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")

This is the work I have so far, I am kind of lost in regards to what to do next. 到目前为止,这是我的工作,我对下一步的工作感到迷茫。

I took the code, made it work, and figured out what to do next. 我获取了代码,使其正常工作,并弄清楚下一步该怎么做。 The first thing I would do is set up a board using Turtle() functions. 我要做的第一件事是使用Turtle()函数设置一个板。 I would hide the turtle using Turtle.ht() , then make lines, and figure out the region that each square is in. using if loops, make 'buttons' or spaces where, if pressed, will be an X or an O . 我将使用Turtle.ht()隐藏乌龟,然后进行线条Turtle.ht() ,并找出每个正方形所在的区域。使用if循环,制作“按钮”或空格(如果按下,则为XO Then using Turtle.forward() , Turtle.right() , Turtle.back() , and Turtle.left() make X 's and O 's. 然后使用Turtle.forward()Turtle.right()Turtle.back()Turtle.left()使XO成为X Also, fix your indentations, that will throw several errors, and add from turtle import * . 同样,修复您的缩进,这将引发一些错误,并from turtle import *添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM