def draw_active_game_screen(self): galaxyBoundingBox = self.player.starChart.print( self.player, 0, 0, range(0, Constants.GALAXY_SIZE), range(0, Constants.GALAXY_SIZE)) rect = Drawing.print_at(0, galaxyBoundingBox.bottom + 5, 'Current Sector: {0}', self.player.galaxy_coord) sectorBox = self.galaxy[self.player.galaxy_coord].print_sector( 0, rect.bottom + 1) statusBox = self.player.display_status(sectorBox.right + 5, rect.bottom + 1, self) # display current input prompt, input text, and error message if any UserInput.drawInput(0, sectorBox.bottom + 5) # Display fading/scrolling messages, if any lineator = Drawing.Lineator(statusBox.right + 15, sectorBox.top) nextList = list() for i, m in enumerate(self.msgList): if m.expiration is None: m.expiration = datetime.datetime.now() + datetime.timedelta( seconds=5) if m.expiration > datetime.datetime.now(): nextList.append(m) lineator.print(m.message) self.msgList = nextList
def print_sector(self, left, top): lineator = Drawing.Lineator(left, top) lineator.print( "{:>2}{:^3}{:^3}{:^3}{:^3}{:^3}{:^3}{:^3}{:^3}{:^3}{:^3}".format( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) for r in range(Constants.SECTOR_SIZE): lineator.print("{:>2}".format(r + 1), end='') for c in range(Constants.SECTOR_SIZE): coord = Coordinate(r, c) if coord in self.map: lineator.print(' ', self.map[coord].asChar(), ' ', sep='', end='') else: lineator.print(' . ', sep='', end='') lineator.print('') lineator.drawBoundingRect(fill='purple', outline='yellow', background=True) return lineator.bbox
def display_status(self, left, top, game): hasEnemies = not not self.sector.klingons if hasEnemies: condition = "RED!" elif self.energy < Constants.YELLOW_ALERT_ENERGY: condition = "Yellow" else: condition = "Green" lineator = Drawing.Lineator(left, top) lineator.print(' Star Date:', game.stardate / 100) lineator.print(' Condition:', condition) lineator.print(' Position:', self.galaxy_coord, '@', self.sector_coord) lineator.print('Life Support:', 'ACTIVE') lineator.print(' Warp Factor:', 'N/A') lineator.print(' Torps:', self.torps) lineator.print(' Energy:', self.energy) lineator.print(' Shield:', self.shield) lineator.print( ' Klingons:', game.cur_klingons + game.cur_commanders + game.cur_superCommanders) lineator.print(' Time:', game.remaining_time) return lineator.bbox
def print(self, player, left, top, rows: range, cols: range): lineator = Drawing.Lineator(left, top) playerIsRightCol = (player.galaxy_coord.col == Constants.GALAXY_SIZE - 1) isHidden = True for r in rows: if r not in self.size: continue playerIsThisRow = (r == player.galaxy_coord.row) # draw top border self.printRowSep(player, lineator, r, cols) # print top data row for sector for c in cols: isHidden = Coordinate(r, c) not in self if playerIsThisRow and (c == player.galaxy_coord.col or c - 1 == player.galaxy_coord.col): lineator.print('* ', end='') else: lineator.print('| ', end='') if not isHidden: s = self[Coordinate(r, c)] lineator.print('s:', s.stars, 'k:', s.klingons, sep=' ', end=' ') else: lineator.print(' ', ' ', ' ', ' ', sep=' ', end=' ') # print right hand cell separator if playerIsThisRow and playerIsRightCol: lineator.print('*', end='') else: lineator.print('|', end='') lineator.print('') # print second row for c in cols: isHidden = Coordinate(r, c) not in self if playerIsThisRow and (c == player.galaxy_coord.col or c - 1 == player.galaxy_coord.col): lineator.print('* ', end='') else: lineator.print('| ', end='') if not isHidden: s = self[Coordinate(r, c)] lineator.print('b:', s.bases, 'p:', s.planets, sep=' ', end=' ') else: lineator.print(' ', ' ', ' ', ' ', sep=' ', end=' ') # print right hand cell separator if playerIsThisRow and playerIsRightCol: lineator.print('*', end='') else: lineator.print('|', end='') lineator.print('') # draw bottom self.printRowSep(player, lineator, Constants.GALAXY_SIZE, cols) return lineator.bbox