def test_checkGameReturnsFalseWhenThereIsNoActiveGame(self): file = open('gunid', 'r+') file.truncate() file.write( "# User Identification File.\n# Change gunid and username.\n# Rename file to gunid.\ngunid=3\nusername=Benjamin\n" ) file.close() gun = Gun() gun.readIDFile() self.assertFalse(gun.checkGame())
def test_checkGameReturnsTrueWhenThereIsAnActiveGame(self): file = open('gunid', 'r+') file.truncate() file.write( "# User Identification File.\n# Change gunid and username.\n# Rename file to gunid.\ngunid=3\nusername=Benjamin\n" ) file.close() gun = Gun() gun.readIDFile() mydb = connect.connect() cursor = mydb.cursor() sql = "INSERT INTO Games (current_state, winner, game_date) VALUES (2, 0, (NOW() - INTERVAL 4 HOUR + INTERVAL 11 MINUTE - INTERVAL 22 SECOND))" cursor.execute(sql) mydb.commit() self.assertTrue(gun.checkGame()) sql = "UPDATE Games SET current_state=0 WHERE current_state=2" cursor.execute(sql) mydb.commit() mydb.close()
while inGame: if hp == 3: led.toggleLED('green') led.setLED('red', 'off') elif hp == 2: led.toggleLED('green') led.setLED('red', 'on') else: led.toggleLED('green') led.toggleLED('red') code = lirc.nextcode() if code and code[0] != "Shot" + str(gun.id).zfill(2): #we got hit by something print(str(datetime.datetime.now()), "Got hit by " + str(code)) hp -= 1 if hp == 0: gun.loseGame() led.setLED('red', 'on') led.setLED('green', 'off') inGame = False stillActive = gun.checkGame() if stillActive == False: inGame = False led.setLED('red', 'off') led.setLED('green', 'on') sleep(0.1) finally: pass