Information=("="*8,"Programmer: Meng Zian","Tested on Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]","Date: November 1st, 2020\n","Current Python: "+version,"="*8)
HowToPlay=("+"*8,"Rules: two players play this tic-tac-toe game.","In a 3x3 grid, Player 1 draws a pattern into an empty grid and Player 2 draws another pattern in turns.","First player who draws 3 continuous patterns in a horizontal, vertical or diagonal line wins the game.","But with no continuous 3 patterns eventually, the game comes to a draw.","+"*8)
Key=("credits","rules")
defShow():
forIinHint:
print(I)
returnNone
defPlayerLog():
Query.Show()
forIinData.Log:
print(I)
print("<"*8)
returnNone
defCredits():
forIinQuery.Information:
print(I)
returnNone
defRules():
forIinQuery.HowToPlay:
print(I)
returnNone
defBegin():
whileTrue:
Data.Player1Circle=input('Player 1 - would you like to be circle or cross? Type "0" if you want to be cross: ')!="0"
print("Player 1 chooses to be circle!")ifData.Player1Circleelseprint("Player 1 chooses to be cross!")
ifinput('''Player 2 - do you agree with Player 1's decision? Type "0" if you want to REJECT: ''')=="0":
print("Player 2 rejects Player 1's decision!")
else:
break
whileTrue:
Data.Player1First=input('Player 1 - would you like to go first? Type "0" if you DO NOT want to go first: ')!="0"
print("Player 1 wants to go first!")ifData.Player1Firstelseprint("Player 1 wants to let Player 2 go first!")
ifinput('''Player 2 - do you agree with Player 1's decision? Type "0" if you want to REJECT: ''')=="0":
print("Player 2 rejects Player 1's decision!")
else:
break
print("Player 1 is circle, and Player 2 is cross.")ifData.Player1Circleelseprint("Player 1 is cross, and Player 2 is circle.")
print("Now it's Player 1's turn!")ifData.Player1Firstelseprint("Now it's Player 2's turn!")
Query.Show()
returnNone
classAction:
defPlayer1():
whileTrue:
AnswerStr=input("Player 1 - please draw into a grid: ")
ifAnswerStrinGridStr:
Answer=int(AnswerStr)
ifAnswerinGrid:
ifAnswerinData.Player1Grid:
Query.PlayerLog()
print("Player 1 - you have drawn into that grid!")
elifAnswerinData.Player2Grid:
Query.PlayerLog()
print("Player 1 - your opponent has drawn into that grid!")
Data.Log+=['{1:02d}/{2:02d}/{0} {3:02d}:{4:02d}:{5:02d} - Player 1 drew {6} to grid {7}'.format(CurrentTime[0],CurrentTime[1],CurrentTime[2],CurrentTime[3],CurrentTime[4],CurrentTime[5],"circle"ifData.Player1Circleelse"cross",Answer)]
returnNone
else:
Query.PlayerLog()
print("Player 1 - unknown out of range error, sorry but please try again.")
elifAnswerStr==Query.Key[0]:
Query.Credits()
elifAnswerStr==Query.Key[1]:
Query.Rules()
else:
Query.PlayerLog()
print("Player 1 - please input a valid integer in range!")
defPlayer2():
whileTrue:
AnswerStr=input("Player 2 - please draw into a grid: ")
ifAnswerStrinGridStr:
Answer=int(AnswerStr)
ifAnswerinGrid:
ifAnswerinData.Player2Grid:
Query.PlayerLog()
print("Player 2 - you have drawn into that grid!")
elifAnswerinData.Player1Grid:
Query.PlayerLog()
print("Player 2 - your opponent has drawn into that grid!")
Data.Log+=['{1:02d}/{2:02d}/{0} {3:02d}:{4:02d}:{5:02d} - Player 2 drew {6} to grid {7}'.format(CurrentTime[0],CurrentTime[1],CurrentTime[2],CurrentTime[3],CurrentTime[4],CurrentTime[5],"cross"ifData.Player1Circleelse"circle",Answer)]
returnNone
else:
Query.PlayerLog()
print("Player 2 - unknown out of range error, sorry but please try again.")
elifAnswerStr==Query.Key[0]:
Query.Credits()
elifAnswerStr==Query.Key[1]:
Query.Rules()
else:
Query.PlayerLog()
print("Player 2 - please input a valid integer in range!")