Sorry if this is too broad a question. I am a relative beginner, so please go easy on me.
My son has a school assignment to design and implement a draughts (checkers) game in Python, and we are looking at wxPython as a tool to help us with this.
We are not looking for a ready-made solution, and certainly are not asking you to do our work for us. What we seek are a few pointers to help us get started.
The core of the game is an 8x8 grid of alternate background colours (say green and cream).
Each cell in the grid can contain an image; one of:
Black piece
White piece
Black King piece
White King piece
Nothing (all the cream cells always contain nothing; only the green cells can contain pieces)
So we need some kind of grid control where we can specify a background colour for each cell, and an image which it can contain.
We shall also need to specify an event handler to invoke when a cell is clicked.
Could someone give us some guidance as to whether such a control is available?
My son has a school assignment to design and implement a draughts (checkers) game in Python, and we are looking at wxPython as a tool to help us with this.
We are not looking for a ready-made solution, and certainly are not asking you to do our work for us. What we seek are a few pointers to help us get started.
...
So we need some kind of grid control where we can specify a background colour for each cell, and an image which it can contain.
We shall also need to specify an event handler to invoke when a cell is clicked.
Could someone give us some guidance as to whether such a control is available?
In general, grid controls are designed for text, not graphics. Many of
them can display an icon, but I'm not sure you'd be able to twist them
into doing what you need.
If it were me, I would create a panel with a grid sizer, and place an
array of 64 image controls in them. Now you can assign an image to each
control, and you can catch click events.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
My son has a school assignment to design and implement a draughts (checkers) game in Python, and we are looking at wxPython as a tool to help us with this.
We are not looking for a ready-made solution, and certainly are not asking you to do our work for us. What we seek are a few pointers to help us get started.
...
So we need some kind of grid control where we can specify a background colour for each cell, and an image which it can contain.
We shall also need to specify an event handler to invoke when a cell is clicked.
Could someone give us some guidance as to whether such a control is available?
In general, grid controls are designed for text, not graphics. Many of
them can display an icon, but I'm not sure you'd be able to twist them
into doing what you need.
If it were me, I would create a panel with a grid sizer, and place an
array of 64 image controls in them. Now you can assign an image to each
control, and you can catch click events.
These will work, and given that this is a beginners assignment, maybe the
best way to go.
But if it were me, I'd draw the board myself -- that way you can really
control how it will all look, etc.
Here's an example for pretty similar case: a sudoko game:
lots of other cool demos in that repo too....
(note: it uses numpy, as I wrote it partly to demonstrate some cool
features of numpy arrays -- perhaps overkill of this case, but it wouldn't
be hard to remove the numpy stuff.)
Also -- suduko has numbers in the boxes, so I'm drawing them as text -- but
not at all had to draw a bitmap there instead (or a circle....)
-Chris
···
On Mon, Feb 3, 2014 at 3:43 PM, Steve Barnes <gadgetsteve@live.co.uk> wrote:
If it were me, I would create a panel with a grid sizer, and place an
array of 64 image controls in them. Now you can assign an image to each
control, and you can catch click events.
Or even an 8x8 grid sizer of bitmap buttons.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
My son has a school assignment to design and implement a draughts (checkers) game in Python, and we are looking at wxPython as a tool to help us with this.
We are not looking for a ready-made solution, and certainly are not asking you to do our work for us. What we seek are a few pointers to help us get started.
...
So we need some kind of grid control where we can specify a background colour for each cell, and an image which it can contain.
We shall also need to specify an event handler to invoke when a cell is clicked.
Could someone give us some guidance as to whether such a control is available?
In general, grid controls are designed for text, not graphics. Many of
them can display an icon, but I'm not sure you'd be able to twist them
into doing what you need.
If it were me, I would create a panel with a grid sizer, and place an
array of 64 image controls in them. Now you can assign an image to each
control, and you can catch click events.
Or even an 8x8 grid sizer of bitmap buttons.
Thanks to all for the helpful responses. Well give it a try with an 8x8 grid sizer of bitmap buttons as a start, and see how that goes.
If it were me, I would create a panel with a grid sizer, and
place an
array of 64 image controls in them. Now you can assign an image
to each
control, and you can catch click events.
Or even an 8x8 grid sizer of bitmap buttons.
These will work, and given that this is a beginners assignment, maybe
the best way to go.
But if it were me, I'd draw the board myself -- that way you can really
control how it will all look, etc.
Here's an example for pretty similar case: a sudoko game:
(note: it uses numpy, as I wrote it partly to demonstrate some cool
features of numpy arrays -- perhaps overkill of this case, but it
wouldn't be hard to remove the numpy stuff.)
Also -- suduko has numbers in the boxes, so I'm drawing them as text --
but not at all had to draw a bitmap there instead (or a circle....)
And just to confuse you with one more option... I would probably do a combination of the approaches mentioned so far. I would create a window class (derived from wx.Panel, or perhaps a wx.ScrolledWindow) and bind a handler for its EVT_PAINT event. I would also create 6 bitmap objects when the board class is initialized, one for each type of square. The paint event handler can then be as simple as creating a DC and iterating over all the positions drawing whatever kind of bitmap should be shown in that position. You can use a wx.BufferedPaintDC to eliminate flicker if you need to.
···
On Mon, Feb 3, 2014 at 3:43 PM, Steve Barnes <gadgetsteve@live.co.uk > <mailto:gadgetsteve@live.co.uk>> wrote: