-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtictactoe.py
49 lines (35 loc) · 1.38 KB
/
tictactoe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Simple Tic-Tac-Toe game to practice Object-oriented Python
print "Welcome to the tic tac toe"
class Board(object):
def __init__(self):
self.boardarray = [1,2,3,4,5,6,7,8,9]
def showBoard(self):
print "{0} - {1} - {2}".format(self.boardarray[0], self.boardarray[1], self.boardarray[2])
print "{0} - {1} - {2}".format(self.boardarray[3], self.boardarray[4], self.boardarray[5])
print "{0} - {1} - {2}".format(self.boardarray[6], self.boardarray[7], self.boardarray[8])
def addLetter(self, letter, location):
if self.boardarray[int(location)-1] != "x" or self.boardarray[int(location)-1] != "o":
self.boardarray[int(location)-1] = str(letter)
newboard = Board()
letter = ""
while letter != "q":
letter = raw_input("Please select (x): x or (o): o ")
if letter == "x":
location = raw_input("Where would you like to place the letter? (1-9) ")
elif letter == "o":
location = raw_input("Where would you like to place the letter? (1-9) ")
else:
print "You messed up our game, jerk"
newboard.addLetter(letter, location)
newboard.showBoard()
# def letterSelection(letter, location):
# while letter != 'q':
# if letter == 'x':
# # newboard.addLetter(letter, location)
# # newboard.showBoard()
# # if letter == 'o':
# # newboard.addLetter(letter, location)
# # newboard.showBoard()
# newboard = Board()
# # letterSelection(letter, location)
# newboard.showBoard()