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 / How is my coding?

Author
Message
Gadget
14
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 26th Jun 2010 11:42
Hello Everyone,

I have been slaving away for a few days to try and make a basic tic tac toe game to learn with. So far I am enjoying what I am doing and know that my code is noobish because well, I'm a noob. I would like somone to take a look at my code and let me know if there are any improvements that can be made to. Thanks.

Gadget

P.S. I hope I did the code insert correctly.

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 26th Jun 2010 15:40
There is no victory condition?How about that?
I challenge you to rewrite it without gosubs.
Are your images power of 2?I know that in game like this probably is irrelevant if they are or not but is good to make it a habbit to use proper images, because computers make calculations faster with images power of 2.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th Jun 2010 19:19
What's strange to me is those semicolons should be colons... but apparently they do work in IF/THEN statements. I think you've unwittingly found a bug.

Gadget
14
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 26th Jun 2010 23:57
What do you mean using an image with the power of 2? And how would suggest doing it without using gosubs and not having just a long page of code? I just started working on victory conditions so that will be next.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 27th Jun 2010 00:06
I havent run your code, but it does look neat, if thats what you meant by "How is my coding?". Just, you didnt indent your gosubs, but yeah, its really neat.

Derekioh
15
Years of Service
User Offline
Joined: 1st Feb 2009
Location:
Posted: 27th Jun 2010 02:14
I suggest you use functions instead of gosubs. And i think that your beginning is a bit compact, but you have it all commented so i can't really complain

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 27th Jun 2010 03:59
As Derekioh said use functions instead of gosubs, that what i wanted to say with the challenge to write it without gosubs.I said it that way assuming you are known with functions which apparently is not?

Looking at your code i think you are not using images like 16x16,32x32 64x64 and etc. resolutions.Someone correct me if i`m wrong because english is not my mother`s, but as i know this is called power of 2.As i know computers make calculations with this kind of images faster.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 27th Jun 2010 07:15
Quote: "because english is not my mother`s"

XD
should be "engllish is not my mother language". What you said is that your mother doesn't own english.

Anyways, that code is good for a start, but you really can't code a whole game like that. what developers do when they have, say, 10 different images with 10 different states each, they don't write 100 if statements, they use variables, for loops, types, arrays, and functions.

for example, copy and paste this code into the editor:


That code probably uses a lot of new concepts (you probably aren't familiar with user defined types, explicitly declaring variables "as integer", colors and dwords, expanding arrays/array insert at bottom, etc.), but at the same time, it's shorter, and can be expanded to any number of buttons easily!

that's what I love about coding. If you find yourself doing a LOT of repetitive coding, it's a good idea to stop for a second and think of another way to go about doing what it is you want to do.


For a tic tac toe game (it looks like that is what you're doing), here are the changes I would suggest you make to your code, without really going into the other concepts I mentioned above:

declare "location(8)" as "dim location(2,2). this would create an array looking like this:

location(0,0) location(0,1) location(0,2)
location(1,0) location(1,1) location(1,2)
location(2,0) location(2,1) location(2,2)

and would probably be easier to wotk with.

then, make a function to draw a circle at a given location (so you could call something like "drawcircle(1,1)" to draw a circle at the given location.

then, try to replace those repetitive if statements with for loops.

It's a lot to take in, I know... but really the only way to go is to keep trying to wrap your head around everything, and eventually it'll all be easy (eventually).


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 27th Jun 2010 10:04
Why should he use functions? What advantage do they have over gosubs in this situation?

There is no point in using a function if you don't need to pass a variable to it, or if you don't receive a value from the function. If it does neither of those, it is, for all intents and purpose, a gosub.

Rawwrr. Sig Fail.
Newcastle is awesome
Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 27th Jun 2010 14:49
it was a challenge, he didn't say YOU SHOULD, he suggested it, it may or may not have been a way to try to expand knowledge of the coding language maybe?

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD

I can see from your smile, you're not here for the sunset.
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 27th Jun 2010 16:04
Well I can also argue that I'm trying to expand his knowledge of when to use functions and when to use gosubs.

Rawwrr. Sig Fail.
Newcastle is awesome
Derekioh
15
Years of Service
User Offline
Joined: 1st Feb 2009
Location:
Posted: 27th Jun 2010 20:21
I guess the problem is that i use to use gosubs and only gosubs. Needless to say, when i went to try to code something like a FPS, it didn't work out to well. I do have to say, for something like this, either way would work.

Michael73
14
Years of Service
User Offline
Joined: 29th Jan 2010
Location:
Posted: 6th Jul 2010 12:17
I think your going just great so far ! And i have to agree with nearly everything Neuro Fuzzy said. Just keep it up and keep learning

Login to post a reply

Server time is: 2024-11-23 14:13:38
Your offset time is: 2024-11-23 14:13:38