示例#1
0
def interactive():
    '''Game interactive mode.

  Runs the full, user interactive Sudoku game,
  asking for the player input at each turn.
  '''
    matrix = [[0 for j in range(9)] for i in range(9)]
    tips = getFromFile('config.txt')
    addTips(tips, matrix)
    if validGame(matrix):
        i = 0
        msg = util.ok('Entre sua jogada:')
        errorcleanup = [0, 0, 0]
        while i < (81 - len(tips)):
            util.clearConsole()
            print(board.build(matrix, tips))
            print(msg)
            r, c, n = errorcleanup
            if matrix[r][c] < 0:
                matrix[r][c] = n
            user_input = formatInput(input())
            row, col, num = map(int, user_input.split(':'))
            inTips = False
            for t in tips:
                if user_input[:3] == t[:3]:
                    inTips = True
            if inTips:
                msg = util.error('As dicas nao podem ser sobrescritas.')
            elif validNum(matrix, num, row, col):
                msg = util.ok('Entre sua jogada:')
                if matrix[row][col] == 0 and num != 0:
                    i += 1
                if matrix[row][col] != 0 and num == 0:
                    i -= 1
                matrix[row][col] = num
            else:
                if row < 9 and col >= 0 and 10 > num > 0:
                    errorcleanup = row, col, matrix[row][col]
                    matrix[row][col] = -num
                msg = util.error(
                    'Jogada invalida. Por favor, jogue novamente.')
        util.clearConsole()
        print(board.build(matrix, tips))
        print(util.ok('Parabens, voce concluiu o jogo!'))
        e = input('    Jogar novamente? (Y/n)\n')
        if e.lower() == 'y' or e == '':
            interactive()
    else:
        util.clearConsole()
        print(board.build(matrix, tips))
        print(util.error('Arquivo de configuracoes invalido.'))
示例#2
0
def duty(req, res):
  req.params = {
    'device': req.url_match.group(1)
  }
  yield from req.read_form_data()
  req.params['value'] = int(req.form['value'][0])
  model.duty(req.params)
  yield from ok(res)
示例#3
0
def update(req, res):
    yield from req.read_form_data()
    req.params = {
        'device': req.url_match.group(1),
        'pin': int(req.form['pin'][0]),
        'default': int(req.form['default'][0])
    }
    model.update(req.params)
    yield from ok(res)
示例#4
0
def update(req, res):
  yield from req.read_form_data()
  req.params = {
    'device': req.url_match.group(1),
    'pin': int(req.form['pin'][0]),
    'default': int(req.form['default'][0])
  }
  model.update(req.params)
  yield from ok(res)
示例#5
0
def list(req, res):
    yield from ok(res, model.list())
示例#6
0
def duty(req, res):
    req.params = {'device': req.url_match.group(1)}
    yield from req.read_form_data()
    req.params['value'] = int(req.form['value'][0])
    model.duty(req.params)
    yield from ok(res)
示例#7
0
def set(req, res):
    yield from req.read_form_data()
    model.set(req.form)
    yield from ok(res)
示例#8
0
def scan(req, res):
    nets = model.scan()
    yield from ok(res, nets)
示例#9
0
 def read(self, req, res):
     yield from ok(res, self.model.get(req.params['name']))
示例#10
0
def scan(req, res):
  nets = model.scan()
  yield from ok(res, nets)
示例#11
0
def get(req, res):
  req.parse_qs()
  yield from ok(res, model.load(req.form['name'][0]))
示例#12
0
def reset(req, res):
  yield from ok(res)
  model.reset()
示例#13
0
def read(req, res):
  yield from ok(res, model.read(req.params))
示例#14
0
def list(req, res):
  yield from ok(res, model.list())
示例#15
0
def read(req, res):
    yield from ok(res, model.read(req.params))
示例#16
0
def set(req, res):
  yield from req.read_form_data()
  model.set(req.form)
  yield from ok(res)
示例#17
0
 def list(self, req, res):
     yield from ok(res, self.model.list())
示例#18
0
 def list(self, req, res):
   yield from ok(res, self.model.list())
示例#19
0
 def update(self, req, res):
     yield from req.read_form_data()
     name = req.params['name']
     value = ujson.loads(req.form['value'][0])
     yield from ok(res, self.model.set(name, value))
示例#20
0
 def read(self, req, res):
   yield from ok(res, self.model.get(req.params['name']))
示例#21
0
def get(req, res):
    yield from ok(res, model.get())
示例#22
0
 def update(self, req, res):
   yield from req.read_form_data()
   name = req.params['name']
   value = ujson.loads(req.form['value'][0])
   yield from ok(res, self.model.set(name, value))
示例#23
0
 def get(req, res):
   yield from ok(res, model.get())
示例#24
0
 def read(self, req, res):
   yield from ok(res, self.model.get(name))