コード例 #1
0
ファイル: colortest.py プロジェクト: drestuart/delvelib
def printColorMessages(win, messages):
    
    y = 0
    
    for line in messages:
        charsPrinted = 0
        wordsPrinted = 0
        wordsInLine = 0
        for (text, fg, bg) in line:
            wordsInLine += len(text.split())
        
        for (text, fg, bg) in line:
            words = text.split()
            
            for word in words:
                if len(word) + charsPrinted > width:
                    print "Word wrap!"
                    win.write("\n")
                    y += 1
                    charsPrinted = 0
                
                if wordsPrinted < wordsInLine - 1:
                    word = word + ' '
                    
                win.write(word, y=y, fgcolor=fg, bgcolor=bg)
                charsPrinted += len(word)
                wordsPrinted += 1
                print charsPrinted
                
        win.write("\n")
        y += 1
        
    pygcurse.waitforkeypress()
コード例 #2
0
ファイル: rl.py プロジェクト: vrum/AtlasWarriors
def LoseGame (win):
	win.setscreencolors('lime', 'black', clear=True)
	win.putchars('For you, the dream ends here.', 6, 5, 'white')
	win.putchars('You have died.', 14, 10, 'white')
	win.putchars('Well. That sucks.', 13, 15, 'white')
	score = scores.CalculateScore(Maps, PC, difficulty, 0)	
	win.putchars('Score: ' + str(score), 2, 17, 'red')
		
	win.update() 
	pygcurse.waitforkeypress()	
	pygcurse.waitforkeypress()	
	pygame.quit()	
	sys.exit()	
コード例 #3
0
ファイル: RN2_UI.py プロジェクト: whgest/roguenaissance2
 def display_intro(self, text):
     self.clear_screen_tint()
     self.draw_border()
     lines = 3
     for t in text.splitlines():
         if "$s" in t:
             #self.play_sound(p.split()[1])
             pass
         elif t == "$p":
             pygcurse.waitforkeypress()
         else:
             lines = self.text_wrapper(t, 2, lines)
         self.screen.update()
     return
コード例 #4
0
    def showMessage(self, header, message, width=20, height=10):
        """
        This function will show a pop up message in the middle of the screen.
        It waits for the user to acknowledge the message by hitting enter or
        escape
        """

        # store the current window for easy restore when we are done
        self.win.push_surface()

        # Show in the middle of the screen.
        menu_region = (
            self.win.centerx / 2,
            self.win.centery / 2 + (height / 2),
            width,
            height)

        textbox = pygcurse.PygcurseTextbox(
            self.win,
            region=menu_region,
            fgcolor=colors.white,
            bgcolor=colors.dark_sepia,
            caption=header,
            text=message,
            margin=2,
            wrap=True,
            border='.')

        # tell the textbox to draw itself onto our win canvas
        textbox.update()

        # update the screen and handle keypresses
        self.win.update()
        menu_busy = True
        result = ''
        while menu_busy:
            key = pygcurse.waitforkeypress(LIMIT_FPS)
            print(key)
            if key == 'escape':
                result = 'Escape'
                break
            elif key in ('enter', 'return'):
                result = 'Enter'
                break

        # restore to original window
        self.win.pop_surface()
        return result
コード例 #5
0
ファイル: main.py プロジェクト: thorvalddox/undeadwar4
 def get_result(self, options):
     selection = 0
     key = ""
     while key != " ":
         if key == "w":
             selection -= 1
         elif key == "s":
             selection += 1
         selection = (selection + len(options)) % len(options)
         self.textbox.text = "\n".join(("> " if i == selection else "  ") + o for i, o in enumerate(options))
         self.textbox.update()
         self.parent.update()
         key = pygcurse.waitforkeypress()
     self.textbox.text = ""
     self.textbox.update()
     self.parent.update()
     return selection
コード例 #6
0
ファイル: main.py プロジェクト: thorvalddox/undeadwar4
    def select_tile(self, redcode=always_false):
        self.redcode = redcode
        key = ""
        while key != " ":

            if key == "w":
                self.sely -= 1
            elif key == "s":
                self.sely += 1
            elif key == "a":
                self.selx -= 1
            elif key == "d":
                self.selx += 1
            for e in self.parent.get_entities(self.selx, self.sely):
                e.show_right()
            self.parent.update()
            key = pygcurse.waitforkeypress()
        return (self.selx, self.sely)
コード例 #7
0
    def showMessage(self, header, message, width=20, height=10):
        """
        This function will show a pop up message in the middle of the screen.
        It waits for the user to acknowledge the message by hitting enter or
        escape
        """

        # store the current window for easy restore when we are done
        self.win.push_surface()

        # Show in the middle of the screen.
        menu_region = (self.win.centerx / 2,
                       self.win.centery / 2 + (height / 2), width, height)

        textbox = pygcurse.PygcurseTextbox(self.win,
                                           region=menu_region,
                                           fgcolor=colors.white,
                                           bgcolor=colors.dark_sepia,
                                           caption=header,
                                           text=message,
                                           margin=2,
                                           wrap=True,
                                           border='.')

        # tell the textbox to draw itself onto our win canvas
        textbox.update()

        # update the screen and handle keypresses
        self.win.update()
        menu_busy = True
        result = ''
        while menu_busy:
            key = pygcurse.waitforkeypress(LIMIT_FPS)
            print(key)
            if key == 'escape':
                result = 'Escape'
                break
            elif key in ('enter', 'return'):
                result = 'Enter'
                break

        # restore to original window
        self.win.pop_surface()
        return result
コード例 #8
0
ファイル: dungeonview.py プロジェクト: dangillet/Pythoria
        """
        Calculate first the top left position of the DungeonView and
        draw DungeonView.
        """
        self.left = clamp(self.player.x - self.width // 2,
                          0, 
                          max(0, self.dungeon_width - self.width))
        self.top = clamp(self.player.y - self.height // 2,
                         0,
                         max(0, self.dungeon_height - self.height))
        self.dungeon_view.draw(self.left, self.top, self.width, self.height)
        
    def blitto(self, *args, **kwargs):
        """
        Pass on the blitting to the DungeonView.
        """
        self.dungeon_view.blitto(*args, **kwargs)
        

if __name__ == '__main__':
    import dungeon, player
    win = pygcurse.PygcurseWindow(40,30)
    level1 = Dungeon.load_from_file('../test/map.txt')
    level1.add_player(player.Player(1, 1))
    view = DungeonView(level1, 10, 10)
    view.draw()
    view.blitto(win.surface)
    win.blittowindow()
    
    pygcurse.waitforkeypress()
コード例 #9
0
import sys
import os
sys.path.append(os.path.abspath('./lib/pygcurse'))

import pygcurse
from lib.Object import Object

print(Object('wall'))

win = pygcurse.PygcurseWindow(40, 25, 'Hello World')
win.pygprint('Hello!!')
pygcurse.waitforkeypress()
コード例 #10
0
    def handleKeys(self):
        """
        Handle any keyboard presses.
        """

        key = pygcurse.waitforkeypress(LIMIT_FPS)
        if key == 'escape':
            return 'exit'

        # this defines all they movement keys we can handle.
        # it supports various layouts: vi keys, keypad, arrows
        movement_keys = {
                    'h': (-1, +0),       # vi keys
                    'l': (+1, +0),
                    'j': (+0, +1),
                    'k': (+0, -1),
                    'y': (-1, -1),
                    'u': (+1, -1),
                    'b': (-1, +1),
                    'n': (+1, +1),
                    '[4]': (-1, +0),     # numerical keypad
                    '[6]': (+1, +0),
                    '[2]': (+0, +1),
                    '[8]': (+0, -1),
                    '[7]': (-1, -1),
                    '[9]': (+1, -1),
                    '[1]': (-1, +1),
                    '[3]': (+1, +1),
                    'left': (-1, +0),    # arrows and pgup/dn keys
                    'right': (+1, +0),
                    'down': (+0, +1),
                    'up': (+0, -1),
                    'home': (-1, -1),
                    'pageup': (+1, -1),
                    'end': (-1, +1),
                    'pagedown': (+1, +1),
                    }

        if self.game.state == Game.PLAYING:
            player = self.game.player

            # movement
            if key in movement_keys:
                # the * here is Python syntax to unpack a list.
                # this allows us to pass a list as parameters.
                # http://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists
                player.tryMoveOrAttack(*movement_keys[key])

            #portal keys
            elif key == '>':
                player.tryFollowPortalDown()
                # clear characters
                self.win.setscreencolors(clear=True)
            elif key == '<':
                player.tryFollowPortalUp()
                # clear characters
                self.win.setscreencolors(clear=True)
            #inventory
            elif key == 'i':
                self.useInventory()
            elif key == 'd':
                self.dropInventory()
            #interact
            elif key == ',':
                player.tryPickUp()
                
            # update field of vision
            self.game.currentLevel.map.updateFieldOfView(
                player.tile.x, player.tile.y)
コード例 #11
0
    def showMenu(self, header, options, width=20, height=10):
        """
        This function will show a menu. The application waits for user input
        before returning the selected option.
        The function will return None if the user escapes the menu.
        Arguments
            header - String, text for the header
            options - String list, text for the options
            width - Width (in characters) of the menu box
        """
        if len(options) > 26:
            raise ValueError('Cannot have a menu with more than 26 options.')

        #store the current view
        self.win.push_surface()

        # Show in the middle of the screen.
        menu_region = (
            self.win.centerx / 2,
            self.win.centery / 2 + (height / 2),
            width,
            height)

        # a list from a-n, where n is the length of our options
        hotkeys = [chr(ord('a') + i) for i in range(0, len(options))]

        # build a menu from the options list by prefixing each with a hotkey
        # then join them together with newlines.
        menu_choices = []
        for counter, option_text in enumerate(options):
            menu_choices.append('(%s) %s' % ((hotkeys[counter]), option_text))
        menu_choices = '\n'.join(menu_choices)

        # construct the menu as a textbox object. It recognizes newlines.
        # this guy draw a nice border for us too.
        
        #TODO: Frost: there is a problem here
        # the menu_region might be too small to contain all the menu items.
        # The height has to be calculated based on the number of menu items.
        # I think the showMessage function suffers from the same problem
        # (if you give it a really long text) 
        txt = pygcurse.PygcurseTextbox(
            self.win,
            region=menu_region,
            fgcolor=colors.white,
            bgcolor=colors.transparent,
            caption=header,
            text=menu_choices,
            margin=2,
            wrap=True,
            border='.')
        txt.update()

        # update the screen and handle keypresses
        self.win.update()
        menu_busy = True
        while menu_busy:
            key = pygcurse.waitforkeypress(LIMIT_FPS)
            if key is None or key == 'escape':
                return_value = None
                break
            if key in hotkeys:
                return_value = hotkeys.index(key)
                break

        #go back to the previous view
        self.win.pop_surface()
        
        return return_value
