Merge from old Gitea
This commit is contained in:
36
examples/game.py
Normal file
36
examples/game.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import asyncio
|
||||
import time
|
||||
from esasdk import Machine
|
||||
|
||||
async def main():
|
||||
# Connect to a machine
|
||||
machine = Machine("ws://localhost:5424")
|
||||
await machine.connect()
|
||||
|
||||
# start a game
|
||||
gameCode = "MAES"
|
||||
await machine.game_start(gameCode)
|
||||
print(f"running {gameCode}")
|
||||
|
||||
# wait a bit and stop the game
|
||||
time.sleep(15)
|
||||
await machine.game_stop()
|
||||
print("game stopped forcefully")
|
||||
|
||||
# start a game as jon
|
||||
gameCode = "MAES"
|
||||
user = "16566"
|
||||
countdown = 15
|
||||
duration = 15
|
||||
await machine.game_start(gameCode, user, countdown, duration)
|
||||
print(f"running {gameCode}")
|
||||
|
||||
# wait for game stopped signal to know the game has stopped.
|
||||
await machine.game_stop_signal()
|
||||
print("game stopped naturally")
|
||||
|
||||
# Close connection
|
||||
await machine.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user