Hi,
I have wrote a game with python curses. The problem is that I want to
confirm before quitting, while my implementation doesn't seem to work.
Anyone can help me?
[code]
#!/usr/bin/python
#
# Brick Ball in Python
# by Jerry Fleming [EMAIL PROTECTED]
#
# This is a small game adapted from that in Motorola Mobile C289, and my
first game in python :)
#
# This progrma is best run under linux. Since Windows port of Python has
poor curses support,
# play it under Windows is not recommended. If you have no linux box
available, try Cygwin,
# though it too has poor curses support.
#
# As I am a newbie to python, please tell me if you have a better
implementation or any suggestions.
#
# TODO:
# re-implemente it with wxPython, so one does not have to rely on the
ugly curses.
# session support.
# pausing, especially when confirming
# resize terminal at run time
#
# HISTORY
# 2006-04-19: first version
#
#
import curses
import _curses
import thread
from time import sleep
from string import split
from random import randint
# parameters: adjust them to fit you terminal
brick_width = 7
brick_gap_x = 1
brick_gap_y = 1
speed = 0.05 # sleep time to control moving speed of the ball
pause = 1 # time to pause
# terminal initialization
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.curs_set(0)
stdscr.keypad(1)
screen_height, screen_width = stdscr.getmaxyx()
screen_height = screen_height - 1
screen_width = screen_width - 1
brick_rows = screen_height / 4
if brick_rows 7: brick_rows = 7
brick_cols = (screen_width + brick_gap_x) / (brick_width + brick_gap_x)
brick_margin = (screen_width - brick_cols * (brick_width + brick_gap_x)
+ brick_gap_x)/2
pad_position = randint(0, screen_width - brick_width)
ball_position = [screen_height - 3, randint(0, screen_width - brick_width)]
ball_direction = [-1, 1] # abs(tan(a)) must be 1
char = ''
bricks = []
game_score = 0
ScreenSizeError = 'ScreenSizeError'
tStart = '''
___ _ ___ ___ _ _
__ _
( \ (_) | | / _ \( \ | | | (_)
(_ \_ | |
) ) _ | | _ ( (_) )) )_| | |_
_) ) _ _| |_| |__ ___
| __ ( / ___) |/ ___) |_/ ) ) _ (| __ (( | | | | | _ \
| / | | (_ _) _ \ / _ \| _ \
| |__) ) | | ( (___| _ ( ( (/ \ | |__) ) ___ | | | | | | | |
| || |_| | | |_| | | | |_| | | | |
|__/|_| |_|\)_| \_) \__/\_) |__/\_|\_)_) |_|_| |_|
|_| \__ | \__)_| |_|\___/|_| |_|
(/
by Jerry Fleming [EMAIL PROTECTED]
GAME STARTING ...
(this assumes that your terminal be larger that
130x40)
'''
tExit = '''
8
8
888 88 ad8ba 88 8bd8 d8
88
88 ,d d8 8b88 Y8,,8P ,8P'
88
88 88 a8P88 Y8, ,8P d8
88
88a 8b, ,d8 88 MM88MMM ,a8P 888aa8,8P'
8b,dPPYba, 88
88 `Y8, ,8P' 88 88 d888 `88'd8 88P'
`8a 88
88 )888(88 88 88 88 ,8P'88
88 88
88 ,d8 8b, 88 88,aa 88 88 d8 88
88 88
888 8P' `Y8 88 Y888 88 88 88 8P' 88
88 88
8
8
'''
tOver = '''
,adba,
88
d8'`8b
88
d8'
88
88,adPPYYba, 88,dPYba,,adPYba, ,adPPYba, ,adPPYba, 8b
d8 ,adPPYba, 8b,dPPYba, 88
88 8 `Y8 88P' 888a a8P_88a8 8a
`8b d8' a8P_88 88P' Y8 88
Y8,88 ,adP88 88 88 88 8PP8b d8
`8b d8' 8PP 88
Y8a..a88 88,,88 88 88 88 8b, ,aa8a, ,a8
`8b,d8' 8b, ,aa 88 aa
`Y8P `8bbdPY8 88 88 88 `Ybbd8' `YbbdP'
8 `Ybbd8' 88 88
'''
tGoon = '''
8
8
,adba, ad8ba 88 8b
d8 d8 88
d8'`8bd8 8b88 Y8,
,8P ,8P' 88
d8'a8P88 Y8,
,8P d888
88 ,adPPYba, ,adPPYba, 8b,dPPYba, ,a8P 88
8aa8,8P' 8b,dPPYba, 88
88 8 a8 8aa8 8a 88P' `8a d888
`88'd8 88P' `8a 88
Y8,88 8b d88b d8 88 88 88
88 ,8P'88 88 88
Y8a..a88