Beispiel #1
0
    def main(self):
        r = renderer.TermRenderer(pygcurse.PygcurseWindow(48, 27))

        while True:
            self.server.calculateLineOfSight()
            self.stateMachine.render(r)
            self.server.refreshForActor(self.actor)
Beispiel #2
0
def run_random_walk(draw=False):
    """Run the random walk and return the final snake length.

    Drawing may be enabled.

    """
    game = Game(WINWIDTH, WINHEIGHT)
    game.drawing_enabled = draw

    if game.drawing_enabled:
        win = pygcurse.PygcurseWindow(WINWIDTH, WINHEIGHT + 4, fullscreen=False)
        pygame.display.set_caption("Window Title")
        win.autoupdate = False
        clock = pygame.time.Clock()

        while not game.ended:
            for event in pygame.event.get():
                LOGGER.log(5, f"event: {event}")

                # Escape to quit
                if event.type == pl.QUIT or (
                    event.type == pl.KEYDOWN and event.key == pl.K_ESCAPE
                ):
                    terminate()

            win.fill(bgcolor="blue")
            random_walk(game)
            game.draw(win)
            win.update()
            clock.tick(FPS)
    else:
        while not game.ended:
            random_walk(game)
    return game.snake_length
Beispiel #3
0
def drawer():
    win = pygcurse.PygcurseWindow(config['board']['w'], config['board']['h'], fgcolor='black')
    win.setscreencolors(None, 'white', clear=True)
    drag = False
    startEnd = []
    while len(startEnd) < 2:
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()
            if event.type == pygame.MOUSEBUTTONUP:
                coordinate = win.getcoordinatesatpixel(event.pos)
                win.write('@', *coordinate)
                startEnd.append(coordinate)

    walls = set()
    while True:
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                drag = True
            elif event.type == pygame.MOUSEBUTTONUP:
                drag = False
            elif event.type == pygame.MOUSEMOTION:
                if drag:
                    coordinate = win.getcoordinatesatpixel(event.pos)
                    win.write('#', *coordinate)
                    walls.add(coordinate)
            elif event.type == pygame.KEYDOWN:
                if config['algo'] == 'bfs':
                    bfs(win, startEnd, walls)
Beispiel #4
0
def main():
    log_fmt = "%(asctime)s %(name)s[%(lineno)d] %(levelname)s %(message)s"
    coloredlogs.install(level=logging.DEBUG, fmt=log_fmt)
    win = pygcurse.PygcurseWindow(WINWIDTH, WINHEIGHT + 4, fullscreen=False)
    pygame.display.set_caption("Window Title")
    win.autoupdate = False
    clock = pygame.time.Clock()

    game = Game(WINWIDTH, WINHEIGHT)
    # print(game.maze())

    while True:
        win.fill(bgcolor="blue")
        # time.sleep(0.01)
        if game.endstate == True:
            time.sleep(1)
            terminate()
        game.find_move_a_star(win)
        # game.terminate()
        # handle_events(game)
        handle_exit(game)
        game.check()
        game.draw(win)
        # print(game.snake)
        win.update()
        clock.tick(FPS)
Beispiel #5
0
def initscr():
    win = pygcurse.PygcurseWindow(AREA_WIDTH, AREA_HEIGHT, fullscreen=False)
    pygame.display.set_caption('Apocalypse')
    win.autowindowupdate = False
    win.autoupdate = False
    win.fill(bgcolor=BACKG)
    return win
def filt(data):
    global situations
    tmpSit = []
    for sit in situations:
        ok = False
        for pat in data:
            patOk = True
            for j in range(7):
                if (pat[j] != -1 and pat[j] != sit[j]):
                    patOk = False
            ok = ok or patOk
        if (ok):
            tmpSit.append(sit)
    situations = tmpSit

    if (len(situations) == 0):
        win = pygcurse.PygcurseWindow(34, 3, None, None)
        win.font = pygame.font.Font(None, 50)
        win.putchars("I think you messed up somewhere.", 1, 1, "red")
        time.sleep(5)
        pygame.quit()
        sys.exit()
    elif (len(situations) == 1):
        cor = []
        for i in range(7):
            if (situations[0][i] == 1):
                cor.append(names[i])
        win = pygcurse.PygcurseWindow(
            len(" It's {}, {}, and {}! ".format(cor[0], cor[1], cor[2])), 4,
            None, None)
        win.font = pygame.font.Font(None, 50)
        win.putchars("I've got it!", 1, 1, "green")
        win.putchars("It's ", 1, 2, "green")
        win.putchars(str(cor[0]) + ", ", 6, 2, colors[names.index(cor[0])])
        win.putchars(
            str(cor[1]) + ", and ",
            len("It's {}, ".format(cor[0])) + 1, 2,
            colors[names.index(cor[1])])
        win.putchars(
            str(cor[2]) + "!",
            len("It's {}, {}, and ".format(cor[0], cor[1])) + 1, 2,
            colors[names.index(cor[2])])
        time.sleep(5)
        pygame.quit()
        sys.exit()
Beispiel #7
0
    def __init__(self, model, width, height):
        """ Initialize view for Marioscii """
        pygame.init()
        self.screen = pygcurse.PygcurseWindow(SCREEN_WIDTH,
                                              SCREEN_HEIGHT,
                                              fullscreen=False)
        pygame.display.set_caption('Pygcurse Marioscii')
        self.screen.autoupdate = False

        # this is used for figuring out where to draw stuff
        self.model = model
Beispiel #8
0
def test(colors):
    import pygcurse, pygame, time
    pygame.init()
    win = pygcurse.PygcurseWindow(3,
                                  len(colors),
                                  font=pygame.font.Font(None, 30))
    for i in range(len(colors)):
        color = colors[i]
        win.putchar("`", 0, i, None, findClosestW(color)[0])
        win.putchar(".", 1, i, None, color)
        win.putchar("'", 2, i, None, findClosest(color)[0])
        if findClosest(color)[0] != findClosestW(color)[0]:
            time.sleep(2)
    pygame.quit()
Beispiel #9
0
def main():
    log_fmt = "%(asctime)s %(name)s[%(lineno)d] %(levelname)s %(message)s"
    coloredlogs.install(level=logging.DEBUG, fmt=log_fmt)
    win = pygcurse.PygcurseWindow(WINWIDTH, WINHEIGHT + 4, fullscreen=False)
    pygame.display.set_caption('Window Title')
    win.autoupdate = False
    clock = pygame.time.Clock()

    game = Game(WINWIDTH, WINHEIGHT)

    while True:
        win.fill(bgcolor='blue')
        handle_events(game)
        game.draw(win)
        win.update()
        clock.tick(FPS)
Beispiel #10
0
def main():
    global FPSCLOCK, WINDOWSURF, BOARDBOX
    pygame.init()
    FPSCLOCK = pygame.time.Clock()
    WINDOWSURF = pygcurse.PygcurseWindow(WINDOWWIDTH,
                                         WINDOWHEIGHT,
                                         'Textris',
                                         font=pygame.font.Font(None, 24))
    WINDOWSURF.autoupdate = False
    BOARDBOX = pygcurse.PygcurseTextbox(
        WINDOWSURF,
        (LEFTMARGIN - 1, TOPMARGIN - 1, BOARDWIDTH + 2, BOARDHEIGHT + 2))

    showTextScreen('Textris')
    while True:  # main game loop
        runGame()
        showTextScreen('Game Over')
Beispiel #11
0
def main():
    global FPSCLOCK, WINDOWSURF, BOARDBOX
    pygame.init()
    FPSCLOCK = pygame.time.Clock()
    WINDOWSURF = pygcurse.PygcurseWindow(WINDOWWIDTH, WINDOWHEIGHT, 'Textris', font=pygame.font.Font(None, 24))
    WINDOWSURF.autoupdate = False
    BOARDBOX = pygcurse.PygcurseTextbox(WINDOWSURF, (LEFTMARGIN-1, TOPMARGIN-1, BOARDWIDTH+2, BOARDHEIGHT+2))

    showTextScreen('Textris')
    while True: # main game loop
        if random.randint(0, 1) == 0:
            pygame.mixer.music.load('tetrisb.mid')
        else:
            pygame.mixer.music.load('tetrisc.mid')
        pygame.mixer.music.play(-1, 0.0)
        runGame()
        pygame.mixer.music.stop()
        showTextScreen('Game Over')
Beispiel #12
0
    def __init__(self):
        """
        Constructor that creates a new instance of the application
        """
        self.DEBUG_COUNT = 0
        #Initialize pygcurse
        self.win = pygcurse.PygcurseWindow(SCREEN_WIDTH,
                                           SCREEN_HEIGHT,
                                           fullscreen=False)
        pygame.display.set_caption('Crunchbang Project')

        # we will call win.update() manually after everything is drawn
        self.win.autoupdate = False

        #Prepare to receive messages and effects from the game utilities
        #(this allows the utilities to send game messages and effects to this application)
        self._messages = []
        self._effects = []
        Utilities.application = self
Beispiel #13
0
def terminal_loop():
    win = pygcurse.PygcurseWindow(WINDOW_WIDTH, WINDOW_HEIGHT)
    win.autoblit = False
    inp = 0
    wallet = read_wallet()
    x, y = WINDOW_WIDTH, WINDOW_HEIGHT
    conf_scr()
    # stdscr.bkgd(' ', curses.color_pair(2))
    # stdscr.clear()
    #stdscr.nodelay(1)
    # while inp != 48 and inp != 27 and inp != 81 and inp != 113:
    while True:
        for event in pygame.event.get():  # the event loop
            if event.type == QUIT or event.type == KEYDOWN and event.key in (
                    K_ESCAPE, K_q):
                pygame.quit()
                sys.exit()

            try:
                write_scr(win, wallet, y, x)
                win.blittowindow()
            except RuntimeError:
                pass

            if event.type == KEYDOWN:
                isWalletChanged = False
                if event.key == K_a:
                    #           if y > 2:
                    data = win.input(
                        'Enter in format Symbol,Amount e.g. BTC,10')
                    wallet = add_coin(data, wallet)
                    isWalletChanged = True
                elif event.key == K_r:
                    #	if y > 2:
                    data = win.input(
                        'Enter the symbol of coin to be removed, e.g. BTC')
                    wallet = remove_coin(data, wallet)
                    isWalletChanged = True

                if isWalletChanged:
                    write_wallet(wallet)
Beispiel #14
0
def init_ui():    
    #Making sure we can access the variables
    global gamewindow
    global imgfile
    global image
    global box
    global sidebox
    global print
    global input
    global sound

    #Defining the UI
    gamewindow = pygcurse.PygcurseWindow(120, 40)
    gamewindow.font = pygame.font.Font('terminus.ttf', 14)
    print = gamewindow.pygprint
    input = gamewindow.input
    imgfile = 'bridge.png'
    image = pygame.image.load(imgfile)
    pygame.display.set_caption('Universe Mission')    
    box = pygcurse.PygcurseTextbox(gamewindow, (1, 27, 118, 12), fgcolor='black', bgcolor=(148,148,148), border='basic', wrap=True, marginleft=1, marginright=1, margintop=1, caption='Universe Mission')
    sidebox = pygcurse.PygcurseTextbox(gamewindow, (100, 1, 19, 25), fgcolor='white', bgcolor=(65,65,65), border='basic', wrap=True, marginleft=1, marginright=1, margintop=1, caption='Inventory')
    box.text = 'This is the Universe Mission test text box.'
    sidebox.text = 'Tools         Mops         Other things'
    sound.play(-1)
