repl.it
@Lord_Poseidon/

the_game_backend-1

Python

a game backend

fork
loading
Files
  • main.py
  • game.py
  • Packager files
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask
import game
import threading
app=Flask(__name__)
@app.route('/')
def hello_world():
    return "hello world"
@app.route('/<int:gameid>/dice', methods=['GET','POST'])
def dieroll(gameid):
    return game.games(gameid).dieroll()#gets the most recent dice roll 
@app.route('/<int:gameid>/<player>/money')
def getmoney(gameid,player):
    return game.games(gameid).getmoney(player)#gets the money of the player
@app.route('/position/<int:gameid>')
def getpos(gameid):
    return game.games(gameid).getposition()#gets the position of the players
@app.route('/<int:gameid>/props/<int:property>')
def getpropdata(gameid,property):
    return game.games(gameid).getpropdetails(property)
    #returns the property's description,number of houses,owner,cost,etc.
@app.route('/<int:gameid>/<player>/data')
def getplayerdata(gameid,player):
    return game.games(gameid).getplayerdata(player)
    #returns player data.properties owned,money in hand,mortgages,jailtime,etc.etc.
@app.route('/<int:gameid>/otherdata')
def getotherdata(gameid):
    return game.games(gameid).getotherdata()
    #returns the most recent status message
    #for example,'john doe bought an abandoned amazon warehouse
    #or maybe even john doe pays 10BTC fine to the bank(community chest) 
@app.route('/lobby/adduser/<user>')
def adduser(user):
    name,tok=user.split(':')
    a=game.getlobby().addplayer(name,tok)
    return a
@app.route('/lobby')
def lobby():    
    return game.getlobby().lobbydata()
@app.route('/lobby/start')
def startgame():
    threading.Thread(target=game.getlobby().startgame).start()
    return ''
@app.route('/lobby/addbot')
def addbot():
    return game.getlobby().addbot()
@app.route('/<int:gameid>/actions')
def alacs(gameid):
    return game.games(gameid).getActions()
@app.route('/<int:gameid>/choose/<option>')
def so(gameid,option):
    actionid,chosen=[int(i) for i in option.split(':')]
    game.games(gameid).satisfyAction(actionid,chosen)
    return ''



app.run('0.0.0.0',8080)
?