コード例 #12
0
ファイル: rl.py プロジェクト: lkingsford/AtlasWarriors
def WinGame (victoryCondition, win):
    if victoryCondition == 1:
        win.setscreencolors('lime', 'black', clear=True)    
        win.putchars('Congratulations!', 1, 2, 'white', 'black')
        win.putchars('The mighty warlord has been slain', 1, 3, 'white', 'black')
        win.putchars('at last!', 1, 4, 'white', 'black')
        win.putchars('It may not last, but peace is upon', 1, 5, 'white', 'black')
        win.putchars('this part of Atlas.', 1, 6, 'white', 'black')
        
    elif victoryCondition == 2:
        win.setscreencolors('lime', 'black', clear=True)    
        win.putchars('Congratulations!', 1, 2, 'white', 'black')
        win.putchars('The mighty warlord has been slain', 1, 3, 'white', 'black')
        win.putchars('It may not have been by your hand, but', 1, 4, 'white', 'black')
        win.putchars('this part of Atlas is at least for now,', 1, 5, 'white', 'black')
        win.putchars('in peace.', 1, 6, 'white', 'black')
    
    elif victoryCondition == 3:
        win.setscreencolors('lime', 'black', clear=True)    
        win.putchars('The mighty warlord has been slain', 1, 3, 'white', 'black')
        win.putchars('by the horrible demonic goliath.', 1, 4, 'white', 'black')
        win.putchars('Absorbing his vast power, the ', 1, 5, 'white', 'black')
        win.putchars('unholy beast unleashes hell upon', 1, 6, 'white', 'black')
        win.putchars('Atlas.', 1, 7, 'white', 'black')
        win.putchars('Doom awaits those who survive.', 1, 7, 'white', 'black')
    
    elif victoryCondition == 4:
        win.setscreencolors('lime', 'black', clear=True)    
        win.putchars('The mighty warlord has been slain', 1, 3, 'white', 'black')
        win.putchars('by the apocalyptic goliath.', 1, 4, 'white', 'black')
        win.putchars('Absorbing his vast power, the ', 1, 5, 'white', 'black')
        win.putchars('unholy beast unleashes a wave', 1, 6, 'white', 'black')
        win.putchars('of destruction that clouds', 1, 7, 'white', 'black')
        win.putchars('Atlas in fire and desolation', 1, 8, 'white', 'black')
        win.putchars('leaving nothing.', 1, 9, 'white', 'black')
        win.putchars('You achieved your goal of', 1, 10, 'white', 'black')
        win.putchars('bringing peace to Atlas.', 1, 11, 'white', 'black')
        win.putchars('You have done so eternally.', 1, 12, 'white', 'black')
        
    elif victoryCondition == 5:
        win.setscreencolors('lime', 'black', clear=True)    
        win.putchars('The mighty warlord has been slain', 1, 3, 'white', 'black')
        win.putchars('by the Mortreon, the True Dragon.', 1, 4, 'white', 'black')
        win.putchars('Mortreon absorbs the explosion of', 1, 5, 'white', 'black')
        win.putchars('power in its entirity and' , 1, 6, 'white', 'black')
        win.putchars('unleashes an almighty roar', 1, 7, 'white', 'black')
        win.putchars('resurrecting Eon, the God King of', 1, 8, 'white', 'black')
        win.putchars('Dragons.', 1, 9, 'white', 'black')
        win.putchars('The second age of Eon will', 1, 10, 'white', 'black')
        win.putchars('come.', 1, 11, 'white', 'black')
        win.putchars('The sons of Eon will reign.', 1, 12, 'white', 'black')     
        
    elif victoryCondition == 6:
        win.setscreencolors('lime', 'black', clear=True)    
        win.putchars('The mighty warlord has been slain', 1, 3, 'white', 'black')
        win.putchars('by the blackest of the black', 1, 4, 'white', 'black')
        win.putchars('The Necromancer grins as his ', 1, 5, 'white', 'black')
        win.putchars('flesh rots away under the', 1, 6, 'white', 'black')
        win.putchars('force of his absorbed power.', 1, 7, 'white', 'black')
        win.putchars('With the power of the warlord', 1, 8, 'white', 'black')
        win.putchars('the Necromancer enslaves', 1, 9, 'white', 'black')
        win.putchars('Atlas. And what of his body?', 1, 10, 'white', 'black')
        win.putchars('Bodies are for mortal men.', 1, 11, 'white', 'black')
    
    score = scores.CalculateScore(Maps, PC, difficulty, victoryCondition)   
    win.putchars('Score: ' + str(score), 2, 17, 'red', 'black')
    win.update();
    screen.blit(surface,(0,0))
    pygame.display.update()
    pygame.display.flip()
    
    pygcurse.waitforkeypress()
    pygcurse.waitforkeypress()       
コード例 #13
0
ファイル: RN2_UI.py プロジェクト: whgest/roguenaissance2
def main():
    RN_UI = RN_UI_Class()
    RN_UI.draw_UI()
    RN_UI.print_legend([[".", "red", "grass"]], [["@", "white", "hero"]])
    pygcurse.waitforkeypress()
コード例 #14
0
ファイル: RN2_UI.py プロジェクト: whgest/roguenaissance2
 def wait_for_keypress():
     pygcurse.waitforkeypress()
     return
