Skip to content

Commit

Permalink
done for now
Browse files Browse the repository at this point in the history
  • Loading branch information
gigatexal committed Jun 16, 2016
1 parent 2a7a77e commit 28ef290
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions teachingpython/tic-tac-toe/game.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
class tictactoe():
class tictactoe:
def __init__(self):
self.MAXPLAYERS = 2
self.board = {1: ['*', '*', '*'],
2: ['*', '*', '*'],
3: ['*', '*', '*']}
self.placement = (0,0)
self.placement = (1,0)#top right most entry key or row 1, array item 0
self.players = []
self.is_playable = self.num_empty_squares()


def get_players(self):
for i in range(0, self.MAXPLAYERS):
question = 'Please enter in your name player ' + str(i+1) + ': '
self.players.append(input(question).strip())

def placements(self,row,col): #make a __function
self.placement = (row,col)



def get_inputs(self):
'''
row = input("Enter in a row (1 - 3): ").strip()
col = input("Enter in a column (1-3): ").strip()
'''

try:
'''
row = int(row)
col = int(col)
'''
row,col = self.placement
if row > 0 and row <=3 and col > 0 and col <= 3:
self.placement = (row,col)
else:
self.get_inputs()
#else:
# self.get_inputs()
except ValueError:
print("Please enter in an integer for row and column, like 1 instead of 1.0 "
"\n and not A or a or any other letter(s)")
self.get_inputs()
#self.get_inputs()

def place(self, token):
self.get_inputs()
row, col = self.placement
col -= 1 #hack to deal with the indexes start at 0
if self.board[row][col] == '*':
self.board[row][col] = token
else:
Expand All @@ -58,13 +67,17 @@ def num_empty_squares(self):
num_empty += 1
return num_empty

#make this part of it's own object?


#rudimentary tests
def main():
game = tictactoe()
game.place('x')
game.show_board()
for i in range(1,4):
for j in range(0,3):
game.placements(i,j)
game.place('x')
game.show_board()


main()

0 comments on commit 28ef290

Please sign in to comment.