Beispiel #15
0
           [
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
           ],
           [
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
           ],
           [
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
           ]]

# - Pygcurse board

win = pygcurse.PygcurseWindow(32, 16, fullscreen=False)


def main():
    os.system('cls' if os.name == 'nt' else 'clear')
    i = 0
    j = 0
    while True:

        oScreen = copy.deepcopy(iScreen)
        win.fill('@', fgcolor='black', bgcolor='black')

        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN
                                      and event.key == K_ESCAPE):
                pygame.quit()
Beispiel #16
0
import pygcurse, pygame, sys
from pygame.locals import *
win = pygcurse.PygcurseWindow(20, 10)
win.colors = ('red', 'gray')
win.autoupdate = False
cellx = 0
celly = 0
while True:
    for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYDOWN
                                  and event.key == K_ESCAPE):
            pygame.quit()
            sys.exit()
        if event.type == MOUSEMOTION:
            n_cellx, n_celly = win.getcoordinatesatpixel(event.pos)
            if (n_cellx, n_celly) != (cellx, celly):
                win.setscreencolors(None, 'gray', clear=True)
                win.putchar('@', x=n_cellx, y=n_celly)
                win.update()
                (cellx, celly) = (n_cellx, n_celly)
Beispiel #17
0
GAME_Y = 0
LEFT_CONSOLE_WIDTH = 10
LEFT_CONSOLE_HEIGHT = 50
LEFT_CONSOLE_X = 0
LEFT_CONSOLE_Y = 0
BOTTOM_CONSOLE_WIDTH = 49
BOTTOM_CONSOLE_HEIGHT = 10
BOTTOM_CONSOLE_X = 11  # offset by 1 to avoid border overlap
BOTTOM_CONSOLE_Y = 40

BORDER_CORNER_CHAR = "O"
BORDER_COLOR = 'green'

TRAIL_COLOR = pygame.Color(255, 140, 0)

win = pygcurse.PygcurseWindow(SCREEN_WIDTH, SCREEN_HEIGHT, 'Hulk')
font = pygame.font.Font("xirod.ttf", 10)
win.font = font
win.autoupdate = False


class GameObject:
    def __init__(self):
        self.paused = False
        self.playing = True
        self.on_ship = False
        self.console_list = []
        self.entity_list = []
        self.ability_list = []
        self.graphical_entity_list = []
        self.enemy_list = []
Beispiel #18
0
"""
The following five lines were added to this previously text-based stdio
program. You can play the original program by commenting out the following
five lines. This demostrates how stdio programs can be converted to Pygcurse
programs with minimal effort.

Simplified BSD License, Copyright 2011 Al Sweigart
"""
import pygcurse

win = pygcurse.PygcurseWindow(50, 25, 'Reversi')
print = win.pygprint
input = win.input
# To get this to work in Python 2, comment the previous two lines and
# uncomment the following lines: (And also modify the print() calls in the code
# to get rid of the "end" keyword argument.
#import sys
#sys.stdout = win
#input = win.raw_input
win.setscreencolors('aqua', 'black', clear=True)
#===========================================================================

# Mini Reversi (with a smaller displayed board)

import random
import sys


def drawBoard(board):
    # This function prints out the board that it was passed. Returns None.
    HLINE = ' +--------+'
Beispiel #19
0
        elif event.type == KEYDOWN and event.key == K_DOWN:
            direction_y += 1
        #elif event.type == KEYDOWN and event.key == K_p:
        #print(self.dungeon.get_field_of_vision(self.dungeon.player.x, self.dungeon.player.y, 5))
        old_x, old_y = self.dungeon.player.x, self.dungeon.player.y
        self.dungeon.player.x += direction_x
        self.dungeon.player.y += direction_y
        if self.dungeon.collide(*self.dungeon.player.pos):
            self.dungeon.player.x, self.dungeon.player.y = old_x, old_y
        else:
            self.dungeon.reveal(self.dungeon.player.x, self.dungeon.player.y,
                                5)


