1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Making a solitaire game

Discussion in 'Programming' started by Matt93, Feb 19, 2017.

Tags:
  1. Matt93

    Matt93 Guest

    Hello everyone,

    I'm currently attempting to make a solitaire game for coding practice. I've rarely seen card games done with Game Maker, so thought it was a worthy project!

    I've been focusing mainly on getting the cards set up in a grid, being able to move them etc. I've created the deck with a ds_list:

    Code:
    //Create the deck
    deck = ds_list_create();
    
    //give the list integers from 0 to 51 (52 integers representing 52 playing cards in a deck)
    for(var i = 0; i < 52; i++)
    {
        ds_list_add(deck, i);
    }
    
    ds_list_shuffle(deck);//shuffle this list
    I've also put them into a ds_grid:

    Code:
    //create the grid
    width = 7;
    height = 1;
    height_last_row = 7;
    max_height = 13;
    x_start_of_gamespace = 64;
    y_start_of_gamespace = room_height - 250;
    xx = 64;
    yy = room_height - 250;
    position = 0; //position in deck
    
    play_area = ds_grid_create(width,max_height);
    
    //width
    for (var i = 0; i < width; i++)
    {
        for (var j = 0; j<height; j++)
        {
            ds_grid_set(play_area,i,j, ds_list_find_value(deck,position))
            m = instance_create(xx, yy, obj_card) //see the visual
            m.image_index = ds_list_find_value(deck, position);
            yy+= 30;
            position++
        }
        yy = room_height - 250;
        xx +=80;
        height++;
    }
    I'm able to move them around okay, and coding this so I can only move the front card shouldn't be an issue. I'm stuck on how, when I have two or more that are movable in a column, I'm going to code this so both of them move at once? And also so that the ids of both, rather than just one, are stored and the cards will be put down in the correct order? I currently have a variable called global.card which is set to noone in create event, then to the id of the card I click on. This is set back to noone when the card is put down.

    I have also had problems snapping the cards to the grid properly. If I could have any advice with any of those things, or any pointers if I'm going about this completely wrong, that'd be great.

    Cheers!
     
  2. InkSurfer6V

    InkSurfer6V Guest

    Im no expert with DS functions, but in theory if you had a object following the mouse as you moved it, as you placed it down, if it was touching a 'slot' object, the x and y of the card would go to the x and y of the slot. Im not sure how functional this system is tho, as if it was touching more than one slot, you might get errors.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice