I need help with a basic card game - BEGINNER

T

TidusXCloud000

Guest
Hello everyone,

I am a beginner to Game Maker Studio 2, I have made some basic games such as platformers and top down tank shooters in previous Game Makers to give you an idea of where I am up to in my experience.

I am trying to make a game right now which is a card game which involves one player or two players. I'll give you the rules:
The game is based off of Topps Match Attax and their soccer section. Essentially one player gets to choose either 'attack' or 'defence'. Each card has an attack stat and a defence stat. Two players place a card down and whoever has the highest stat wins both cards, and rests them next to the player, showing the amount of cards he has won. The game will go on until one player has lost all of their cards. So what I am struggling with is the fact that I have many cards with different statistics. How would I give a player a random deck of cards, and then let them choose a stat on which to play on. Basically, how would I code this game? I understand the basics, which is setting up the room, the sprites, and I have made an object for each of the cards to go off of. If anything is unclear, please do not hesitate to ask. I will leave an example of one of the cards in the link below. Also, I can just make the card change from its back to the front through just an animation where the player clicks and both cards flip, right? Thank you so much!IMG_4633.JPG
 
T

Taddio

Guest
I Basically, how would I code this game? I understand the basics, which is setting up the room, the sprites, and I have made an object for each of the cards to go off of. View attachment 24728
Don't go with one object per card. Use at most one object for the whole deck of cards.
Check out arrays and how to use them, they would be perfect to hold your cards data. And ds_list would be perfect for shuffling decks, draing cards, adding cards to the hands, etc. Just don't go with that many different objects, you'll hate yourself later on
 
T

TidusXCloud000

Guest
Oh, I guess that makes sense. I haven’t come across that command, but I have seen videos based around the “ds” function when it comes to stacks. Thank you!
 
T

Taddio

Guest
Oh, I guess that makes sense. I haven’t come across that command, but I have seen videos based around the “ds” function when it comes to stacks. Thank you!
Basically, they are very much like arrays (which I would abuse of in your case, too!)
The whole deck data could be just a simple 2D array, like (taking the card above as example)
Code:
deck[0,0] = "Robin Van Persie";  //PLAYER NAME
deck[0,1] = 20;        //DEFENSE
deck[0,2] = 84;       //OFFENSE
deck[0,3] = "Arsenal FC";       // TEAM
ds_list, I would use for more volatile data, like player's hand and such, but for the data that you need to access on a regular basis, just a good ol' 2D array would do all you need, and it's easy to access. Need to draw the player name?
Code:
draw_string(x,y,deck[current_card, 0]);
Need to use the def value to calculate some stuff?
Code:
var _def = deck[current_card, 1];
And boom!

Really useful and user-friendly, plus it's clean, readable code
 
Last edited by a moderator:
T

TidusXCloud000

Guest
OMG! You are such a great help, was busy with school, sorry for the late reply. Thank you sooo much, I really deeply appreciate it.
 
T

TidusXCloud000

Guest
Basically, they are very much like arrays (which I would abuse of in your case, too!)
The whole deck data could be just a simple 2D array, like (taking the card above as example)
Code:
deck[0,0] = "Robin Van Persie";  //PLAYER NAME
deck[0,1] = 20;        //DEFENSE
deck[0,2] = 84;       //OFFENSE
deck[0,3] = "Arsenal FC";       // TEAM
ds_list, I would use for more volatile data, like player's hand and such, but for the data that you need to access on a regular basis, just a good ol' 2D array would do all you need, and it's easy to access. Need to draw the player name?
Code:
draw_string(x,y,deck[current_card, 0]);
Need to use the def value to calculate some stuff?
Code:
var _def = deck[current_card, 1];
And boom!

Really useful and user-friendly, plus it's clean, readable code
Hey there, sorry to bother you again. I would like to know how to give a player a random set of cards. I have approximately 50 saved up, and would like to utilise all of them. I'm planning to give the player 10 cards for his deck. Thanks!
 
T

Taddio

Guest
Hey there, sorry to bother you again. I would like to know how to give a player a random set of cards. I have approximately 50 saved up, and would like to utilise all of them. I'm planning to give the player 10 cards for his deck. Thanks!
You will need some kind of list that holds the cards the player has. I would suggest either a 1D array or a ds_list.
You could then use a loop (length of which is the number of cards you have to draw) combined with irandom(deck_size) and add the random card from the deck in the player hand. You would obviously need to add a conditional in there to avoid duplicate cards.

Another way to go would be to simply shuffle the whole deck and pick the cards from the top to bottom. This would be how cards work in real life, but that's the beauty of game dev: illusion! It doesnt have to be realistic under the hood if the end result appears to he the same.

Just go step by step with it. If you don't master them yet, you will need to check arrays, data structures, loops, and the various random functions. They will be useful for a ton of other stuff, so it's worth learning them sooner than later
 
Top