My first program. Design/style advice requested.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

My first program. Design/style advice requested.

peter h meadows

Hi. I wondered if anyone could take a look at my code and answer some
questions. I'm trying to write a program that lets people play Arimaa
(Arimaa is a board game that can be played with a standard chess set. You
can find the rules at arimaa.com but you won't need to know how to play to
understand my code)

My code is on squeaksource: http://www.squeaksource.com/Arimaa.html

I run it by: ArimaaGameZone new openInWindow .

Click on the last two rows to position white pieces, then press the send
button. Then click on the first two rows to position the black pieces. The
move logic is not yet implemented, but I'm sure you get the idea of what I
want to do.

I've tried to use a MVC design where ArimaaBoardMorph is the View,
ArimaaBoard is the Model and ArimaaEventHandler is the controller.

So I have a different class to handle gold setup, silver setup, gold move
and silver move (in arimaa we have gold/silver instead of black/white).
All inherited from the ArimaaEventHandler. The board morph sends a message
to the controller and depending on which controller is set you get
different behaviour.

Is this the best way to do what I want? I think it's probably wrong that
when I switch between controllers I have to copy the variables that
contain the model and the view. How should it be done with good smalltalk
style? Is there a simpler way? Is it right to use inheritance as I have
done?

Any comments on other aspects are most welcome, but my main question is;
have I done the MVC thing right? Don't be afraid to say it's all wrong,
this is my first project and I don't mind rewriting the whole thing from
scratch.

I realise helping me with this may take some of your time, and I am very
grateful for any response. I hope I will stick with squeak and one day do
something useful for the community.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: My first program. Design/style advice requested.

Marcin Tustin
Well, the obvious thing to do is not to have separate classes for each side. Instead have one class, and have one instance per side. Probably have each controller decide what to do, or perhaps even better, have a single controller that delegates to the appropriate instance depending on whose turn it is (and orchestrates the transition from setup to play). That way you won't be duplicating functionality, or spreading around logic about the flow of the stages of the game.

On Mon, May 26, 2008 at 6:21 PM, peter h meadows <[hidden email]> wrote:

Hi. I wondered if anyone could take a look at my code and answer some questions. I'm trying to write a program that lets people play Arimaa (Arimaa is a board game that can be played with a standard chess set. You can find the rules at arimaa.com but you won't need to know how to play to understand my code)

My code is on squeaksource: http://www.squeaksource.com/Arimaa.html

I run it by: ArimaaGameZone new openInWindow .

Click on the last two rows to position white pieces, then press the send button. Then click on the first two rows to position the black pieces. The move logic is not yet implemented, but I'm sure you get the idea of what I want to do.

I've tried to use a MVC design where ArimaaBoardMorph is the View, ArimaaBoard is the Model and ArimaaEventHandler is the controller.

So I have a different class to handle gold setup, silver setup, gold move and silver move (in arimaa we have gold/silver instead of black/white). All inherited from the ArimaaEventHandler. The board morph sends a message to the controller and depending on which controller is set you get different behaviour.

Is this the best way to do what I want? I think it's probably wrong that when I switch between controllers I have to copy the variables that contain the model and the view. How should it be done with good smalltalk style? Is there a simpler way? Is it right to use inheritance as I have done?

Any comments on other aspects are most welcome, but my main question is; have I done the MVC thing right? Don't be afraid to say it's all wrong, this is my first project and I don't mind rewriting the whole thing from scratch.

I realise helping me with this may take some of your time, and I am very grateful for any response. I hope I will stick with squeak and one day do something useful for the community.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners