Esempio n. 1
0
 def __init__(self, field_size=FIELD_SIZE):
     logging.info("Created Farm instance")
     self.field_size = field_size
     self.field = [[Plant() for _ in range(field_size)]
                   for _ in range(field_size)]
     self.money = 0
     self.lock = Lock()
Esempio n. 2
0
def plant_handler(col, row, plant_type):
    user = session['user']
    if user.get_plant(col, row).type != 'empty':
        pass

    new_plant = Plant((plant_type, time.time()))
    user.set_plant(col, row, new_plant)

    db.session.add(user)
    db.session.commit()

    emit('set_plant', {
        'position': (col, row),
        'new_plant': new_plant.info
    },
         room=user.username)
Esempio n. 3
0
def harvest_handler(col, row):
    user = session['user']
    cur_plant = user.get_plant(col, row)
    user.money = user.money + cur_plant.cost

    new_plant = Plant()
    user.set_plant(col, row, new_plant)

    db.session.add(user)
    db.session.commit()

    emit('set_plant', {
        'position': (col, row),
        'new_plant': new_plant.info
    },
         room=user.username)
Esempio n. 4
0
 def get_plant(self, col, row):
     if row >= TILE_NUM or col >= TILE_NUM:
         raise AttributeError("Plant {} {} doesn't exist".format(col, row))
     return Plant(self.field[row * TILE_NUM + col])
Esempio n. 5
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     if 'field' not in kwargs:
         self.field = [Plant().info] * (TILE_NUM**2)
Esempio n. 6
0
    def plant(self, col, row, plant_type):
        fake_plant = Plant((plant_type, time.time()))
        self._set_fake_plant(col, row, fake_plant)

        sio.emit('plant', (col, row, plant_type))
Esempio n. 7
0
    def harvest_plant(self, col, row):
        plant = self.get_plant(col, row)
        self._set_money(self.money + plant.cost)
        self._set_fake_plant(col, row, Plant())

        sio.emit('harvest', (col, row))
Esempio n. 8
0
 def set_plant(self, col, row, plant_info):
     logging.info("New plant at {} {} is {}".format(col, row, plant_info))
     with self.lock:
         self.field[row][col] = Plant(plant_info)