Esempio n. 1
0
  def state_to_grid(self, prev_x_board=-1, prev_y_board=-1, prev_x_cell=-1, prev_y_cell=-1):
    board = self.state.boards
    for y_board in range(3):
      for x_board in range(3):

        # for this mini-grid, do i make buttons or dashes?
        will_make_buttons = self.will_buttons(y_board, x_board)

        g=Grid()
        g.resize(3, 3)
        g.setBorderWidth(2)
        g.setCellPadding(9)
        g.setCellSpacing(1)
        for y_cell in range(3):
          for x_cell in range(3):

            if board[y_board][x_board][y_cell][x_cell]['cell'] == 0:
              if will_make_buttons:
                if self.min_player == -1:
                  b = Button('Play 1 here.', self)
                else:
                  b = Button('Play %d here.' % (self.state.next_piece[2]), self)
                b.point = {'x_cell':x_cell, 'y_cell':y_cell, 'y_board': y_board, 'x_board': x_board}
              else:
                b = HTML('-')

            elif board[y_board][x_board][y_cell][x_cell]['cell'] == 1:
              if (prev_x_cell == x_cell and
                  prev_y_cell == y_cell and
                  prev_y_board == y_board and
                  prev_x_board == x_board):
                b = HTML('<p style="color:red">1</p>')
              else:
                b = HTML('1')
            elif board[y_board][x_board][y_cell][x_cell]['cell'] == 2:
              if (prev_x_cell == x_cell and
                  prev_y_cell == y_cell and
                  prev_y_board == y_board and
                  prev_x_board == x_board):
                b = HTML('<p style="color:red">2</p>')
              else:
                b = HTML('2')
            g.setWidget(y_cell, x_cell, b)

        self.add(g)
        self.g.setWidget(y_board, x_board, g)
Esempio n. 2
0
  def init(self):
    '''Initializes the grid on which the game is played.
    '''
    for y_board in range(3):
      for x_board in range(3):

        g=Grid()
        g.resize(3, 3)
        g.setBorderWidth(2)
        g.setCellPadding(9)
        g.setCellSpacing(1)
        for x_cell in range(3):
          for y_cell in range(3):
            b = Button('Play here.', self)
            b.point = {'x_cell':x_cell, 'y_cell':y_cell, 'y_board': y_board, 'x_board': x_board}
            g.setWidget(y_cell, x_cell, b)

        self.add(g)
        self.g.setWidget(y_board, x_board, g)
Esempio n. 3
0
 def state_to_grid(self, state, game_over=False, over_message=''):
   if over_message:
     self.game_resolution.setText(over_message)
     self.game_resolution.setVisible(True)
   else:
     self.game_resolution.setVisible(False)
   board = state.board
   for y in range(3):
     for x in range(3):
       if board[y][x] == 0:
         if not game_over:
           b = Button('Press', self)
           b.point = {'x':x, 'y':y}
           self.g.setWidget(y, x, b)
         else:
           self.g.setText(y, x, '-')
       elif board[y][x] == '1':
         self.g.setText(y, x, '1')
       elif board[y][x] == '2':
         self.g.setText(y, x, '2')
       else:
         print 'state_to_grid exception'
Esempio n. 4
0
 def init(self):
   for y in range(3):
     for x in range(3):
       b = Button('Press', self)
       b.point = {'x':x, 'y':y}
       self.g.setWidget(y, x, b)