私はPythonクラスの課題を扱っています。私たちは、Bejewledゲームに再帰関数を追加しようとしています。私は正直なところ、紛失しているし、私の再帰的な機能の中で次に何を加えるべきか分からない。Bejewledゲームに再帰関数を追加する
import turtle
import random
turtle.setup(800,600)
window = turtle.Screen()
t = turtle.Turtle()
t.speed('fastest')
def drawDot(t, x, y, diameter, colorP):
t.up()
t.goto(x, y)
t.pencolor(colorP)
t.dot(diameter)
def drawboard(t, x, y, diameter,board):
for i in range(len(board)):
for j in range(len(board[i])):
drawDot(t, x, y, diameter + 5, 'black')
drawDot(t, x, y, diameter, board[i][j])
x = x + 60
y = y - 50
x = -300
def shuffleboard(t, x, y, diameter, line):
for i in range(len(line)):
for j in range(len(line[i])):
drawDot(t, x, y, diameter + 5, 'black')
drawDot(t, x, y, diameter, line[i][j])
x = x + 60
y = y - 50
x = -300
def randomColor():
randomColor = ['ivory', 'snow', 'gold', 'sky blue', 'indian red', 'slate gray', 'orange']
num = random.randint(0,6)
color = randomColor[num]
return color
def generateBoard():
board = []
for r in range(10):
row = []
for i in range(10):
color = randomColor()
row.append(color)
board.append(row)
return board
t1 = turtle.Turtle()
x = -300
y = 240
diameter = 20
letterX = -300
letterY = 260
for r in range(10):
t1.penup()
t1.goto(letterX, letterY)
t1.write(chr(r+ord('A')), move = False, align = 'center', font = ('Arial', 24, "normal"))
letterX += 60
letterX = -300
for r in range(10):
t1.penup()
t1.goto(letterX - 35, letterY - 40)
t1.write(r + 1, move = False, align = "center", font = ('Arial', 24, "normal"))
letterY -= 50
t1.hideturtle()
start = input('previous board? (Y/N) ')
if start == "N":
aList=[]
board = generateBoard()
generateBoard()
drawboard(t, x, y, 25, board)
if start== "Y":
fileName = input('enter file name(.txt): ')
input_file=(fileName, 'r')
for i in input_file:
aList.append(i)
coordinate = input("enter your coordinate: ")
letter= coordinate[0]
number=int(coordinate[1:])
number=number-1
if letter == 'A':
letIndex = 0
if letter == 'B':
letIndex = 1
if letter == 'C':
letIndex = 2
if letter == 'D':
letIndex = 3
if letter == 'E':
letIndex = 4
if letter == 'F':
letIndex = 5
if letter == 'G':
letIndex = 6
if letter == 'H':
letIndex = 7
if letter == 'I':
letIndex = 8
if letter == 'J':
letIndex = 9
number = int(coordinate[1:])
number = number - 1
print(board[number][letIndex])
finalBoard = []
save = input("save current board? (Y/N) ")
if save == "Y":
outputFileName = input("enter output file: ")
output_file=open(outputFileName, "w")
board = str(board)
output_file.write(board)
output_file.close()
while save == "N":
coord = input("enter your coordinate: ")
letter = coord[0]
if letter == 'A':
letIndex = 0
if letter == 'B':
letIndex = 1
if letter == 'C':
letIndex = 2
if letter == 'D':
letIndex = 3
if letter == 'E':
letIndex = 4
if letter == 'F':
letIndex = 5
if letter == 'G':
letIndex = 6
if letter == 'H':
letIndex = 7
if letter == 'I':
letIndex = 8
if letter == 'J':
letIndex = 9
number = int(coordinate[1:])
number = number - 1
print(board[number][letIndex])
save = input('save and quit? (Y/N)')
if save == 'Y':
outputFileName = input('enter output file: ')
output_file=open(outputFileName, 'w')
for i in board:
finalBoard.append(i)
finalBoard = str(finalBoard)
output_file.write(finalBoard)
output_file.close()
checked = []
def recursive(coordinate, checked, board):
let = coord[0]
num = coord[1:]
num1 = num-1
intnum = int(num1)
topnum = intnum-1
bottomnum = intnum+1
letindex = ord(let)-65
rightlet = letindex+1
leftlet = letindex-1
newright = rightlet + 65
newleft = leftlet + 65
rightcharacter = chr(newright)
leftcharacter = chr(newleft)
topcoord = let+str(topnum)
bottomcoord = let+str(bottomnum)
leftcoord = leftcharacter+num
rightcoord = rightcharacter+num
topcolor = board[topnum][letindex]
bottomcolor = board[bottomnum][letindex]
leftcolor = board[intnum][leftlet]
rightcolor = board[intnum][rightlet]
coordcolor = board[intnum][letindex]
print(topcoord)
print(bottomcoord)
print(leftcoord)
print(rightcoord)
print(topcolor)
print(bottomcolor)
print(leftcolor)
print(rightcolor)
recursive(coordinate, checked, board)
あなたのやりたいことに関連する部分にコードを絞り込むことができますか? – MooingRawr
ようこそStackOverflowへ。ヘルプドキュメントの投稿ガイドラインを読み、それに従ってください。 [最小、完全で検証可能な例](http://stackoverflow.com/help/mcve)がここに適用されます。 MCVEコードを投稿して問題を正確に記述するまでは、効果的にお手伝いすることはできません。 StackOverflowは、コーディングまたはチュートリアルサービスではありません。 – Prune