Click here to Skip to main content
15,888,056 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am doing a little project that consists of a basic Peg-Solitaire game. I am using GUI(buttons). To determine the possibility of a move I use the get.Background() method. So how could I determine if there is no more moves left?
Posted
Updated 9-Jan-16 18:54pm
v2
Comments
PIEBALDconsult 10-Jan-16 0:54am    
Any way you like.
Patrice T 10-Jan-16 1:20am    
Check every possible move to see which one are left.

You know what moves are legal - because you have to forbid illegal moves when the user tries them. And you know which spaces on the board are occupied - otherwise you couldn't check the user moves!

So look at each occupied space on the board, and see if it has any legal moves. If necessary, "simulate" the user trying to move the piece and check every possible move he could make. If you find a move the user can make, the game isn't over...
 
Share this answer
 
You already took a wrong path. You get the status of the game from the UI. It can work, but it's easy to understand why this is not a robust way of software development. With more complicated problems, it can even push your project to the dead end, mess it up beyond repair. Consider just one thing: you change the colors of the UI, and your game logic will stop working. You have to change the color you compared the result of checking the background with, and it will work again, right? The whole idea is wrong.

First of all, you need to understand that the game itself has its own logic. You need to develop its logic separately, so it would not depend on UI at all. Call it data model, call it just model&heliip; And another, isolated part could be UI or View. And think what should be between them…

I suggest you learn and analyze applicability of the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900