static 'banner' for zork like game

Started by
5 comments, last by Bacterius 10 years, 2 months ago

hello,

i'm currently making a text based game like zork using python 3 with pycharm IDE.

I am wondering how I can make a static banner at the top of the console that always remains while the user enters commands etc at the bottom.

if you don't know what I mean, here is the zork game:

I want to make what they have at the very top, with location, score and moves. Also, how can I highlight the text in grey like that?

thanks in advance,

Jonathan

Advertisement

You should be able to do all that with Curses for Python.

thanks LennyLen

i've downloaded and installed that module and i'm reading the documentation regarding it now.

However i've come up against an unusual error already, the tutorial states that


curses.initscr() must be called first. 

So I do this with


stdscr = curses.initscr()

but my pyCharm compile output gives this error "Redirection is not supported."

i've googled this problem but there seems to be only 1 result, for which that person also didn't get an answer... I don't suppose you know at all?

hmm after checking google further it seems curses in general doesn't support windows and errors can occur often and that I should download a windows designed curses module instead.

i'll guess i'll look into that!

EDIT: although it seems they are all outdated and not workable for python 3.

Looks like curses is a luxury for Linux users and the like. Is there no other way such a thing as at the top of the Zork game can be done without it?

Looks like curses is a luxury for Linux users and the like. Is there no other way such a thing as at the top of the Zork game can be done without it?

You can do manually all the stuff curses would do for you - but it's not for the faint of heart.

You can get most of the way there by learning the escape codes for your terminal (for Windows, you'll need something like ansicon).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

thanks swiftcoder

actually so far I don't need a module for the simple thing I wanted to do, which was create something "static" at the top of the console.

i've so far achieved it by simply clearing the screen in python, writing the "banner" then printing several blank new lines before any input or output :) example:

os.system('cls')

print("Whatever banner you want")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
input("enter a command: ")

of course this is a very crude way of doing it and who knows how many blank lines need to be used for all users (probably impossible to know) - as an ultra beginner I know of no other way though

but at least you get a simple static line above any commands or output. I thought my request was too simplistic to warrant any modules!

There's also PDCurses as an ncurses implementation for Windows. It sucks that it doesn't have the same name (which means your build process needs to deal with it) but the code is the same. system("cls") is somewhat system-dependent, and not very efficient. It's probably not a problem yet but when it becomes one, do consider using ncurses!

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

This topic is closed to new replies.

Advertisement