[Tutor] Battleship grid not working how I expect

Alex Hall mehgcap at gmail.com
Thu May 27 23:35:56 CEST 2010


Hi all,
I very much hoped not to have to do this, but I have been staring at
my code for two days and I just cannot see what is going on.
http://www.gateway2somewhere.com/bs.zip
has my code in it. You need wxPython to run it. speech.py has some
pywin stuff, but that is only to interface with screen readers and is
not important to most, probably all, of you. In board.py, you will
want to find the speak method in the grid class and comment out the
line "speech.speak(txt)", as well as commenting out "import speech" at
the top of the file.

The problem: I have a battleship grid, where each square is a
wx.Button and the row letters and column numbers are wx.StaticTexts.
Internally, I refer to coordinates as (x,y), so which column you are
in followed by which row. Battleship uses (row,col) for coordinates,
which is why anything to do with printing or reading coordinates may
seem backwards. I want a grid with 10 rows and 14 columns or, in
Battleship terms, columns 1-14 and rows a-j. Somewhere, or maybe
several somewheres, something is getting switched around and I end up
with columns 1-10 and rows a-n, but my movement function still allows
me to move in a 10cx14r grid, not the other way around. I have added a
lot of comments, but if something does not make sense, please ask me
to clarify. Also, I only indent one space, and I use #closeing tags.
This is because I use a screen reader, and it makes life a great deal
easier (especially in Python) to do it this way. Thanks in advance for
any light you can shed on this very frustrating problem!

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


More information about the Tutor mailing list