Minesweeper clone, getting my feet wet with PureBasic

Advanced game related topics
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

Everyone its own style id say. Theres plenty of good structured code on the boards if you need a "style-guide". However i think all this just was commented because you didnt use code tags to post the code so it completelly got ripped apart.

Otherwise nice game :)

Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
SMartin
User
User
Posts: 19
Joined: Thu Aug 16, 2007 6:08 am
Location: Las Vegas

Ohh...

Post by SMartin »

Oh, It was the posted code....
Now that makes more sense, without the code tags it's a bit of a mess.

I didn't post that message but I could see how someone might think I did.

Maybe I'm not completely insane...but then again...maybe just a little. :D

Steve.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

@ SM: I wasn't trying to RIP... or Flame... The code was different, but it worked. I was hard to read for me. Very nonlinear. I apologize if you felt I was flaming you... I was only teasing (should have used more smileys!!!) :D

Really... it worked well. I think it works better than the original since I have had a few issues with the original giving FALSE info by undercounting mines around the square... yours has not done that yet which shows it to be an improvement!!! :D :D :D

8)

Hope you accept the well intended apology.
RZ
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
SMartin
User
User
Posts: 19
Joined: Thu Aug 16, 2007 6:08 am
Location: Las Vegas

Thanks.

Post by SMartin »

RZ, Thanks, I appreciate it.

It's probably me that needs to lighten up a bit :) and you have my apologies for that.

It's always a little weird moving to a new platform because you don't always know what the conventions and standards are, and peer review is very helpful, in my humble opinion. So I do appreciate it.

So...I've got to ask...
By non-linear do you mean that you think the code is easier to follow if the procedures are organized by what they do, or organized by how they're likely to be called?

Steve
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Steve... :D Your style works... thats what is important keep doing what you do as it works for you!

Linear styles are great for readability, but suffer in that a great deal of organization (IMO) is necessary to manae your code and flow.

To pundit:

All programs are organized so that the initial declares all variables, types, lists etc.
the main body of the program loop is organized
and the functions are placed at the end.

but it does not have to work that way.

Indeed, when I switched to PB from BB3d I had issues with the structures created by the window designer and had to learn how to work within the framework.

Witht the new way the window designer works I am relearning a bit. I have switched a POS project from the old method, to the new incredible functions list method (a function for every button... On a POS there are a lot of buttons... ) :D

I am not saying this well enough because I am typing it in an airport waiting to go to Newfoundland to install a new set of Xerox Printers for GMC. Too many people being nosy here !!!


OK organization:

When I studied for myMEd in Educational Psychology (and get my Teaching certificate) I learned [ie:forced down my throat] the Madeline Hunter Lesson Cycle as a methodology for classroom instruction and as a way to organize a lesson plan.

Anythin I would say on organization would probably apply just to me.

I keep it simple...

will edit in a moment... have to do the check in
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

SMartin: About your coding style...

I prefer to think of programming as an artform, like creative writing or similar. It's not (unless tought as such) a science - in the old days you could get a BA or a BSC in Computing - you decided at the end! (now its just BSC :( ). Maybe it really should depend if it was natural ability or not and if the output is "creative"?

Anyhow, my point is, it doesn't matter how you get to the end result, or what particular style you used to get there. It really also doesn't matter if people don't appear to appreciate your work or are critical of your style. What matters is that you enjoyed the experience and that it was creative (for you) in some form or another.

If you like the way you program, stick to that method. It obviously works. :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
SMartin
User
User
Posts: 19
Joined: Thu Aug 16, 2007 6:08 am
Location: Las Vegas

Thanks

Post by SMartin »

Thanks for the replies. It's interesting reading.

I program strictly for the pleasure of it, so the doing, and the methodology is often more interesting to me than the product.

The truth is, I don't even play minesweeper that often, (I just wanted a way to cheat a little so I could win once in a while) :D

Re coding styles: I'm feelin' the need to refine mine. The project I'm working on now has already got four windows and the formatting style (like Termite Terminator) I'm using is starting to feel a little overloaded. I think I should have gone with separate files for each window and used 'Includes' and not relied so much on the code folding to keep my brain from exploding.

Also, this hand coding of the controls has got to go. Pure comes with a really good visual designer but I haven't quit figured out how to wrap in into my style yet.

I spent a good part of the summer before last writing (in .net) a Sudoku program that can create puzzles and solve to a fairly high level, so I've also been thinking a lot on the methodology of converting classes to a procedural based system.

I'd love to convert it to Purebasic. Those tiny, fast, executables that this system makes really puts a big smile on my face. :D

Steve
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

it doesn't matter how you get to the end result,
Doubledutch cut through the miasma of my excess verbage to say what is really important. :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Re: Minesweeper clone, getting my feet wet with PureBasic

Post by Tipperton »

SMartin wrote:I discovered that GetCurrentDirectory() doesn't mean that you get the application's start path, so I added some gak to check for the directory that contains the graphics.
If you need the path to the program to get the graphics files, try:

Code: Select all

GetPathPart(ProgramFilename())
SMartin
User
User
Posts: 19
Joined: Thu Aug 16, 2007 6:08 am
Location: Las Vegas

Thanks

Post by SMartin »

Tipperton,

Thanks for the tip. I hadn't come across that yet, and it's very useful.

Steve Martin
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

I tend to organize my code in groups, ie. related procedures are close to each other in the source. That often saves a little scrolling :-)

I also use this framework:

procedure init()
whateverprocedure()
procedure end()

procedure mainloop()

init()
mainloop()
end()

ie. i start my code with all procedure definitions, first one that contains all initialisations, then all used subsections, then one that frees up stuff (if need be), then the mainloop, then three calls to subsequently init(), mainloop(), and end().

But it is all a matter of choice and taste.

It's the same story on commenting and indenting. Everyone likes something different.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

I indent with a tab per group (so an if inside a procedure has 1 tab, simple indentation but without spaces, just real tabs). I comment using robodoc template because that allows me to output good docs out of my sources and it also keeps it all clean and nice :)

for big libraries I use 2 files, just like in C. one is a header containing declarations for that specific library and the other one is a source where the declarations are put to use with code content.

I also separate every module into a different dir which contains also their dependencies, etc.

Regarding code-style, I try to follow a GCC style I always used in C, but with the obvious differences on PB.

About file structure, that's a whole different subject, but this is how my things work through SVN (mind you, single user repositories are not the same as multi-user, IMO).

Code: Select all

root
 |-> project name
 |      |-> bin
 |      |     |-> program exe, dll, common files/dirs for the program, etc
 |      |
 |      |-> src
 |      |     |-> libs
 |      |     |     | -> libraries in different directories, etc.
 |      |     |-> main sources (the main file is called main.pb usually)
 |      |
 |      |-> tmp
 |      |     |-> any temporary data goes in here (test files such as txt,  binary, images, etc)
 |-> project name....
 |      |-> ...
Its actually a little more complicated than that, but just to give you an idea.

Yep, it's all about the whole process and not just the end product that is enjoyable.
Post Reply