Skip to content

Commit

Permalink
Swap all docstring quotes, per PEP 257.
Browse files Browse the repository at this point in the history
Patch generated with:
sed -i "s/'''/\"\"\"/g' *.py
  • Loading branch information
Francis Herne committed Nov 7, 2014
1 parent 1012ec9 commit 4d8d40e
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 57 deletions.
14 changes: 7 additions & 7 deletions Bear.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import MGO

def mindist(a, b, size):
'''Distance between two values accounting for world wrapping'''
"""Distance between two values accounting for world wrapping"""
return min((b-a)%size,(a-b)%size)

class Bear(MGO.GEMGO):
'''Harmless animal that follows the player'''
"""Harmless animal that follows the player"""
PER_TILE = 1/float(2000)

def __init__(self, position, cellmap):
'''Create bear at position'''
"""Create bear at position"""
super(Bear, self).__init__(position, cellmap)
self.direction = -1 # Left
self.speed = 0.7 # Chance of moving per turn, max 1, min 0
Expand All @@ -21,14 +21,14 @@ def __init__(self, position, cellmap):
self.hunting = False

def directiontoplayer(self, playerpos):
'''Find the best direction to move towards the player'''
"""Find the best direction to move towards the player"""
if (mindist(playerpos[0], self.position[0], self.cellmap.size[0]) > self.pfmapsize or
mindist(playerpos[1], self.position[1], self.cellmap.size[1]) > self.pfmapsize):
# Player is outside pathfinder area
return False

def mapcoord(pfcoord):
'''Get map coordinate from pathfinder one'''
"""Get map coordinate from pathfinder one"""
return coords.modsum(self.position, pfcoord, (-self.pfmapsize,)*2, self.cellmap.size)

foundtarget = False
Expand Down Expand Up @@ -68,7 +68,7 @@ def mapcoord(pfcoord):
def update(self, player):
playerpos = player.position
def chaseplayer():
'''Decide whether to chase the player'''
"""Decide whether to chase the player"""
if (mindist(playerpos[0], self.position[0], self.cellmap.size[0])**2 +
mindist(playerpos[1], self.position[1], self.cellmap.size[1])**2) > self.detectionrange**2:
# Can't see/smell/hear (?) player
Expand All @@ -79,7 +79,7 @@ def chaseplayer():
return True

def randommove():
'''Move in random direction'''
"""Move in random direction"""
move = [0, random.randint(-1,1)]
random.shuffle(move)
return move
Expand Down
6 changes: 3 additions & 3 deletions Dragon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import MGO

class Dragon(MGO.GEMGO):
'''Harmless flying thing that follows the player'''
"""Harmless flying thing that follows the player"""
PER_TILE = 1/float(6000)
detectionrange = 18
speed = 0.8

def __init__(self, position, cellmap):
'''Create new dragon in position'''
"""Create new dragon in position"""
super(Dragon, self).__init__(position, cellmap)
self.direction = UPLEFT
self.hunting = False

def update(self, player):
'''Fly toward the player if nearby, or continue in same direction'''
"""Fly toward the player if nearby, or continue in same direction"""
playerpos = player.position
def tileoffset(a, b, size):
offset = [0, 0]
Expand Down
22 changes: 11 additions & 11 deletions HUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from colors import *

class ScoreWidget:
'''Widget to show a score and associated image'''
"""Widget to show a score and associated image"""
def __init__(self, image, window, total=None, stringfunc=None, bgtileimage=None):
self.image = image
self.bgtileimage = bgtileimage
Expand All @@ -16,7 +16,7 @@ def __init__(self, image, window, total=None, stringfunc=None, bgtileimage=None)
self.textbox = TextBox(22, (205, 205, 75), True)

def draw(self, region, quantity):
'''Draw the score widget'''
"""Draw the score widget"""
region = pygame.Rect(region)
old_clip = self.window.get_clip()
self.window.set_clip(region)
Expand All @@ -36,13 +36,13 @@ def draw(self, region, quantity):
self.window.set_clip(old_clip)

class MinimapWidget:
'''Widget to display a small map of the world'''
"""Widget to display a small map of the world"""
def __init__(self, world, window):
self.world = world
self.window = window

def draw(self, region, scrollpos):
'''Draw the minimap'''
"""Draw the minimap"""
region = pygame.Rect(region)
old_clip = self.window.get_clip()
self.window.set_clip(region)
Expand All @@ -65,7 +65,7 @@ def draw(self, region, scrollpos):
self.window.set_clip(old_clip)

class Frame:
'''Thingy to draw around widgets'''
"""Thingy to draw around widgets"""
HORIZONTAL = 0
VERTICAL = 1
def __init__(self, images, window):
Expand All @@ -75,7 +75,7 @@ def __init__(self, images, window):
self.window = window

def draw(self, region, orientation):
'''Draw frame along top or left of region'''
"""Draw frame along top or left of region"""
region = pygame.Rect(region)
old_clip = self.window.get_clip()
self.window.set_clip(region)
Expand All @@ -86,7 +86,7 @@ def draw(self, region, orientation):
self.window.set_clip(old_clip)

