def choi1(self): self.choice = raw_input('move, stay, camera or shoot?\n>') if self.choice == 'shoot': self.shoot() self.choi2() elif self.choice == 'stay': print colors['YELLOW'] + '你停留在了原地,它来了' + colors['END'] End.End().dead(self.cur_pos, alien.cur_pos) elif self.choice == 'move': self.move() End.End().dead(self.cur_pos, alien.cur_pos) elif self.choice == 'camera' and self.cam > 0: self.cam -= 1 # print self.cam # 测试行 self.cam_pos.append(list(self.cur_pos)) # print self.cam_pos # 测试行 print '' print colors['YELLOW'] + '你在此处设置了一个检测仪' + colors['END'] self.choi2() elif self.choice == 'camera' and self.cam <= 0: print colors['RED'] + '你已经没有检测仪了' + colors['END'] self.choi1() else: print colors['RED'] + '你特么要干啥!' + colors['END'] self.choi1()
def testRoadVertical(takGame): correct = True aux.resetBoard(takGame) aux.fillCol(takGame, 1, 1) ans = End.road(takGame.board) assert ans[0] and not ans[1] aux.resetBoard(takGame) aux.fillCol(takGame, 1, -1) ans = End.road(takGame.board) assert ans[1] and not ans[0]
def testRoadHorizontal(takGame): correct = True aux.resetBoard(takGame) aux.fillRow(takGame, 1, 1) ans = End.road(takGame.board) assert ans[0] and not ans[1] aux.resetBoard(takGame) aux.fillRow(takGame, 1, -1) ans = End.road(takGame.board) assert ans[1] and not ans[0]
def testWinnerRoad(takGame): aux.resetBoard(takGame) aux.fillRow(takGame, 0, 1) assert End.winRoad(takGame.board, 1) == 1 aux.resetBoard(takGame) aux.fillRow(takGame, 0, -1) assert End.winRoad(takGame.board, 1) == 2 aux.resetBoard(takGame) assert End.winRoad(takGame.board, 1) == False aux.fillRow(takGame, 0, 1) aux.fillRow(takGame, 1, -1) assert End.winRoad(takGame.board, 1) == 1 assert End.winRoad(takGame.board, 2) == 2
def testWinnerOther(takGame): aux.resetBoard(takGame) aux.fillRow(takGame, 0, 1) aux.fillRow(takGame, 1, 1) aux.fillCol(takGame, takGame.board.size - 1, 0) assert End.winner(takGame.board) == 1 aux.resetBoard(takGame) aux.fillRow(takGame, 0, -1) aux.fillRow(takGame, 1, -1) aux.fillCol(takGame, takGame.board.size - 1, 0) assert End.winner(takGame.board) == 2 aux.fillRow(takGame, 0, 1) aux.fillSpace(takGame, [0, takGame.board.size - 1], 0) assert End.winner(takGame.board) == 2
def testPoints(takGame): aux.resetBoard(takGame) assert End.points(takGame.board, 1) == takGame.board.pieces + takGame.board.capstones + ( takGame.board.size**2) aux.fillRow(takGame, 0, 1) aux.fillSpace(takGame, [0, 0], 0) assert End.points(takGame.board, 1) == takGame.board.pieces + takGame.board.capstones + ( takGame.board.size**2) - (takGame.board.size - 1) aux.fillRow(takGame, 1, -1) aux.fillRow(takGame, 2, -1) assert End.points(takGame.board, 2) == takGame.board.pieces + takGame.board.capstones + ( takGame.board.size**2) - (takGame.board.size * 2)
def testEndPieces(takGame): aux.resetBoard(takGame) correct = True aux.fillBoardEndPiece(takGame) if not End.end(takGame.board): correct = False assert correct
def __init__(self): ''' Defines the game screen. param list:(object) only needs self return: (None) ''' pygame.init() self.begin = True while self.begin: self.x = WIDTH / 2 self.y = HEIGHT - 140 self.cont = True self.front = Start.Start() if self.front.choice(): try: self.char = Char.Char() self.image = self.char.start() self.display = pygame.display.set_mode((WIDTH, HEIGHT)) self.background = pygame.Surface( self.display.get_size()).convert() self.room = pygame.image.load('classroom2.jpg') self.room = pygame.transform.scale(self.room, (1000, 700)) self.background.blit(self.room, (0, 0)) self.ship = ship.ship(self.image[0], self.x, self.y) self.alien = [] self.bullet = [] self.num = 0 self.speed = 1 self.spriteship = pygame.sprite.Group(self.ship) self.spritealien = pygame.sprite.Group(self.alien) self.spritebullet = pygame.sprite.Group(self.bullet) self.font = pygame.font.SysFont('bodoniblack', 30) self.score = score.score() self.value = self.font.render( 'Score: ' + str(self.score.count), True, (0, 255, 0)) self.game = Controller.start(self) self.end = End.End(self.game) Controller.end(self) except: self.cont = False else: self.end = End.End(0) Controller.end(self) if not self.cont: self.begin = False
def asteroids(): continuer = True gameState = ["EndScreen", 50] screen = pygame.display.set_mode((600, 600)) while continuer: if gameState[0] == "TitleScreen": gameState = Title.Title(screen) elif gameState[0] == "GameScreen": gameState = Game.Game(screen) elif gameState[0] == "EndScreen": gameState = End.End(screen, gameState[1]) elif gameState[0] == "Quit": continuer = False
def shoot(self): self.judge = Judge().direction('朝哪个方向开枪') if self.cur_pos[0] == alien.cur_pos[0] + 1 and self.cur_pos[1] == alien.cur_pos[1] and self.judge == 'up' or \ self.cur_pos[0] == alien.cur_pos[0] - 1 and self.cur_pos[1] == alien.cur_pos[1] and self.judge == 'down' or \ self.cur_pos[1] == alien.cur_pos[1] + 1 and self.cur_pos[0] == alien.cur_pos[0] and self.judge == 'left' or \ self.cur_pos[1] == alien.cur_pos[1] - 1 and self.cur_pos[0] == alien.cur_pos[0] and self.judge == 'right': alien.blood -= 1 print '' print colors['YELLOW'] + '命中!' + colors['END'] self.death = ['正中后肢', '正中腹部', '正中前胸'] print colors['YELLOW'] + self.death[random.randint(0, 2)] + colors['END'] print '' End.End().win(alien.full_blood, alien.blood) else: print colors['YELLOW'] + "\n你什么也没有打中,它似乎不在那里\n" + colors['END']
def move(self): self.mid_val = self.rand(list(self.cur_pos)) while not Judge().in_map(self.mid_val) or self.mid_val in green_house: self.mid_val = list(self.cur_pos) self.mid_val = self.rand(self.mid_val) self.cur_pos = self.mid_val #print '异形位置:',self.cur_pos#;print player.cam_pos # 这行测试用的 self.track[str(self.cur_pos)] = '它似乎来过这个房间' if self.cur_pos in player.cam_pos: print '' print '{0[RED]}!!!!你安装的监视仪发出警报: {1}{0[END]}'.format(colors, self.cur_pos) else: print '' print colors['YELLOW'] + '你听见了一些动静,它在移动,或许留下了一些痕迹' + colors['END'] End.End().dead(player.cur_pos, self.cur_pos)
def engine(self): while self.step < self.time / 10: self.step += 1 alien.move() player.choi1() self.inform() if self.step in range(6, 30, 5): print '' print """ 这是深空号各船舱的坐标:\n [1, 1] [1, 2] [1, 3] [1, 4] [1, 5] [2, 1] [2, 2] {1[GREEN]}{0[0]}{1[END]} [2, 4] [2, 5] [3, 1] {1[GREEN]}{0[1]}{1[END]} {1[GREEN]}{0[2]}{1[END]} [3, 5] [4, 1] [4, 2] {1[GREEN]}{0[3]}{1[END]} [4, 4] [4, 5] [5, 1] [5, 2] [5, 3] [5, 4] [5, 5] """.format(green_house, colors) print 'Time has run out!' print '自毁系统开启' End.End().timeout()
def __end(self): self.__bg.destroy() End.End()
def __init__(self): self.picker = [] self.choice = [] pygame.init() self.begin = True while self.begin: self.front = Start.Start() if self.front.choice(): self.x = WIDTH / 2 self.y = HEIGHT - 140 self.score = 0 self.box1 = Colors.Colors(50, 20) self.box2 = Colors.Colors(180, 20) self.box3 = Colors.Colors(310, 20) self.box4 = Colors.Colors(440, 20) self.box5 = Colors.Colors(50, 150) self.box6 = Colors.Colors(180, 150) self.box7 = Colors.Colors(310, 150) self.box8 = Colors.Colors(440, 150) self.box9 = Colors.Colors(50, 280) self.box10 = Colors.Colors(180, 280) self.box11 = Colors.Colors(310, 280) self.box12 = Colors.Colors(440, 280) self.box13 = Colors.Colors(50, 410) self.box14 = Colors.Colors(180, 410) self.box15 = Colors.Colors(310, 410) self.box16 = Colors.Colors(440, 410) self.box = [self.box1,self.box2,self.box3,self.box4, \ self.box5,self.box6,self.box7,self.box8, \ self.box9,self.box10,self.box11,self.box12, \ self.box13,self.box14,self.box15,self.box16] self.image = pygame.image.load('app.png').convert_alpha() self.image = pygame.transform.scale(self.image, (100, 100)) self.spritebox = pygame.sprite.Group(self.box) self.display = pygame.display.set_mode((WIDTH, HEIGHT)) self.background = pygame.Surface( self.display.get_size()).convert() for i in self.box: self.background.blit(self.image, (i.x, i.y)) self.font = pygame.font.SysFont('bodoniblack', 50) self.font2 = pygame.font.SysFont('bodoniblack', 20) self.value = self.font.render('Score: ' + str(self.score), True, (0, 0, 255)) self.text = self.font2.render('Click the images', True, (255, 0, 255)) self.text2 = self.font2.render('in the order that', True, (255, 0, 255)) self.text3 = self.font2.render('they change', True, (255, 0, 255)) self.background.blit(self.text, (350, 550)) self.background.blit(self.text2, (350, 580)) self.background.blit(self.text3, (350, 610)) self.num = 4 self.game = True while self.game: for i in range(len(self.picker)): self.picker[i].revert() self.picker = [] self.choice = [] self.game = Controller.game(self) self.num += 1 self.end = End.End(self.score) self.begin = self.end.choice() else: self.begin = False pygame.quit()
def end(self): return End.end(self.board)
def testNotEnd(takGame): aux.resetBoard(takGame) assert not End.end(takGame.board)
def testEndRoad(takGame): aux.resetBoard(takGame) aux.fillCol(takGame, 1, 1) assert End.end(takGame.board)
def new(self, mapPath): self.mapPath = mapPath self.map = tiledMap(mapPath) self.mapImg = self.map.makeMap(self) self.mapRect = self.mapImg.get_rect() self.camera = Camera(self.mapRect.x, self.mapRect.y) self.frontSprites = pygame.sprite.Group() self.backSprites = pygame.sprite.Group() self.allSprites = pygame.sprite.Group() self.triggers = pygame.sprite.Group() self.holes = pygame.sprite.Group() self.players = pygame.sprite.Group() self.walls = pygame.sprite.Group() self.spikes = pygame.sprite.Group() self.bullets = pygame.sprite.Group() self.enemies = pygame.sprite.Group() self.enemyBullet = pygame.sprite.Group() self.chests = pygame.sprite.Group() self.allUpgrades = pygame.sprite.Group() self.allDrops = pygame.sprite.Group() self.savers = pygame.sprite.Group() self.texts = {} self.hasBoss = False if name == 'nt': if mapPath == '../Maps\\mapBoss1.tmx': self.hasBoss = True else: if mapPath == '../Maps/mapBoss1.tmx': self.hasBoss = True if self.hasBoss: self.boss = BossController(self) for i in self.map.tmdata.objects: if i.name == 'spawn': self.player = Player(self, 1, i.x, i.y) if self.hasBoss: self.boss.setSpawn(i.x, i.y) elif i.name == 'wall': Wall(self, i.x, i.y, i.width, i.height) elif i.name == 'end': End(self, i.x, i.y, i.width, i.height) elif i.name == 'hole': Hole(self, i.x, i.y, i.width, i.height) elif i.name == 'spike': Spike(self, i.x, i.y, i.width, i.height, i.type) elif i.name == 'enemy': if not self.hasBoss: Enemy(self, i.x, i.y, i.width, i.height) else: self.boss.addEnemiesArena(i.x, i.y, i.width, i.height) elif i.name == 'chest': Chest(self, i.x, i.y, i.width, i.height) elif i.name == 'save': Save(self, self.menu, i.x, i.y, i.width, i.height) elif i.name == 'boss': self.boss.setPos(i.x, i.y) elif i.name == 'bossCopy': self.boss.addCopy(i.x, i.y) elif i.name == 'spawn1': self.boss.setSpawn1(i.x, i.y) elif i.name == 'spawn2': self.boss.setSpawn2(i.x, i.y) elif i.name == 'bossSpawn': self.boss.setBossSpawn(i.x, i.y) elif i.name == 'enemyAfter': self.boss.addEnemiesAfter(i.x, i.y) self.hud = Hud(self) self.camera = Camera(self.mapRect.width, self.mapRect.height) print(self.walls) print(self.triggers) print(self.mapsAlreadyPlayed)
def getEndResults(self): player = 2 - ((self.turnCount + 1) % 2) winP = End.winner(self.board, player) pts = End.points(self.board, player) return (winP, pts)
def testNoRoad(takGame): aux.resetBoard(takGame) ans = End.road(takGame.board) assert not ans[0] and not ans[1]