I'm trying to make a tiny arcade game in curses and this has been bugging me out for the past 40 minutes. How do you print something in the middle of the screen and also what is wrong with my syntax on the first screen.addstr (Game Over)
I am running linux and using xterm.
import curses
import time
import random
color_pref = int(input('Choose color mode (0-WHITE, 1-GREEN, 2-RED, 3-BLUE): '))
screen = curses.initscr()
curses.start_color()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.noecho()
screen.keypad(1)
curses.curs_set(0)
dims = screen.getmaxyx()
screen.refresh()
def game():
x, y = 3, 2
points = 5
q, Vertical, Horizontal = -1, 1, 1
gameover = False
screen.border(0)
if q == ord('q'):
gameover = True
if gameover == True:
screen.clear()
screen.border()
screen.refresh()
screen.nodelay(0)
score = '1'
message2 = 'Press Space to Play Again.'
message3 = 'Press q to Quit.'
message4 = 'You killed ' + score+ 'enemies'
screen.addstr(int(int(dims[0])/2-1), int(int(dims[1])) - int(len(message))), 'Game Over!', curses.color_pair(color_pref)|curses.A_BOLD)
screen.addstr(int(int(dims[0])/2-1), int(int(dims[1])) - int(len(message4))), message4)
screen.addstr(int(int(dims[0])/2+3), int(int(dims[1])) - int(len(message2))), message2)
screen.addstr(int(int(dims[0])/2+4), int(int(dims[1])) - int(len(message3))), message3)
screen.getch()
game()
curses.endwin()