Problems with code for a card game.

BlitzMax Forums/BlitzMax Programming/Problems with code for a card game.

WERDNA(Posted 2010) [#1]
Hey folks!

I'm working on a game engine for Solitaire type card games right now, and having
a tad of trouble.

I used this tutorial.
http://www.informit.com/articles/article.aspx?p=130837&seqNum=3

But it's for Visual Basic. So I've been converting it all into BlitzMax, with a relative
degree of success.

However I've run into a snag ;)



There's my code as it stands, with 3 Types, and a short function near the
bottom for testing all the functions to make sure things work.

I managed to create an instance of the clsDeck type, named Deck. When it
tries to access the Hand type though, it returns an error that the type doesn't
exist.

I'm pretty darn sure it's because I need to create type lists for everything, to
keep track of them. However since all 3 types interact with each other a LOT,
and some of the type fields reference other types, I'm getting a bit confused
as to how this all works out. I've never used types within types this much
before, and am not sure where to make calls to the type lists.

If someone could help me out, that would be really, really nice.

Thanks!


Dabhand(Posted 2010) [#2]
.

Even though the info was correct in the old post regarding arrays, I noticed the syntax wasnt, so, heres a quick version:-

Type MyType
	Field arr:Int[] ' Not initialized

	Method New() ' This function is called when a new MyType is created with New
		arr = New Int[32]
		'or you could init with a normal for..loop and using New on each element
	End Method
End Type

Local a_type:MyType = New MyType

a_type.arr[16] = 10

Print a_type.arr[16]


Dabz


Czar Flavius(Posted 2010) [#3]
Oh My God.

That is some of the worst Blitz Code I have ever seen.

Method GetxPosition:Int()
xPosition = m_xPosition
End Method

What the hell is that supposed to be??? A getter??? It's going in a global variable!!!

Ahem, sorry.




There is a reason why nobody takes Visual Basic seriously. Find a better tutorial before you are lost irreversibly to the dark programming gods.


And personally I can't stand prefixing members with "m_". If you can't keep track of what's a member and what isn't, you shouldn't be allowed to program.


WERDNA(Posted 2010) [#4]
@Dabz, thanks Dabz, I'll give that a shot ;)
And yes, I know I need to indent. I still need to clean up the code a lot, I just want
to get the basics working first.

@Czar Flavius
That is some of the worst Blitz Code I have ever seen.

I am fully aware of this fact ;)
Although I have now created my first commercial game, I am still very far away from being a 'clean' coder. I.e, someone who codes something that is well written, and easily understandable.

Also keep in mind that for a lot of this I'm just giving it my best guess, since I have
0 experience with Visual Basic. I'm converting it as best as I can.

I had no clue what the m_ is for, so I just left them all in there.
This is the best tutorial I could find, and does(Supposedly) everything I want
my game to do. I just need to figure out how to convert it.

I'll try Dabz suggestion(Keep in mind, I only started using arrays a month ago, so
I'm still relatively new at them), and see what that does.

Thanks!


Dabhand(Posted 2010) [#5]

I had no clue what the m_ is for, so I just left them all in there.



Generally, the m_ prefix means that its a member variable of a type/class (In some cases it may suggest the variables scope, like if a variable is private)... Its just a naming convention really, like how we put a capital 'T' at the start of our Type names: eg

Type TWorld
End Type

Type TMenu
End Type

etc etc

Dabz


WERDNA(Posted 2010) [#6]
Thanks for the clarification Dabz!


Dabhand(Posted 2010) [#7]
You've also got to remember that when converting from one platform to another, you really need to know the intimate behavior of the one your converting from, so you can make compromises in the platform your converting too.

Take converting BlitzMax to XNA... Pretty simple, the main coding doesnt take much converting to C#, but, if you didnt know XNA uses radians instead of degrees, your gonna see some odd results, but, if you know this, you can quickly knock out a small bit of code to convert between the two and your away!

You are probably better off rolling up your sleeves and trying to build something yourself if no code for Blitzmax is lying around, this will essentially save you a lot of hard work when you try to change or add to your code in the future, because for one, its in a language you know well, and two, its your own code.

:)

Dabz


Jesse(Posted 2010) [#8]
I created cardsLib.bmx that include all of the basic types clsCard and clsDeck, cardForm and Hand:

this is as accurate as I can get it but there might be some errors(or not) not tested enough.


Dabhand(Posted 2010) [#9]
Nice work Jesse! :)

Dabz


WERDNA(Posted 2010) [#10]
Thanks Jesse!

Much appreciated :)


Jesse(Posted 2010) [#11]
The code above was never tested as I had one hour to do it and post it. I finally got some time to really try it out and discovered that there were quite a few errors so I updated the code above and added a type to load the images and modified the clsCard to display accordingly. it is still not complete but I am trying to test it and I am creating a type with the code posted on the link you posted WERDNA.

this is what I got so far(I'll finish it tomorrow):


[edited]
working demo now.


WERDNA(Posted 2010) [#12]
Really appreciate the help Jesse!

And omg, paypal does to!

Check your e-mail ;)


Jesse(Posted 2010) [#13]
oh, you shouldn't have but thanks anyway. I don't do it to get payed. I do it to help others and myself at the same time. Besides, it was not that difficult. Most of it was search and replace except for the annoying line numbers.

I made a spider solitaire game a while ago that I wanted to compare code with the one from your link. That was my main interest and the fact that I had some free time and wanted to challenge myself to see if I could do it. I programmed in Visual Basic for a couple of months but that was the first year it came out. I left it because it wasn't working for me as I hoped. I did noticed that some of the stuff was a little bit different than I originally remembered.

I will keep working on it to see if I can get the engine working correctly. I will post a working demo when and if I get it running. No guarantee.


Jesse(Posted 2010) [#14]
Cheers WERDNA,
I think I have it now! I tried it with a dummy deck and it looks like it's working.

To use it, set the "CardForm " "new" method to load the cards graphics and it will work properly. there might be some bugs that I am not aware of but if someone points them out I might be able to fix them.

I used cards graphics that don't have a black image so I couldn't tell if it was deleting them or not.

I updated my last post that has source code with the updated demo code.


WERDNA(Posted 2010) [#15]
You deserved payment. You saved me a great deal of time and effort :)

Using the code that you posted(With a few modifications), I managed to get it up
and working. I can now use any of the functions and methods, I just need to put it
all together into a game now. Which won't be too hard now that the basics are done.

The main problem was in the Init_Hands method.

A new hand was never created, thus I nothing to hold the code up with and got
errors.


But I think it all works fine now, so thanks for the help!

I might like to hire you for a bit of codework in the future if I get stuck again, lol.


Jesse(Posted 2010) [#16]
yes I made the mistake of creating a new deck after auto creating and initializing it.
I did fixed the code above. I don't know if you seen it sense I thing we were posting at the same time.


WERDNA(Posted 2010) [#17]
I saw when reading my post for typo's ;)

Thanks a bundle!

I really appreciate it!