Compare commits

...

2 Commits

Author SHA1 Message Date
Joe S 298e5abdbe idk 2021-02-05 11:45:49 -05:00
Joe S 37524876e5 Clean up adventure-game 2021-02-03 17:27:22 -05:00
5 changed files with 38 additions and 57 deletions

0
4/4.10/4.10.1/main.py Normal file
View File

7
Adventure Game/Makefile Normal file
View File

@ -0,0 +1,7 @@
init:
pip install -r requirements.txt
test:
py.test tests
.PHONY: init test

View File

@ -1,21 +1,35 @@
import npyscreen
# std imports
from math import floor
# This application class serves as a wrapper for the initialization of curses
# and also manages the actual forms of the application
# local
from blessed import Terminal
class MyTestApp(npyscreen.NPSAppManaged):
def onStart(self):
self.registerForm("MAIN", MainForm())
# This form class defines the display that will be presented to the user.
def roundxy(x, y):
return int(floor(x)), int(floor(y))
class MainForm(npyscreen.Form):
def create(self):
self.add(npyscreen.TitleText, name = "Text:", value= "Hellow World!" )
def afterEditing(self):
self.parentApp.setNextForm(None)
term = Terminal()
if __name__ == '__main__':
TA = MyTestApp()
TA.run()
x, y, xs, ys = 2, 2, 0.4, 0.3
with term.cbreak(), term.hidden_cursor():
# clear the screen
print(term.home + term.black_on_olivedrab4 + term.clear)
# loop every 20ms
while term.inkey(timeout=0.02) != 'q':
# erase,
txt_erase = term.move_xy(*roundxy(x, y)) + ' '
# bounce,
if x >= (term.width - 1) or x <= 0:
xs *= -1
if y >= term.height or y <= 0:
ys *= -1
# move,
x, y = x + xs, y + ys
# draw !
txt_ball = term.move_xy(*roundxy(x, y)) + ''
print(txt_erase + txt_ball, end='', flush=True)

View File

@ -1,40 +0,0 @@
import curses
# The `screen` is a window that acts as the master window
# that takes up the whole screen. Other windows created
# later will get painted on to the `screen` window.
screen = curses.initscr()
# lines, columns, start line, start column
my_window = curses.newwin(15, 20, 0, 0)
# Long strings will wrap to the next line automatically
# to stay within the window
my_window.addstr(4, 4, "Hello from 4,4")
my_window.addstr(5, 15, "Hello from 5,15 with a long string")
# Print the window to the screen
my_window.refresh()
curses.napms(2000)
# Clear the screen, clearing my_window contents that were printed to screen
# my_window will retain its contents until my_window.clear() is called.
screen.clear()
screen.refresh()
# Move the window and put it back on screen
# If we didn't clear the screen before doing this,
# the original window contents would remain on the screen
# and we would see the window text twice.
my_window.mvwin(10, 10)
my_window.refresh()
curses.napms(1000)
# Clear the window and redraw over the current window space
# This does not require clearing the whole screen, because the window
# has not moved position.
my_window.clear()
my_window.refresh()
curses.napms(1000)
curses.endwin()

View File

@ -1,2 +1,2 @@
npyscreen==4.10.5
windows-curses==2.2.0 # Only for those using windows, curses is standard on python for BSD and GNU/Linux
# Blessed handles our terminal "graphics"
blessed==1.17.12