console programming without scrolling
I am not really sure how to describe it, but here it goes... I started with python a couple of months ago. It is going pretty good. Several of my bash scripts have been converted over to python. I use python every other day at work. Sometimes, I want to challenge myself with new projects.
Back in high school, we had a computer club. The teacher wrote a fish-shark simulation (Wa-Tor). For some reason, I remembered it and I started to write it program. Here is my problem, the program gets my terminal window's rows and columns. My entire fish world is size of the terminal window. Every other move, I want the fish world to be re-drawn. My only problem is that 'print my_ocean' ends up just scrolling.
Example: Chronos 1: print Chronos 2: print
I just want to update the same screen over and over.
Is it possible to stay on your current screen and update it, instead of scrolling? The scrolling does not always look that pretty.
Does that make sense?
6 comments · 93% upvoted · other discussions
Prepend each line with four spaces or use backticks (`like this` →
like this) to show code on Reddit.This is hard to answer without knowing more details. How is the game world drawn to the terminal? If it's just using regular prints, you can reset the terminal's output with
os.system("clear")(assuming Linux or OS X, useos.system("cls")for windows). You obviously have to import the os module.You might want to consider using curses. It's archaic, but very commonly used for TUI's in Linuxland. See here for the docs.