Top Section

Welcome to my computer games design blog ..

Tuesday 24 March 2015

Easter Break : Game Script help (session two).

So now we have a filled in game-deck, however these cards are not random.

We need to randomise these cards.

How do we do that?

well we set-up another global variable called deck.

Then we randomly copy cards from gamedeck to deck

We use a special function called irandom, irandom is a Gamemaker function that generates random numbers in a range you set.

so irandom[51] creates a random number from 0 to 51, however our cards start at one and end at 52 so we use

 cardno = irandom(51)+1;

where cardno stores a random number from 1 to 52.

now we need to randomly copy all 52 cards from the card deck (set as carddeck) to the random deck (which is defined as deck )

We need a loop to do this in, so we use a for loop

for (i = 1; i < 52 ; i++)
{  
    
}

in this loop i starts at 1 and ends at 52

If we choose a random number there is a chance that we will get the same number again!
Roll some dice and you will get the same numbers occasionally (the theory of probability shows this).

So how do we stop that?

Well when we set the gamedeck up we set it up as gamedeck[1,1] = "heart_a" or something.


gamedeck[1,1] = "heart_a";

So we need to log what cards are taken and we do that using a value of false or true. True means its taken and false means its not, simple as that so...

We do this

gamedeck[1,0] = "false";

Note [1,0] we use 0 not 1 after the


Ok I know this is hard to understand but look at this...

for (i = 1; i < 52 ; i++)
{  
    gamedeck[i,0] = "false";
}

What are we doing?
Answer setting all gamedeck as cards not taken (false).

When we take a card from the gamedeck and copy to random deck (called deck) then we set the value to true (as in its taken)

SO ...

for (i = 1; i < 52 ; i++)
{  
        cardno = irandom(51)+1;
        if gamedeck[cardno,0] == false
        { 
          gamedeck[cardno,0] = true; 
          deck[i] =  gamedeck[cardno,1];
         }
}

PS This CODE IS INCOMPLETE! What is missing?

What are we doing?

Checking to see if card is taken if gamedeck[cardno,0] == false
Setting card to taken  gamedeck[cardno,0] = true; 
Adding card to random card deck deck[i] =  gamedeck[cardno,1];

All this needs to be added as a new script as well.



No comments:

Post a Comment