def setText(s, text, title=None, dark=None): if dark is not None: s.dark = dark s.clr = getColors(s.dark, s.opacity) if title is not None: s.title = title s.correct_text = text s.correct_len = len(s.correct_text) s.mistakes = 0 s.t.clear()
def __init__(s, text, dark=False, title='Recite', rtl=False, filterText=None, wrongScore=None, msgTxt='<b>Well done!</b>', msgInfo='Your accuracy is %.2f%%.', msgOther='Another Recitation', msgRepeat='Repeat Recitation', msgQuit='Quit', otherRecitation=None): super().__init__() s.filterText = filterText if filterText is not None else lambda t: t s.wrongScore = wrongScore if wrongScore is not None else lambda isPrevWrong, **kw: 0 if isPrevWrong else 1 s.rtl = rtl s.msgTxt = msgTxt s.msgInfo = msgInfo s.msgOther = msgOther s.msgRepeat = msgRepeat s.msgQuit = msgQuit s.otherRecitation = otherRecitation # s.setWindowTitle(title) s.setWindowFlags(Qt.FramelessWindowHint) s.setAttribute(Qt.WA_NoSystemBackground) s.setAttribute(Qt.WA_TranslucentBackground) s.setAttribute(Qt.WA_TransparentForMouseEvents) # s.t = QTextEdit() s.setCentralWidget(s.t) s.t.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) s.t.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # s.correct_text = text s.correct_len = len(s.correct_text) s.opacity = 255 s.dark = dark s.clr = getColors(s.dark, s.opacity) s.mistakes = 0 # see https://github.com/wereturtle/ghostwriter/issues/206 for QPlainTextEdit s.t.setFont(QFont("Amiri", 18)) s.t.setStyleSheet(s.clr['normal']) # QShortcut(QKeySequence('Ctrl++'), s).activated.connect(s.t.zoomIn) QShortcut(QKeySequence('Ctrl+-'), s).activated.connect(s.t.zoomOut) QShortcut(QKeySequence('Ctrl+*'), s).activated.connect(s.moreOpaque) QShortcut(QKeySequence('Ctrl+/'), s).activated.connect(s.lessOpaque) QShortcut(QKeySequence('Ctrl+^'), s).activated.connect(s.toggleDark) # s.t.textChanged.connect(s.updateColors)
import random from logbox import Message from game_states import State from colors import getColors colors = getColors() def get_entities_at(entities, x, y): for entity in entities: if entity.px == x and entity.py == y: return entity def get_blocking_entities_at(entities, x, y): for entity in entities: if entity.px == x and entity.py == y and entity.stopper: return entity def kill_player(player): player.tile = '%' player.color = colors.get('dark_red') message = Message('You DIED!', colors.get('orange')) return message def kill_monster(monster): death_message = Message('{0} is dead!'.format(monster.name.capitalize()), colors.get('orange'))
def toggleDark(s): s.dark = not s.dark s.clr = getColors(s.dark, s.opacity) s.updateColors()
def moreOpaque(s): s.opacity += OPACITY_STEP if s.opacity > 255: s.opacity = 255 s.clr = getColors(s.dark, s.opacity) s.updateColors()
def lessOpaque(s): s.opacity -= OPACITY_STEP if s.opacity < 0: s.opacity = 0 s.clr = getColors(s.dark, s.opacity) s.updateColors()
import colors import sys import matplotlib.pyplot as plt import numpy as np from random import random plotColors = colors.getColors().keys() # Get the set to pull from from the command line SetNum = sys.argv[1] def extractEffDataFromFile(pathToResults,runNum): wavelengths = [] effVals = [] effUncert = [] fileName = pathToResults+'Run'+str(runNum)+'/effData.csv' dataFileIn = open(fileName,'r').read().split('\n') for line in dataFileIn[1:]: if line == '': continue tempLine = line.split(',') wavelengths.append(float(tempLine[0])) effVals.append(float(tempLine[1])) effUncert.append(float(tempLine[2])) return wavelengths,effVals,effUncert def consolidateDiff(dataSet): fullWavelengths = [] effVals = [] effUncert = []
class __Engine: """ Handle game variables and functions. """ title = 'excelsior' font = 'fonts/cp437_12x12.png' altLayout = False greyscale = True screen_width = 80 screen_height = 50 message_x = 4 message_width = screen_width - 4 message_height = 7 mouse = (0, 0) mouse_x, mouse_y = mouse mousedown = False pc_hud_x = int(screen_width / 2) - 17 pc_hud_y = screen_height - 19 en_hud_x = int(screen_width / 2) - 20 en_hud_y = 5 started = False state = State.MENU animation_playing = False combat_locked = False over = False endtext = '' upgd_selec = '' dungeon_levels = 6 dungeon = [] current_level = Room() creature_database = get_monster_data('data/monsters.json') skill_database = get_skill_data('data/skills.json') colors = getColors() def __init__(self): pskills = [ copy.deepcopy(self.skill_database[0]), copy.deepcopy(self.skill_database[1]), copy.deepcopy(self.skill_database[2]), copy.deepcopy(self.skill_database[3]) ] pc_fighter = { 'hp': 50, 'atk': 15, 'df': 10, 'spd': 15, 'skills': pskills } self.__pc = PC('Player', fighter=pc_fighter) def gen_dungeon(self, levels): self.dungeon = [] for amount in range(levels): level = Room(weight=amount) candidates = [] for creature in self.creature_database: creature.skills = [copy.deepcopy(self.skill_database[0])] if creature.weight <= level.weight: candidates.append(copy.deepcopy(creature)) if candidates: level.entity = random.choice(candidates) self.dungeon.append(level) if amount == 0: self.current_level = self.dungeon[0] def next_level(self): c = 0 for level in self.dungeon: if self.current_level == level: self.current_level = self.dungeon[c + 1] break c += 1 def return_player(self): return copy.deepcopy(self.__pc) def reset(self): self.gen_dungeon(self.dungeon_levels)
def main(): Game = Engine() colors = getColors() show_upgd_menu = False # TDL init tdl.set_font(Game.font, greyscale=Game.greyscale, altLayout=Game.altLayout) root_console = tdl.init(Game.screen_width, Game.screen_height, title=Game.title) # Gameplay screen con = tdl.Console(Game.screen_width, Game.screen_height) # UI Panel panel = tdl.Console(Game.screen_width, Game.panel_height) # Upgrade Screen upgd = tdl.Console(Game.screen_width, Game.panel_height) # TODO: Change later. GameMap object and Engine Object game_map = GameMap(Game.map_width, Game.map_height) Game.gen_dungeon(5) entities = [] # Player init pskills = [getSkill('punch'), getSkill('kick'), getSkill('scratch')] pc_combatant = Combat(hp=500, sp=100, ar=15, df=10, spd=15, skills=pskills) pc = PC(1, 1, 'Player', combat=pc_combatant) # TODO: Include Player at first. Change Later # Game.dungeon[0].entities.append(pc) entities.append(pc) state = State.PLAYER_TURN Game.dungeon[0].rooms = make_map(game_map, Game.max_rooms, Game.room_min_size, Game.room_max_size, Game.map_width, Game.map_height, pc) Game.dungeon[0].populate(1, 2) fov_recompute = True message_log = MessageLog(Game.message_x, Game.message_width, Game.message_height) if Game.starting: message_log.add_message(Message('Welcome to Hell')) Game.starting = False # TODO: Change later. Easy access for entity list for entity in Game.dungeon[0].entities: entities.append(entity) print(entity.tile, entity.name, entity.px, entity.py) # Draw while not tdl.event.is_window_closed(): # Recompute Field of View when necessary if fov_recompute: game_map.compute_fov(pc.px, pc.py, fov=Game.fov_algorithm, radius=Game.fov_radius, light_walls=Game.fov_light_walls) # Render everything on screen render_all(con, panel, entities, pc, game_map, fov_recompute, root_console, message_log, Game, colors) # ------------------------------- if show_upgd_menu: upgd.clear(fg=colors.get('white'), bg=colors.get('black')) upgd.draw_str(1, 1, 'Status:') upgd.draw_str(10, 1, pc.name) upgd.draw_str(1, 6, 'Skills') y = 8 for skill in pc.combat.skills: upgd.draw_str(1, y, ' -' + skill.name) y += 1 upgd.draw_str(20, 6, 'Souls:') upgd.draw_str(28, 6, str(pc.soulstack)) """ upgd.draw_str(20, 6, 'Souls') y = 8 for soul in pc.soulstack: upgd.draw_str(20, y, ' -'+ soul.name) y += 1 """ root_console.blit(upgd, 0, 0, Game.screen_width, Game.screen_height, 0, 0) # ------------------------------- tdl.flush() # Clear all entities previous locations. Prevents ghost images clear_all(con, entities, pc) fov_recompute = False # Handle events for event in tdl.event.get(): if event.type == 'KEYDOWN': user_input = event break elif event.type == 'MOUSEMOTION': Game.mouse_coordinates = event.cell # If no input matches KEYDOWN, set user_input to None else: user_input = None # If there is no input, continue checking. This means the game only continues if there's user input (Keypress). if not user_input: continue # Input actions action = handle_keys(user_input) pmove = action.get('pmove') quit = action.get('quit') fullscreen = action.get('fullscreen') upgd_menu = action.get('upgd_menu') # Varible to hold results from player turn player_turn_results = [] # Player movement and controls if pmove and state == State.PLAYER_TURN and not show_upgd_menu: dx, dy = pmove fx = pc.px + dx fy = pc.py + dy if fx < Game.map_width and fy < Game.map_height: if game_map.walkable[fx, fy]: target = get_blocking_entities_at(entities, fx, fy) if target and target is not pc: skill = pc.combat.skills[random.randint( 0, len(pc.combat.skills) - 1)] attack_results = pc.combat.attack(target, skill) player_turn_results.extend(attack_results) else: pc.move(dx, dy) fov_recompute = True state = State.ENEMY_TURN if quit: return True if fullscreen: tdl.set_fullscreen(not tdl.get_fullscreen()) if upgd_menu: show_upgd_menu = not show_upgd_menu # Handle results from player turn for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == pc: message = kill_player(dead_entity) state = State.PLAYER_DEAD else: message, soul = kill_monster(dead_entity) pc.absorb(soul) message_log.add_message(message) # Handle enemy turn if state == State.ENEMY_TURN and not show_upgd_menu: for entity in entities: # Enemies act if entity.ai: enemy_turn_results = entity.ai.act(pc, game_map, entities) # Handle results for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == pc: message = kill_player(dead_entity) state = State.PLAYER_DEAD else: message, soul = kill_monster(dead_entity) pc.absorb(soul) message_log.add_message(message) if state == State.PLAYER_DEAD: break if state == State.PLAYER_DEAD: break else: state = State.PLAYER_TURN