コード例 #15
0
    def handleKeys(self):
        """
        Handle any keyboard presses.
        """

        key = pygcurse.waitforkeypress(LIMIT_FPS)
        if key == 'escape':
            return 'exit'

        # this defines all they movement keys we can handle.
        # it supports various layouts: vi keys, keypad, arrows
        movement_keys = {
            'h': (-1, +0),  # vi keys
            'l': (+1, +0),
            'j': (+0, +1),
            'k': (+0, -1),
            'y': (-1, -1),
            'u': (+1, -1),
            'b': (-1, +1),
            'n': (+1, +1),
            '[4]': (-1, +0),  # numerical keypad
            '[6]': (+1, +0),
            '[2]': (+0, +1),
            '[8]': (+0, -1),
            '[7]': (-1, -1),
            '[9]': (+1, -1),
            '[1]': (-1, +1),
            '[3]': (+1, +1),
            'left': (-1, +0),  # arrows and pgup/dn keys
            'right': (+1, +0),
            'down': (+0, +1),
            'up': (+0, -1),
            'home': (-1, -1),
            'pageup': (+1, -1),
            'end': (-1, +1),
            'pagedown': (+1, +1),
        }

        if self.game.state == Game.PLAYING:
            player = self.game.player

            # movement
            if key in movement_keys:
                # the * here is Python syntax to unpack a list.
                # this allows us to pass a list as parameters.
                # http://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists
                player.tryMoveOrAttack(*movement_keys[key])

            #portal keys
            elif key == '>':
                player.tryFollowPortalDown()
                # clear characters
                self.win.setscreencolors(clear=True)
            elif key == '<':
                player.tryFollowPortalUp()
                # clear characters
                self.win.setscreencolors(clear=True)
            #inventory
            elif key == 'i':
                self.useInventory()
            elif key == 'd':
                self.dropInventory()
            #interact
            elif key == ',':
                player.tryPickUp()

            # update field of vision
            self.game.currentLevel.map.updateFieldOfView(
                player.tile.x, player.tile.y)
コード例 #16
0
    def showMenu(self, header, options, width=20, height=10):
        """
        This function will show a menu. The application waits for user input
        before returning the selected option.
        The function will return None if the user escapes the menu.
        Arguments
            header - String, text for the header
            options - String list, text for the options
            width - Width (in characters) of the menu box
        """
        if len(options) > 26:
            raise ValueError('Cannot have a menu with more than 26 options.')

        #store the current view
        self.win.push_surface()

        # Show in the middle of the screen.
        menu_region = (self.win.centerx / 2,
                       self.win.centery / 2 + (height / 2), width, height)

        # a list from a-n, where n is the length of our options
        hotkeys = [chr(ord('a') + i) for i in range(0, len(options))]

        # build a menu from the options list by prefixing each with a hotkey
        # then join them together with newlines.
        menu_choices = []
        for counter, option_text in enumerate(options):
            menu_choices.append('(%s) %s' % ((hotkeys[counter]), option_text))
        menu_choices = '\n'.join(menu_choices)

        # construct the menu as a textbox object. It recognizes newlines.
        # this guy draw a nice border for us too.

        #TODO: Frost: there is a problem here
        # the menu_region might be too small to contain all the menu items.
        # The height has to be calculated based on the number of menu items.
        # I think the showMessage function suffers from the same problem
        # (if you give it a really long text)
        txt = pygcurse.PygcurseTextbox(self.win,
                                       region=menu_region,
                                       fgcolor=colors.white,
                                       bgcolor=colors.transparent,
                                       caption=header,
                                       text=menu_choices,
                                       margin=2,
                                       wrap=True,
                                       border='.')
        txt.update()

        # update the screen and handle keypresses
        self.win.update()
        menu_busy = True
        while menu_busy:
            key = pygcurse.waitforkeypress(LIMIT_FPS)
            if key is None or key == 'escape':
                return_value = None
                break
            if key in hotkeys:
                return_value = hotkeys.index(key)
                break

        #go back to the previous view
        self.win.pop_surface()

        return return_value