Source

GtugGoSandbox / mapgame / action.py

Full commit
from google.appengine.ext import webapp
from google.appengine.api import user
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from django.utils import simplejson as json
from models import Player
from models import Location
from random import *
from engine import *


class Action(webapp.RequestHandler):
    def post(self):
        u = user.get_current_user()
        player1 = db.Query(Player)
        player1.filter('name =',u.email)
        player1 = player1.get()
        player2 = db.Query(Player)
        player2.filter('name =',self.request.get('opponent'))
        player2 = player2.get()
        damage = generate_damage(player1) + random.randint()
        resist = generate_resistance(player2) + random.randint()
        player2.hp = player2.hp + resist - damage
        player2.put()
        player1.xp = player1.xp + random.randint()
        player1.put()
        level_up(player1) 
        player1 = {'player':u.email,'hp':player1.hp} 
        player2 = {'player':self.request.get('opponent'),
                   'hp':player2.hp}
        result = [player1,player2]
        self.response.out.write(json.loads(result))