if __name__ == '__main__':
    win = pygcurse.PygcurseWindow(40, 20)
    level1 = Dungeon.load_from_file('map/map.txt')
    level1.add_player(Player(1, 1))
    view = DungeonView(level1, win)
    controller = Controller(level1, view)
    win.autoupdate = False
    mainClock = pygame.time.Clock()
    running = True

    while running:
        for event in pygame.event.get():
            controller.process_event(event)

        win.setscreencolors()
        win.cursor = (0, 0)
        view.draw()
Beispiel #20
0
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)

WINWIDTH = 40
WINHEIGHT = 50
TEXTCOLOR = WHITE
BACKGROUNDCOLOR = (0, 0, 0)
FPS = 40
BADDIEMINSIZE = 1
BADDIEMAXSIZE = 5
BADDIEMINSPEED = 4
BADDIEMAXSPEED = 1
ADDNEWBADDIERATE = 3

win = pygcurse.PygcurseWindow(WINWIDTH, WINHEIGHT, fullscreen=False)
pygame.display.set_caption('Pygcurse Dodger')
win.autoupdate = False


def main():
    showStartScreen()
    pygame.mouse.set_visible(False)
    mainClock = pygame.time.Clock()
    gameOver = False

    newGame = True
    while True:
        if gameOver and time.time() - 4 > gameOverTime:
            newGame = True
        if newGame:
 def _test_cell_size():
     test = pygcurse.PygcurseWindow(1, 1)
     width = test.cellwidth
     height = test.cellheight
     pygame.quit()
     return width, height
            retPart[in3] = (i == 2)
            ret.append(retPart)
    elif (inN == 2):
        ret = []
        for i in range(3):
            retPart = [-1, -1, -1, -1, -1, -1, -1]
            retPart[in1] = not (i == 0)
            retPart[in2] = not (i == 1)
            retPart[in3] = not (i == 2)
            ret.append(retPart)

    filt(ret)


while True:
    win = pygcurse.PygcurseWindow(9, 11, "Three Of A Crime")
    win.font = pygame.font.Font(None, 100)
    ##win.fill("o")

    for i in range(-1, 7):
        win.putchars(names[i], 1, i + 1, colors[i])
        win.putchars("o", 5, i + 1, colors[i])

    numColors = [(255, 150, 0), (0, 255, 255), (0, 255, 0), "black"]

    for i in range(-1, 3):
        win.putchar(str(i), 1 + i, 9, numColors[i])

    win.putchars("Go!", 5, 9, "black", (0, 255, 0))

    def inRange(spot, area):
Beispiel #23
0
"""
The following five lines were added to this previously text-based stdio
program. You can play the original program by commenting out the following
five lines. This demostrates how stdio programs can be converted to Pygcurse
programs with minimal effort.

Note that this only works for Python 3, since print in Python 2
is a statement rather than a function.

Simplified BSD License, Copyright 2011 Al Sweigart
"""
import pygcurse
win = pygcurse.PygcurseWindow(40, 25, 'Tic Tac Toe')
print = win.pygprint
input = win.input
# To get this to work in Python 2, comment the previous two lines and
# uncomment the following lines:
#import sys
#sys.stdout = win
#input = win.raw_input
win.setscreencolors('lime', 'blue', clear=True)
#===========================================================================

# Tic Tac Toe

import random

def drawBoard(board):
    # This function prints out the board that it was passed.

    # "board" is a list of 10 strings representing the board (ignore index 0)
Beispiel #24
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()
Beispiel #25
0
           [
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
           ],
           [
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
           ],
           [
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
           ]]

# - Pygcurse board

win = pygcurse.PygcurseWindow(32, 16, fullscreen=isfullscreen)