class HUD:
'''Vertical bar with player scores and minimap'''
"""Vertical bar with player scores and minimap"""
def __init__(self, world, window):
self.window = window
self.world = world
Expand All @@ -99,7 +99,7 @@ def __init__(self, world, window):
self.minimapwidget = MinimapWidget(world, window)

def draw(self, region, scrollpos):
'''Draw the heads-up display'''
"""Draw the heads-up display"""
region = pygame.Rect(region)
pygame.draw.rect(self.window, BLACK, region)
framewidth = self.frame.thickness[Frame.VERTICAL]
Expand All @@ -122,7 +122,7 @@ def draw(self, region, scrollpos):
self.coinwidget.draw(widgetareas[2], self.world.player.score[collectables.COIN])

def splash(self, message, fontsize=40, icon=None):
'''Display a splash message across the entire window'''
"""Display a splash message across the entire window"""
windowrect = self.window.get_rect()
pygame.draw.rect(self.window, BLACK, windowrect)
textbox = TextBox(fontsize, WHITE, False)
Expand All @@ -132,7 +132,7 @@ def splash(self, message, fontsize=40, icon=None):
textbox.draw(message, windowrect, surface=self.window)

def endsplash(self, reason):
'''Display an explanation for the game ending'''
"""Display an explanation for the game ending"""
if reason == collectables.CHOCOLATE:
self.splash("You ran out of chocolate!")
elif reason == collectables.COIN:
Expand All @@ -141,5 +141,5 @@ def endsplash(self, reason):
self.splash("What happened here?")

def loadingsplash(self, description):
'''Display a splash screen while a new world loads'''
"""Display a splash screen while a new world loads"""
self.splash(description, 25, hudimages.HourGlass)
2 changes: 1 addition & 1 deletion MGO.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, position, cellmap):

@classmethod
def place(cls, cellmap):
'''Create set of objects with random positions'''
"""Create set of objects with random positions"""
created = []
for i in xrange(int(cellmap.size[0]*cellmap.size[1]*cls.PER_TILE)):
attempt = (random.randint(0, cellmap.size[0]-1),
Expand Down
16 changes: 8 additions & 8 deletions Map.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import sys

class Map():
'''Contains array of Cells and properties representing the map as a whole'''
"""Contains array of Cells and properties representing the map as a whole"""
CELLDAMAGEDCOST = 5
CELLBURNINGCOST = 200
DIRTYCACHE = False

def __init__(self, mapdict):
'''Load the map from image files'''
"""Load the map from image files"""
self.startpos = tuple(mapdict['startpos'])
self.signdefs = []
if 'signs' in mapdict:
Expand Down Expand Up @@ -90,11 +90,11 @@ def createcell(ground, collectable):
self.origcoins = (self.cellarray['collectableitem'] == collectables.COIN).sum()

def __getitem__(self, coord):
'''Get map item with [], wrapping'''
"""Get map item with [], wrapping"""
return self.cellarray[coord[0]%self.size[0]][coord[1]%self.size[1]]

def __setitem__(self, coord, value):
'''Set map item with [], wrapping'''
"""Set map item with [], wrapping"""
self.cellarray[coord[0]%self.size[0]][coord[1]%self.size[1]] = value

def sprites(self, coord):
Expand Down Expand Up @@ -151,7 +151,7 @@ def ignitefuse(self, coord):
openlist.add(nbrpos)

def destroy(self, coord):
'''Change cell attributes to reflect destruction'''
"""Change cell attributes to reflect destruction"""
cell = self[coord]
if not cell['destructable']:
return False
Expand All @@ -169,7 +169,7 @@ def destroy(self, coord):
return True

def ignite(self, coord, multiplier=1, forceignite=False):
'''Start a fire at coord, with chance cell.firestartchance * multiplier'''
"""Start a fire at coord, with chance cell.firestartchance * multiplier"""
coord = coords.mod(coord, self.size)
cell = self[coord]
if coord in self.fusetiles:
Expand All @@ -185,7 +185,7 @@ def ignite(self, coord, multiplier=1, forceignite=False):
return False

def detonate(self, coord):
'''Set off an explosion at coord'''
"""Set off an explosion at coord"""
def blam(epicentre):
self[epicentre]['collectableitem'] = 0
for dx in (-1, 0, 1):
Expand All @@ -199,7 +199,7 @@ def blam(epicentre):
return True

def update(self):
'''Spread fire, potentially other continuous map processes'''
"""Spread fire, potentially other continuous map processes"""
for tile in self.burningtiles.copy():
cell = self[tile]
for nbrpos in coords.neighbours(tile):
Expand Down
4 changes: 2 additions & 2 deletions MessageBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from colors import *

class MessageBox:
'''Horizontal bar with messages'''
"""Horizontal bar with messages"""
def __init__(self, window, mgolist):
self.window = window
self.textbox = TextBox(20, BLACK, False)
self.string = None
self.mgolist = mgolist

def draw(self, region):
'''Draw the message box'''
"""Draw the message box"""
if self.string != None:
region = pygame.Rect(region)

Expand Down
8 changes: 4 additions & 4 deletions Pixie.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import MGO

class Pixie(MGO.GEMGO):
'''Pixie that says things when walked to'''
"""Pixie that says things when walked to"""
def __init__(self, phrasebook, position, cellmap):
'''Create new pixie in position'''
"""Create new pixie in position"""
super(Pixie, self).__init__(position, cellmap)
self.direction = -1 # Left
self.phrasebook = phrasebook
Expand All @@ -20,7 +20,7 @@ def place(cls, cellmap):
return created

def update(self, player):
'''DOCSTRING NEEDED HERE'''
"""DOCSTRING NEEDED HERE"""
self.move()
ppx, ppy = player.position
for testx in (ppx-1, ppx, ppx+1):
Expand All @@ -39,7 +39,7 @@ def update(self, player):
def move(self):

def randommove():
'''Move in random direction'''
"""Move in random direction"""
move = [0, random.randint(-1,1)]
random.shuffle(move)
return move
Expand Down
10 changes: 5 additions & 5 deletions Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from directions import *

class Player(MGO.GEMGO):
'''The player, exploring the grid-based world'''
"""The player, exploring the grid-based world"""
FREEPLAYER = False
XRAYVISION = False

def __init__(self, position, cellmap):
'''Initialise instance variables'''
"""Initialise instance variables"""
super(Player, self).__init__(position, cellmap)
self.color = MAGENTA
self.visibility = 15
Expand Down Expand Up @@ -55,7 +55,7 @@ def action(self, arg):
self.move(*arg)

def move(self, x, y):
'''Move if possible, update collectable levels accordingly'''
"""Move if possible, update collectable levels accordingly"""
if abs(x) + abs(y) != 1:
return False
self.direction = (x, y)
Expand Down Expand Up @@ -89,7 +89,7 @@ def subtuple(a, b):
return True

def detonate(self):
'''Detonate carried explosives at player's location'''
"""Detonate carried explosives at player's location"""
if self.score[collectables.DYNAMITE] <= 0:
return
if not self.cellmap[self.position]['destructable']:
Expand All @@ -115,7 +115,7 @@ def scattercoins(self, radius, number):
scattered += 1

def updatevisible(self):
'''Calculate and return the set of tiles visible to player'''
"""Calculate and return the set of tiles visible to player"""
self.visibletiles = set()
self.visibletiles.add(self.position)

Expand Down
6 changes: 3 additions & 3 deletions Sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import MGO

class Sign(MGO.GEMGO):
'''Sign that displays message when walked over'''
"""Sign that displays message when walked over"""
def __init__(self, string, position, cellmap):
'''Create new sign in position'''
"""Create new sign in position"""
super(Sign, self).__init__(position, cellmap)
self.string = string
self.visible = False
Expand All @@ -17,7 +17,7 @@ def place(cls, cellmap):
return created

def update(self, player):
'''Display message if becoming visible or trodden on'''
"""Display message if becoming visible or trodden on"""
if self.position == player.position:
self._suggestmessage("The sign reads: " + self.string, 50)

Expand Down
6 changes: 3 additions & 3 deletions TextBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
from colors import *

class TextBox:
'''Render text with given size/font/colors'''
"""Render text with given size/font/colors"""
def __init__(self, size, color, beveled=True, font="./fonts/MorrisRomanBlack.ttf"):
'''Set instance variables, calculate beveling colors'''
"""Set instance variables, calculate beveling colors"""
self.font = pygame.font.Font(font, size)
self.beveled = beveled
self.maincolor = pygame.Color(*color).correct_gamma(1)
self.darkcolor = BLACK #FIXME
self.lightcolor = self.maincolor.correct_gamma(8)

def draw(self, string, region, centered=(True, True), surface=None):
'''Draw text to surface, or return text on a new surface'''
"""Draw text to surface, or return text on a new surface"""
textsize = self.font.size(string)
returnsurface = False
if surface == None:
Expand Down
2 changes: 1 addition & 1 deletion World.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def rendervisibletiles(self, extrasprites=[]):
self.surface.blit(*sprite[:2])

def moveplayer(self, arg):
'''Move the player by (x, y), move other fauna, update world surface around player'''
"""Move the player by (x, y), move other fauna, update world surface around player"""
self.cellmap.update()
self.player.action(arg)

Expand Down
2 changes: 1 addition & 1 deletion WorldView.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def updateregion():
drawregion.center = region.center

def updatescrollpos():
'''scroll towards the correct position'''
"""scroll towards the correct position"""
for axis in [0, 1]:
pq = (world.player.position[axis]*TILESIZE+self.scrollpos[axis]) % world.surface.get_size()[axis]
if drawregion.size[axis] > 2*world.player.visibility*TILESIZE:
Expand Down
Loading

0 comments on commit 4d8d40e

Please sign in to comment.