使用flask运行python游戏并与之交互
我不熟悉python和Flask。我用python制作了一个简单的Tic-Tac-Toe游戏,它是通过CLI玩的。我希望能够使用我的树莓圆周率在网络浏览器上玩那个游戏使用flask运行python游戏并与之交互,python,html,flask,Python,Html,Flask,我不熟悉python和Flask。我用python制作了一个简单的Tic-Tac-Toe游戏,它是通过CLI玩的。我希望能够使用我的树莓圆周率在网络浏览器上玩那个游戏 我已经在pi上安装了Flask,并运行了一个基本的网页,我可以在局域网上访问它。我正在努力寻找一个关于如何从python游戏中获取输出并将其作为HTML显示在网页上的教程 此外,一旦显示python输出,我需要一种方法来使用网页将数据输入python脚本 一次只解决一个问题。有谁能推荐一种将python游戏输出为HTML的好
x1 = "-"
x2 = "-"
x3 = "-"
y2 = "-"
y3 = "-"
x2y2 = "-"
x2y3 = "-"
x3y2 = "-"
x3y3 = "-"
gameStatus = 0
player = "1"
symbol = "X"
choice = 0
error = 0
winner_status = 0
move_counter = 0
def test():
return "This is a test"
def check_winner(p, s):
winner = 0
if y3 == s and y2 == s and x1 == s:
print("Player " + p + " won!")
winner = 1
elif y3 == s and x2y3 == s and x3y3 == s:
print("Player " + p + " won!")
winner = 1
elif y3 == s and x2y2 == s and x3 == s:
print("Player " + p + " won!")
winner = 1
elif y2 == s and x2y2 == s and x3y2 == s:
print("Player " + p + " won!")
winner = 1
elif x1 == s and x2y2 == s and x3y3 == s:
print("Player " + p + " won!")
winner = 1
elif x1 == s and x2 == s and x3 == s:
print("Player " + p + " won!")
winner = 1
elif x1 == s and y2 == s and y3 == s:
print("Player " + p + " won!")
winner = 1
elif x2 == s and x2y2 == s and x2y3 == s:
winner = 1
print("Player " + p + " won!")
if x3 == s and x3y2 == s and x3y3 == s:
print("Player " + p + " won!")
winner = 1
return winner
print("Welcome to TikTacToe\nPress 1 to play\nPress 2 to quit")
menu = int(input())
if menu == 1:
gameStatus = 1
while gameStatus == 1:
print("It is player " + player + "'s turn\nSelect a position to place an " + symbol + " by using a number")
print("1 2 3\n4 5 6\n7 8 9")
choice = int(input("Select number:"))
move_counter += 1
if choice == 1:
if y3 == "-":
y3 = symbol
elif y3 != "-":
error = 1
if choice == 2:
if x2y3 == "-":
x2y3 = symbol
elif x2y3 != "-":
error = 1
if choice == 3:
if x3y3 == "-":
x3y3 = symbol
elif x3y3 != "-":
error = 1
if choice == 4:
if y2 == "-":
y2 = symbol
elif y2 != "-":
error = 1
if choice == 5:
if x2y2 == "-":
x2y2 = symbol
elif x2y2 != "-":
error = 1
if choice == 6:
if x3y2 == "-":
x3y2 = symbol
elif x3y2 != "-":
error = 1
if choice == 7:
if x1 == "-":
x1 = symbol
elif x1 != "-":
error = 1
if choice == 8:
if x2 == "-":
x2 = symbol
elif x2 != "-":
error = 1
if choice == 9:
if x3 == "-":
x3 = symbol
elif x3 != "-":
error = 1
print(y3, x2y3, x3y3 + "\n" + y2, x2y2, x3y2 + "\n" + x1, x2, x3)
winner_status = check_winner(player, symbol)
if winner_status == 1:
print("Do you want to play again?")
res = int(input("1. Yes\n2. No"))
if res == 1:
x1 = "-"
x2 = "-"
x3 = "-"
y2 = "-"
y3 = "-"
x2y2 = "-"
x2y3 = "-"
x3y2 = "-"
x3y3 = "-"
player = "2"
move_counter = 0
elif res == 2:
quit()
if move_counter == 9:
print("It's a draw, would you like to play again?")
ans = int(input("1. Yes\n2. No"))
if ans == 1:
x1 = "-"
x2 = "-"
x3 = "-"
y2 = "-"
y3 = "-"
x2y2 = "-"
x2y3 = "-"
x3y2 = "-"
x3y3 = "-"
player = "2"
move_counter = 0
elif ans == 2:
quit()
if error == 1:
print("This position has already been taken")
error = 0
elif error == 0:
if player == "1":
player = "2"
symbol = "O"
elif player == "2":
player = "1"
symbol = "X"
if menu == 2:
exit()
您是想让游戏通过互联网进行,还是仅仅显示结果?