Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

BattleClass.py

By: a guest on Oct 22nd, 2011  |  syntax: Python  |  size: 4.46 KB  |  views: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from PersonClass import *
  2. from HTMLTemplates import *
  3. import time
  4. '''
  5. Created on Oct 18, 2011
  6.  
  7. @author: Trevor Coleman
  8. '''
  9.  
  10. class Battle(object):
  11.     '''
  12.    classdocs
  13.    '''
  14.  
  15.     def __init__(self, numberOfPlayers):
  16.         self.players = {}
  17.         self.timeline = {}
  18.        
  19.         for i in range(numberOfPlayers):
  20.             self.players[i] = Person()  
  21.        
  22.                
  23.         self.timeline = {}
  24.         for y in self.players:
  25.             firstAction = self.players[y].ticks
  26.             if firstAction in self.timeline:
  27.                 self.timeline[firstAction].append(self.players[y])
  28.             else:
  29.                 self.timeline[firstAction] = [self.players[y]]
  30.    
  31.     ######################################################
  32.     #OLD TEXT-BASED TIMELINE GENERATOR
  33.    
  34.     def showTimeline(self):
  35.         for i in range(11):
  36.             if i in self.timeline:
  37.                 print str(i) + ": ",
  38.                 actingPlayers = self.timeline[i]
  39.                 for player in actingPlayers:
  40.                     print player.name + " (" + str(player.dv_penalty) + ")",
  41.                    
  42.             else:
  43.                 print str(i) + ": ",
  44.             print "\n",
  45.            
  46.     ######################################################
  47.  
  48.     def updateTimeline(self):
  49.         self.timeline = {}
  50.         for y in self.players:
  51.             firstAction = self.players[y].ticks
  52.             if firstAction in self.timeline:
  53.                 self.timeline[firstAction].append(self.players[y])
  54.             else:
  55.                 self.timeline[firstAction] = [self.players[y]]
  56.    
  57.     def createHTMLTimeline(self):
  58.        
  59.         #self.updateTimeline()
  60.        
  61.         HTMLTimeline = {}
  62.         for i in range(11):
  63.             if i in self.timeline:
  64.                 actingPlayers = self.timeline[i]
  65.                 for player in actingPlayers:
  66.                     if str(i) in HTMLTimeline:
  67.                         HTMLTimeline[str(i)] = HTMLTimeline[str(i)] + ", " + player.name
  68.                     else:
  69.                         HTMLTimeline[str(i)] = player.name
  70.            
  71.             else:
  72.                 HTMLTimeline[str(i)] = "---"
  73.        
  74.         print "BEFORE FILE CREATE"
  75.                
  76.         f = open('/sdcard/sl4a/scripts/ExaltedCombatManager/html/timeline.html', 'w')
  77.         f.write(timelineHTML % HTMLTimeline)
  78.         f.close()
  79.        
  80.         print "AFTER FILE CREATE"
  81.  
  82.     def updateTimeline(self):
  83.         self.timeline = {}
  84.         for y in self.players:
  85.             firstAction = self.players[y].ticks
  86.             if firstAction in self.timeline:
  87.                 self.timeline[firstAction].append(self.players[y])
  88.             else:
  89.                 self.timeline[firstAction] = [self.players[y]]
  90.  
  91.     def tick(self):
  92.         for y in self.players:
  93.             if self.players[y].ticks == 0:
  94.                 self.players[y].turn()
  95.             else:
  96.                 self.players[y].ticks = self.players[y].ticks - 1
  97.        
  98.         self.createHTMLTimeline()
  99.  
  100.     def editPlayers(self):
  101.        
  102.         #WRITE THIS BIT!
  103.        
  104.         #Generate Edit Players Javascript GUI
  105.        
  106.         #Display Edit Players Screen
  107.        
  108.         #Recieve Data from Screen
  109.        
  110.         #Parse data & update players
  111.         print "not ready yet"
  112.  
  113.     def generateEditPlayersScreen(self):
  114.        
  115.         # holds the HTML for all of the rows in the edit players table
  116.         playerRows = ""
  117.        
  118.         #    Create dict with the following STRINGS for players[i]
  119.         #        playerNumber : i
  120.         #        name : players[i].name
  121.         #        ticks : players[i].ticks
  122.         #        dv_penalty : players[i].dv_penalty
  123.        
  124.        
  125.         for i in self.players:
  126.             playerDict = {}
  127.             playerDict["name"] = self.players[i].name
  128.             playerDict["ticks"] = self.players[i].ticks
  129.             playerDict["dv_penalty"] = self.players[i].dv_penalty
  130.             playerDict["playerNumber"] = i
  131.            
  132.             # add each player's row
  133.             playerRows = playerRows + (editPlayersRow % playerDict)
  134.        
  135.         f = open('/sdcard/sl4a/scripts/ExaltedCombatManager/editPlayers.html', 'w')
  136.         f.write(editPlayersScreen % playerRows)
  137.         f.close()
  138.                    
  139.     def addPlayer(self):
  140.         newPlayer = max(self.players.iterkeys()) + 1
  141.         self.players[newPlayer] = Person()
  142.        
  143.                
  144.  
clone this paste RAW Paste Data