This site requires JavaScript, please enable it in your browser!
Greenfoot back
MrSandwich
MrSandwich wrote ...

2016/3/20

Dealing cards when the deck is clicked

MrSandwich MrSandwich

2016/3/20

#
Hello, I'm a complete noob at Greenfoot and I am starting to give my first foots in programming in general. With this said I'm trying to do a card game and the first thing I thought of doing was dealing a random card when the deck is clicked. So far I have:
public void Deck()
    {
        Baralho= new GreenfootImage ("redflip.png");
        setImage(Baralho);
        if (Greenfoot.mouseClicked(Deck))
{
    switch( Greenfoot.getRandomNumber(3) )
        {
            case 0: setImage("cards/aceclubs.png"); break; //or whatever your image files are named
            case 1: setImage("cards/acediamonds.png"); break;
            case 2: setImage("cards/acehearts.png"); break;
        }   
    }

}
And then on the World class Table i have the following to call the Deck
addObject(new Deck(), 100, 100);
But I have no luck in doing what it's meant to do ( Draw a random card on the table). I'm in need of some inspiration, and I'd like to have you guys reccomend tutorials before starting Greenfoot(already watched the most basics ones). Thanks in advance.
danpost danpost

2016/3/20

#
All the code given is executed while the Deck object is being created and before it is added into the world. It cannot receive a mouse-click if it is not in the world, so the image remains as a 'redflip' image. Lines 5 through 13 should be placed in the 'act' method so that they are continuously executed while in the active world (so, a click can be constantly checked on).
MrSandwich MrSandwich

2016/3/20

#
I don't get it (Sry I'm rly bad at this, need way more practice) . I should add it to the 'act' method in the Deck class or the table class?
Super_Hippo Super_Hippo

2016/3/20

#
In the Deck class. And line 5 should be
if (Greenfoot.mouseClicked(this))
MrSandwich MrSandwich

2016/3/20

#
Thank you so much. it's working now :) Can you recommend me some tutorials I can watch to get the basic grasp of getting to make a card game?
danpost danpost

2016/3/20

#
MrSandwich wrote...
I'm a complete noob at Greenfoot and I am starting to give my first foots in programming in general. With this said I'm trying to do a card game
There is quite a lot involved in making a card game. As a "newbie" in programming in general, I would consider it a jump. You should build a foundation in both programming and in using greenfoot before trying an endeavor as extensive a project as that.
You need to login to post a reply.