Jump to content


Photo

Blackjack game, need help getting started


  • Please log in to reply
1 reply to this topic

#1 JusticeDude

JusticeDude

    GMC Member

  • GMC Member
  • 17 posts
  • Version:GM:Studio

Posted 24 April 2012 - 11:22 PM

Hi guys. I'm messing around with the GM Studio beta and trying to make a Blackjack game. I have a little experience messing around with shoot'em ups in GM in the past, but making card games is a big changing of gears and is tripping me up. I've been searching for tutorials and advice, but it's hard selecting bits and pieces of other people's code and trying to make it all work together. I know a little about GML, but not as much as I'd like, being a little more experienced in things like C# and JavaScript.

The specific things that are tripping me up are storing and retrieving cards from a ds_list and managing card sprite images. I understand that it would be wise to use a ds_list to represent the deck as it has a built in shuffle function, but I need some clarification on how things are actually added, and how to 'pop' a card off the top once it's been shuffled. I tried using some of the code in the sample card game, but it doesn't really seem to work as intended.

//Generate the card list
for(i=0;i<52;i+=1){
    c = instance_create(0,0,objCard);
    c.suit = floor(i/13);
    c.rank = i-(c.suit*13);
    c.image_speed = 0;
    ds_list_add(dCards,c);
}

// Shuffle the deck!
ds_list_shuffle(dCards);
...but this seems to create a stack of cards in the corner of the window. Not exactly what I was looking for. I need the card not to show up on screen until I need it, but I don't know how to get it once it's in the list.

What I'm trying to do is this:
-create and shuffle a deck of cards at the beginning of the game. After I get that working I'd like to be able to control the number of decks in the 'shoe,' but one thing at a time.
-create a script of drawing a card from the deck that can be used on the button for Hit, Double, etc.

I also have all my card images stored in one sprite, but I'm not clear on how to specify the sub-image to correspond to the face value.


I hate to sound like I'm asking for the majority of the game to be handed to me, but any help would be greatly appreciated.
Thanks!
  • 0

#2 Weird Dragon

Weird Dragon

    GMC Member

  • Global Moderators
  • 1915 posts
  • Version:GM:Studio

Posted 26 April 2012 - 08:37 PM

You don't need to create 52 instances of the card object in order to make a ds_list of all the cards. As a matter of fact you don't need any card instance for that purpose. Instead I suggest that you make a ds_list with 52 values where the values are the numbers 0-51 representning the 52 sub images in the card sprite.
After you have shuffled the list you 'pop' a card off the top of the deck with the function ds_list_find_value by using the value at position 0. That value will then determine which sub image to display and thus which card. You can then create an instance of the card object with that sub image. Then you delete the value at position 0 with ds_list_delete. Now a new value will exist at position 0, so can draw a value 52 times before the list is empty.

Edited by Weird Dragon, 26 April 2012 - 08:49 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users