Example #1
0
class Play:
  def __init__(self):
    self.game = Game()

  def start(self):
    self.reset()
    print "Welcome to Connect Four!"
    while not self.over():
      self.nextTurn()
    if self.won():
      print str(self.player) + " has won! Congratulations!"
    elif self.drawn():
      print "It was a draw. Sorry :/"
    print self.showBoard()
    
  def nextTurn(self):
    self.player = self.current()
    print str(self.player) + " to move"
    print self.showBoard()
    move = self.getMove()
    self.place(move)

  def getMove(self):
    col = raw_input("Choose your Column with a number from 1 to 7: ")
    while not self.valid(col):
      col = raw_input("Sorry, that wasn't valid: ")
    return col

  def place(self, move):
    move = int(move)
    self.game.nextDrop(move)
      
  def valid(self, col):
   if col in "1234567":
     return self.game.valid(int(col))
   return False

  def drawn(self):
    return self.game.isDraw()
 
  def won(self):
    return self.game.isWin()

  def over(self):
    return self.won() or self.drawn()

  def current(self):
    return self.game.nextPlayer

  def reset(self):
    self.game.setBoard()

  def showBoard(self):
    return self.game.showBoard()