Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- theBoard = {'T-L': ' ', 'T-M': ' ', 'T-R': ' ',
- 'M-L': ' ', 'M-M': ' ', 'M-R': ' ',
- 'L-L': ' ', 'L-M': ' ', 'L-R': ' '}
- def printBoard(board):
- print('-------')
- print('|' + board['T-L'] + '|' + board['T-M'] + '|' + board['T-R'] + '|')
- print('|' + '-+-+-' + '|')
- print('|' + board['M-L'] + '|' + board['M-M'] + '|' + board['M-R'] + '|')
- print('|' + '-+-+-' + '|')
- print('|' + board['L-L'] + '|' + board['L-M'] + '|' + board['L-R'] + '|')
- print('-------')
- def playAgain() :
- print('Do you want to play again?')
- again = 0
- while True:
- print('Press: Y for rematch ; E for exit')
- again = input()
- if again == 'Y':
- turn = 'X'
- theBoard = {'T-L': ' ', 'T-M': ' ', 'T-R': ' ',
- 'M-L': ' ', 'M-M': ' ', 'M-R': ' ',
- 'L-L': ' ', 'L-M': ' ', 'L-R': ' '}
- break
- if again == 'y':
- turn = 'X'
- theBoard = {'T-L': ' ', 'T-M': ' ', 'T-R': ' ',
- 'M-L': ' ', 'M-M': ' ', 'M-R': ' ',
- 'L-L': ' ', 'L-M': ' ', 'L-R': ' '}
- break
- elif again == 'E':
- sys.exit()
- elif again == 'e':
- sys.exit()
- else:
- continue
- turn = 'X'
- while True:
- printBoard(theBoard)
- print('Turn for ' + turn + '. Where do you want to place your ' + turn + '?')
- move=input()
- while True:
- if ' ' in theBoard[move]:
- theBoard[move] = turn
- break
- else:
- print('This spot is taken! try something else')
- print('Where do you want to place your ' + turn + '?')
- move=input()
- continue
- if turn in (theBoard['T-L'] and theBoard['T-M'] and theBoard['T-R']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn in (theBoard['M-L'] and theBoard['M-M'] and theBoard['M-R']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn in (theBoard['L-L'] and theBoard['L-M'] and theBoard['L-R']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn in (theBoard['T-L'] and theBoard['M-M'] and theBoard['L-R']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn in (theBoard['L-L'] and theBoard['M-M'] and theBoard['T-R']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn in (theBoard['T-L'] and theBoard['M-L'] and theBoard['L-L']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn in (theBoard['T-M'] and theBoard['M-M'] and theBoard['L-M']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn in (theBoard['T-R'] and theBoard['M-R'] and theBoard['L-R']):
- print('Result of the game:')
- printBoard(theBoard)
- print('Player ' + turn + ' won the game!')
- playAgain()
- if turn == 'X':
- turn = '0'
- else:
- turn = 'X'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement