[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] question about Rect objects



Hi all,
I am new to this list. A quick intro:
I am a blind college student studying for a computer science degree. I
use Jaws for Windows from Freedom Scientific to read the content of my
computer screen. I have a bit of vision, enough to see high-contrast
colors in a big enough window (500x500 or larger is good).
I use Python2.6 with the latest release of Pygame. I am trying to add
a visual element to a Battleship game I wrote last year. Originally,
the game was all based on screen readers; the user could arrow around
and their screen reader (the program that reads text on the computer)
would announce which square they were on and the status of that
square, among other information. No visuals were needed since most
screen readers offer an API which I can interface with directly.
However, I want to expand this to a 2-player, online game so my
sighted friend and I can play against each other. Of course, for that,
I need to give him something to look at.

I am trying to generate a grid of rectangles, each rect a square on
the classic Battleship grid. All rects will start out gray, and will
then change color as the game progresses (red=hit, white=miss,
blue=enemy sighted). I have a Square class, which has variables like
firedOn or ship. That way I can examine the square on which the user
fired, change its firedOn from False to True, and say something like
"if(grid[i][j].ship!=None): #change color to red". You get the idea.

Anyway, the pygame documentation says rect cannot be subclassed. Is
there any way, then, for me to put a rect object in my Square class,
then draw the grid using my grid (a 2d array of Squares)? I guess what
I want is to say:
bg.replace_ip(red, grid[i][j].rect) #change fired-on grid square to
red and redraw it
after building my grid of rects? I am quite new to Pygame, and this is
my first time venturing into the world of generating shapes and grids;
up to now, my involvement in visual elements has been some
experimenting with wxPython and XRC, and that package does most of the
layout for you. Any help with this grid problem would be greatly
appreciated, and please tell me if my above question and explanation
do not make sense (as I doubt they will).

-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap