Ejemplo n.º 1
0
 def test_insertPawn_makeRoom(self):
     """
     When pawns are inserted, a space should be made for them.
     For now, make a space on all sides.  Later, this could
     change.
     """
     board = Board()
     board.generate(5,5)
     locs = map2coord([
         'x   x',
         '     ',
         '  x  ',
         '     ',
         'x   x',
     ])
     pawns = []
     for loc in locs:
         pawns.append(Pawn())
         board.insertPawn(loc, pawns[-1])
     
     expected_empty = map2coord([
         'xx xx',
         'x x x',
         ' xxx ',
         'x x x',
         'xx xx',
     ])
     actual_empty = set()
     for k,v in board.fg_tiles.items():
         if v == EMPTY:
             actual_empty.add(k)
     
     self.assertCoordsEqual(expected_empty, actual_empty,
                            "Expected empty tiles to be thus")
Ejemplo n.º 2
0
 def test_insertPawn(self):
     """
     You can put a pawn on the board (and into the game)
     """
     pawn = Pawn()
     board = Board()
     board.generate(1,1)
     board.insertPawn((0,0), pawn)
     self.assertEqual(pawn.board, board, "Pawn should know "
                      "he's on the board.")
     self.assertEqual(pawn.loc, (0,0), "Pawn should know where"
                      " he is on the board")
     
     self.assertTrue(pawn in board.pawns, "Board should know "
                     "about the Pawn")
Ejemplo n.º 3
0
 def test_generate(self):
     """
     You should be able to generate a standard board of any size,
     where there's indestructable bricks in a grid like this:
     """
     board = Board()
     board.generate(5, 5)
     expected = [
         [SOFT, SOFT, SOFT, SOFT, SOFT],
         [SOFT, HARD, SOFT, HARD, SOFT],
         [SOFT, SOFT, SOFT, SOFT, SOFT],
         [SOFT, HARD, SOFT, HARD, SOFT],
         [SOFT, SOFT, SOFT, SOFT, SOFT],
     ]
     for r,row in enumerate(expected):
         for c,tile in enumerate(row):
             actual = board.fg_tiles[(c,r)]
             self.assertEqual(actual, tile, "Expected foreground"
                              "tile at %s,%s to be %s, not %s"%(
                              c,r,tile,actual))
Ejemplo n.º 4
0
Archivo: run.py Proyecto: iffy/boom
from twisted.internet import reactor, stdio, task
from twisted.internet.endpoints import TCP4ServerEndpoint

from boom.protocol import TelnetFactory
from boom.game import (Board, Pawn, YoureDead, IllegalMove, SOFT, 
                       EMPTY, HARD)

board = Board()
board.generate(11,11)


def _printBoard():
    yield '+' + '-'*board_width + '+'
    for y in xrange(board_height):
        row = '|'
        for x in xrange(board_width):
            coord = (x,y)
            pawns = [x for x in board.pawns if x.loc == coord]
            if pawns:
                p = pawns[0]
                if p.alive:
                    row += p.name[0].upper()
                else:
                    row += p.name[0].lower()
                continue
            if coord in board.bombs:
                row += 'O'
                continue
            if coord in board.fires:
                row += 'x'
                continue