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

2023/12/3

Trying to get data about an object without a specific name

Squashyoshi Squashyoshi

2023/12/3

#
Hi I'm pretty new here(have done greenfoot for only a few months). Anyway, I'm trying to make it so I can click on an object and have an array change based on the object's data. I have data stored in the array, and added the objects with a constructor that had the data in it. However, the data and the specific objects are not connected. Basically, what I'm asking is if there is a way to see the variables that passed through the constructor of each individual object. Background: I'm trying to make uno, I am using arrays to store the players' hands, and I want to be able to click on a card, then click on the pile to play that card and have the array be updated accordingly. (this is in my card class)
if(Greenfoot.mouseClicked(this) && !cardSelected) {
           //how do i find the specific data from this object(the number and color) and change the array
}
The arrays in the MyWorld class:
public int p1Hand[][] = {
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        };
Thank you for your help btw, I really appreciate it ;)
danpost danpost

2023/12/5

#
Squashyoshi wrote...
I am using arrays to store the players' hands, and I want to be able to click on a card, then click on the pile to play that card and have the array be updated accordingly.
Since the size of a hand is variable, it might (will be) better to use List objects instead of Array objects for the hands (plus draw and discard piles). You can use an array for the players themselves (a game will have a set number of players, regardless of what that values might be. The if block might be best placed in your MyWorld act method. Or, at least the actions when a card is clicked should be there (a card can inform the world it was clicked on easily enough). The MyWorld class should retain a reference to the players, the discard pile and the draw pile and its act method should control gameplay.
You need to login to post a reply.