Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Input about this game...

Author
Message
Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 22nd Jun 2012 19:56
While learning to code in DBPro, I created a simple slot machine game (See below). I have moved on and was thinking this morning that I would like some input on my coding for anyone willing to give it. I tend to try and write things to where someone (Such as a member of my team who is also learning DBPro) could come along behind me and easily pick up or change the code.
My question is this, how can this game be written to make it more simplistic, yet still be easy to follow by someone coming in behind me? Or is the code ok as it is? All advice, no matter what it is, is very appreciated.. and thanks in advance!



Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 23rd Jun 2012 01:32
Well Three Of A Kind, Four Of A Kind, and Five Of A Kind all use exactly the same code so you could use a For Next loop. But apart from that it is easy to follow.

Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 23rd Jun 2012 11:06
Thanks Pincho.. I appreciate the input Easy to follow is what I was going for. Unfortunatly at times that means probably twice the load of code writing, but I am getting better as I go

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 24th Jun 2012 05:43 Edited at: 24th Jun 2012 06:36
Where to begin

1. Declare your variables , prevents misspellings e.g. Foreground as opposed to Forground
2. Reusable code should always be put in functions.
3. Never have loose code after your Main loop bad coding practice.

Here is a quick example
I quickly broke down your code into function calls, to make it easier to follow the flow of the code.
Code should be readable and reusable. You should have no duplicate code. Duplicate code should be put in a function.

EDIT:Excuse large indents Pasting code in code snippet block seems to increase the indenting.




[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 24th Jun 2012 07:07
Thanks Stab! Ya the code was a re-write of an example given to me to work with in a book that is teaching me DB. However, I had not gotten to functions at that point (as opposed to now), nor has the book even began to touch upon declaring the variables before hand...so the advice is very sound and I appreciate it

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 24th Jun 2012 14:12
Here's a very crude example of mechanics to look at. It's a way of simplifying code. It's obviously incomplete but something to think about when you code. You can easily use the elements in the string returned in SELECT switches to perform whatever other tasks. To re-iterate what Pincho said, "[there's no need for all those functions for each match]"



Just something to think about.

Login to post a reply

Server time is: 2024-11-23 21:09:26
Your offset time is: 2024-11-23 21:09:26