Skip to content

Commit

Permalink
Extra bomb levels generator has been implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
ferustigris committed Aug 31, 2014
1 parent 19df6f4 commit a8b80b7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 6 deletions.
3 changes: 2 additions & 1 deletion biologylevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def isGameOver(self, player):
return False

def nextLevel(self):
return "default"
return "extrabomblevel_1_0_4"

def name(self):
return "biologylevel"
Expand All @@ -29,3 +29,4 @@ def onBombed(self, player, cell, enemy):
ship.pushOn()

LevelsFactory.levels["biologylevel"] = Level()
import extrabomblevel
6 changes: 4 additions & 2 deletions bomblevel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from levels import AbstractLevel, LevelsFactory, check
import random
import nuclearlevel

def allBombed(self, player):
""" Check, is all players units are bombed """
Expand All @@ -24,14 +23,17 @@ def name(self):
return "bomblevel"

def onBombed(self, player, cell, enemy):
self.onBombedSized(player, cell, enemy, self.fieldSize())

def onBombedSized(self, player, cell, enemy, n):
unit = cell.decorators["unit_type"]
if unit == 'bomb_unit':
x = cell.x
y = cell.y
n = self.fieldSize()
koords = map(lambda i, j: (x + i, y + j), [0, 0, -1, 1], [-1, 1, 0, 0])
koords = filter(lambda(x, y): 0 <= x < n and 0 <= y < n, koords)# remove unbounded
cells = filter(lambda cell: (cell.x, cell.y) in koords, player.cells)
[cell.pushOn() for cell in cells]

LevelsFactory.levels["bomblevel"] = Level()
import nuclearlevel
2 changes: 1 addition & 1 deletion buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ requirements = kivy
#garden_requirements =

# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png
presplash.filename = %(source.dir)s/images/ship.png

# (str) Icon of the application
icon.filename = %(source.dir)s/images/icon.png
Expand Down
43 changes: 43 additions & 0 deletions extrabomblevel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from levels import AbstractLevel, LevelsFactory, check

def allBombed(self, player):
""" Check, is all players units are bombed """
return player.units.count('default_unit') == self.fieldSize()

class Level(AbstractLevel):
def __init__(self, bombsCount, biologiesCount, size):
self.bombsCount = bombsCount
self.biologiesCount = biologiesCount
self.size = size
lvls = LevelsFactory()
self.__bombLevel = lvls.create('bomblevel')
self.__bombLevel.fieldSize = lambda : size
self.__biologyLevel = lvls.create('biologylevel')

def fieldSize(self):
return self.size

def units(self):
return ["bomb_unit" for i in range(self.bombsCount)] + ["biology_bomb_unit" for i in
range(self.biologiesCount)] + ["default_unit" for i in range(self.fieldSize())]

@check(allBombed)
def isGameOver(self, player):
return self.__biologyLevel.isGameOver(player) or self.__bombLevel.isGameOver(player)

def nextLevel(self):
return "default" if self.name() == "extrabomblevel_5_4_8" else self.formatName(self.bombsCount + 1, self.biologiesCount + 1, self.size + 1)

def name(self):
return self.formatName(self.bombsCount, self.biologiesCount, self.size)

def formatName(self, bombsCount, biologiesCount, size):
return "extrabomblevel_" + str(bombsCount) + "_" + str(biologiesCount) + "_" + str(size)

def onBombed(self, player, cell, enemy):
self.__biologyLevel.onBombed(player, cell, enemy)
self.__bombLevel.onBombedSized(player, cell, enemy, self.size)

for i,j,c in map(None , range(1, 6), range(0, 5), range(4, 9)):
lvl = Level(i, j, c)
LevelsFactory.levels[lvl.name()] = lvl
2 changes: 1 addition & 1 deletion game.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def initPlayers(self):
lvl = self.lvl

n = lvl.fieldSize()
self.observer.onFieldSizeChanged(n)

self.human = Player(lvl.units(), self)
self.ai = AI(lvl.units(), self)
Expand Down Expand Up @@ -70,7 +71,6 @@ def onScore(self, bonus):

def onLevelUp(self, level):
self.lvl = level
self.observer.onFieldSizeChanged(level.fieldSize())
self.save()

def onBombed(self, player, cell):
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GameStatesObserver:
def __init__(self, RootWidget):
self.RootWidget = RootWidget
self.units = []
self.__fieldSize = 5

def onGameStart(self, game):
self.current.onGameStart(game)
Expand All @@ -34,6 +35,7 @@ def onGamePrepare(self, game):
self.RootWidget.rootLayout.clear_widgets()
self.current = FieldWidget(game)

self.current.onFieldSizeChanged(self.__fieldSize)
self.current.onUnitsCountChange(self.units)
self.units = []

Expand All @@ -51,6 +53,7 @@ def onUnitsCountChange(self, units):

def onFieldSizeChanged(self, size):
self.current.onFieldSizeChanged(size)
self.__fieldSize = size

def onScoreChanged(self, bonus):
self.current.onScoreChanged(bonus)
Expand Down
1 change: 0 additions & 1 deletion mplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def __init__(self, sound, timeout):
def __call__(self, *args, **kwargs):
if self.term:
return
self.sound.volume = 0
self.sound.play()
Clock.schedule_once(self, self.t())

Expand Down

0 comments on commit a8b80b7

Please sign in to comment.