The Basic Models
This game contains a fair bit more application logic than the previous examples and requires a decent number of model classes to define how everything behaves. To get these set up, we need to create a file to contain these models and set up the basics. In your appengine directory, create a file called models.py and fill it with the following code:
from geo.geomodel import GeoModel import geo.geotypes as geotypes from google.appengine.api import xmpp, users, urlfetch, memcache from google.appengine.ext import db from django.utils import simplejson as json import logging, os, string, random, urllib from datetime import datetime, timedelta import math class Game(object): # setup some gameplay variables default_score = 5 default_germ_spread = 0.03 default_germ_speed = 0.0055 default_germ_slowdown = 0.00015 default_germ_strength = 0.03 default_disease_strength = 0.5 default_disease_strength_increment = 0.001 # the color of the germs as they get displayed on the map default_color_friendly = "#577ff5" default_color_enemy = "#007b00" default_color_threat = "#ff0000"
This codes does all the imports that we’re going to need for this file in the future. Then, we define a number of variables that we’ll use to govern the gameplay of iPandemic. There is no real science behind these numbers, so feel free to modify them as much as you wish.
default_score
Every user has a score, which is the number of points she has accumulated. When user join the game, we’ll give them some points just ...
Get Building the Realtime User Experience now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.