5 Replies - 3303 Views - Last Post: 14 September 2012 - 07:00 AM Rate Topic: -----

#1 narutoninjakid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 15-November 11

Help. Python Tic-Tac-toe

Posted 13 September 2012 - 12:08 PM

how woudl i do this ?

Modify your function tttDrawGrid() to take a parameter cellSize. cellSize is the length of a side of a single square of the TicTacToe grid.

this is my tttDrawGrid() it draws a tic tac toe board

how would i do the cellsize thing i am so confused.
from turtle import*
def tttDrawBoard( ): 
    t = Turtle()
    t.width(10)
    t.color('blue')
    t.rt(90)
    t.fd(150)
    t.pencolor('white')
    t.rt(90)
    t.fd(50)
    t.pencolor('blue')
    t.rt(90)
    t.fd(150)
    t.bk(65)
    t.lt(90)
    t.fd(50)
    t.rt(180)
    t.fd(150)
    t.lt(180)
    t.fd(50)
    t.lt(90)
    t.fd(50)
    t.lt(90)
    t.fd(50)
    t.lt(180)
    t.fd(150)


This post has been edited by narutoninjakid: 13 September 2012 - 12:10 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Help. Python Tic-Tac-toe

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5907
  • View blog
  • Posts: 12,813
  • Joined: 16-October 07

Re: Help. Python Tic-Tac-toe

Posted 13 September 2012 - 12:28 PM

You find the value you want to be passed and replace it with a name. For instance, if you wanted the width passed:
def tttDrawBoard(lineWidth): 
    t = Turtle()
    t.width(lineWidth)
...



Now you can call the function with tttDrawBoard(3) and have a skinnier board.
Was This Post Helpful? 0
  • +
  • -

#3 narutoninjakid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 15-November 11

Re: Help. Python Tic-Tac-toe

Posted 13 September 2012 - 12:36 PM

View Postbaavgai, on 13 September 2012 - 12:28 PM, said:

You find the value you want to be passed and replace it with a name. For instance, if you wanted the width passed:
def tttDrawBoard(lineWidth): 
    t = Turtle()
    t.width(lineWidth)
...



Now you can call the function with tttDrawBoard(3) and have a skinnier board.


so what does it want me to pass ?
edit : i get it now

This post has been edited by narutoninjakid: 13 September 2012 - 12:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 narutoninjakid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 15-November 11

Re: Help. Python Tic-Tac-toe

Posted 13 September 2012 - 12:45 PM

Write a function named tttDrawX() that draws an x in one of the cells of the TicTacToe grid.
tttDrawMove takes four parameters:
i) a turtle to draw with
ii) the size of a single square of the TicTacToe grid,
iii) an int (0-2) that specifies the row,
iv) an int (0-2) that specifies the column.


i have to do this next how would i make my tic tac toe board into saome type of gridso i can have rows and columns ?
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7963
  • View blog
  • Posts: 13,581
  • Joined: 19-March 11

Re: Help. Python Tic-Tac-toe

Posted 13 September 2012 - 12:47 PM

A row is a list of columns. A board is a list of rows.
Was This Post Helpful? 0
  • +
  • -

#6 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5907
  • View blog
  • Posts: 12,813
  • Joined: 16-October 07

Re: Help. Python Tic-Tac-toe

Posted 14 September 2012 - 07:00 AM

This looked like a ton of fun.

A few turtle methods you NEED to know; pu ( penup ), pd ( pendown ), home ( reset your position ). Find them all here: http://docs.python.o...ary/turtle.html

Use functions for as much as possible. If you copy and paste the same code a lot, use a function.

e.g.
from turtle import *

def boardUpperLeft(t, squareSize):
	'''
	given the square size, move to the starting corner of a tic tac toe board
	'''
	# your code here

def cellUpperLeft(t, squareSize, row, col):
	'''
	move the the starting corner of a tic tac toe board cell
	'''
	# your code here

def tttDrawX(t, squareSize, row, col):
	# your code here

def tttDrawBoard(t, squareSize):
	def twoLines():
		# your code here
	
	t.color('blue')
	boardUpperLeft(t, squareSize)
	t.rt(90)
	twoLines()
	
	boardUpperLeft(t, squareSize)
	t.bk(squareSize*3)
	twoLines()
	
def main():
	t = Turtle()
	t.width(10)
	squareSize = 100
	tttDrawBoard(t, squareSize)
	tttDrawX(t, squareSize, 0, 0)
	tttDrawX(t, squareSize, 2, 2)
	mainloop()
	
main()



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1