def main():
    # os.system('cls' if os.name == 'nt' else 'clear')
    mainClock = pygame.time.Clock()
    newGame = True
    while True:

        oScreen = copy.deepcopy(iScreen)
        win.fill('@', fgcolor='black', bgcolor='black')

        if newGame:
            pygame.mouse.set_pos(win.centerx * win.cellwidth,
                                 (win.bottom) * win.cellheight)
            mousex, mousey = pygame.mouse.get_pos()
 def create_gui(self, fullscreen=False):
     self._window = pygcurse.PygcurseWindow(self._size_x, self._size_y, "GraphAlgo", fullscreen=fullscreen)
Beispiel #27
0
from time import sleep
import pygame
import pygcurse

win = pygcurse.PygcurseWindow(80, 40)
print(pygame.font.get_fonts())
win.font = pygame.font.SysFont('consolas', 12)

win.write('What is your name?')
name = win.input("so... who are you eh? > ")

win.write('Hello, ')
win.fgcolor = 'red'
win.write(name + '!\n')
win.colors = ('red', 'green')

# printing with pygprint -additional end, as in regular print function
# for char in 'It is good to meet you!':
#     sleep(0.1)
#     win.pygprint('What is your name?', end='')
#     win.pygprint('')

#printing with win.write
# for char in 'It is good to meet you!':
#     sleep(0.1)
#     win.write(char)

for char in f'It is good to meet you, {name}!':
    sleep(0.05)
    win.write(char)
win.write("\n")
Beispiel #28
0
import pygame
import sys
import random
import copy
import io
import level
import book
import item
import endgame
import characters as ch
import pregame
from level import Level

# Main Window size and name

win = pygcurse.PygcurseWindow(70, 35)
win.font = pygame.font.SysFont('dejavuserif', 16, bold=False, italic=False)
pygame.display.set_caption('GradHack')
win.autowindowupdate = False
win.autoupdate = False

# Some auxilary functions and globals


def attack(hero, opponent, messageList):
    if opponent.name == 'Virus':
        if random.random() < (0.5 - 0.05 * (hero.lvl)):
            hero.time -= 3
            io.new_message("Virus evades you. Lose 3 time.", messageList)
        else:
            opponent.health -= hero.strength
# Simplified BSD License, Copyright 2011 Al Sweigart

import pygcurse, pygame, sys, random, time
from pygame.locals import *

BLUE = (0, 0, 128)
YELLOW = (255, 255, 0)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
RED = (255, 0, 0)

MAZE_WIDTH = 11
MAZE_HEIGHT = 11
FPS = 40

win = pygcurse.PygcurseWindow(MAZE_WIDTH, MAZE_HEIGHT, fullscreen=False)
pygame.display.set_caption('Pygcurse Maze')
win.autowindowupdate = False
win.autoupdate = False


class JoeWingMaze():
    # Maze generator in Python
    # Joe Wingbermuehle
    # 2010-10-06
    # http://joewing.net/programs/games/python/maze.py

    def __init__(self, width=21, height=21):
        if width % 2 == 0:
            width += 1
        if height % 2 == 0:
Beispiel #30
0
Snake Game
"""

import pygame
from pygame.locals import *
import pygcurse
import random
import string

res_x = 60
res_y = 40

center_x = res_x / 2
center_y = res_y / 2

win = pygcurse.PygcurseWindow(res_x, res_y)
win.font = pygame.font.Font(None, 28)

movements = {
    'n': lambda coord: (x_pos(coord), y_pos(coord) - 1),
    'e': lambda coord: (x_pos(coord) + 1, y_pos(coord)),
    'w': lambda coord: (x_pos(coord) - 1, y_pos(coord)),
    's': lambda coord: (x_pos(coord), y_pos(coord) + 1)
}
fruit_chars = list(string.printable)
colors = list(pygcurse.colornames.keys())

class Snake:
    """Documentation for Snake

    """