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

2017/2/10

How Do I Change Value Of Actors(cards) Based On Previous Actor Selected?

zanzabarjones zanzabarjones

2017/2/10

#
I am working on a combinatorial card game,when the world is initiated and first card gets clicked the score is set to zero but the values of the remaining cards changes based on a list of integers of how well each card combines with that card,when the next card gets clicked the integer value of that card is added to the score and so on and so on. So how do I do it how would I assign an integer value to each actor/card based on the previous actor/card chosen..Can someone please help me using a simple example of 5 cards? my actual list has 40+ cards but a five card code will help me to understand the gist of it
Super_Hippo Super_Hippo

2017/2/11

#
Let's say you have one class Card. And each different card is represented by a different 'type' value. For 5 cards, these values would be 0-4. If you press a card with type 3 and then one with type 2, it will add a certain number of points. The next card's previous is 2 then. The array could look like this:
private static final int points[][] =
{
    {2, 5, 3, 8, 1}, //for card with type 0: if last card was 0, add 2 points, if last card was 1, add 5 points and so on...
    {3, 1, 6, 3, 2}, //for card with type 1: if last card was 0, add 3 points...
    {8, 2, 7, 3, 9},
    {3, 2, 6, 3, 4},
    {3, 5, 2, 8, 2}
};
When creating the Card, save the type:
private in type;

public Card(int typ)
{
    type = typ;
}
To return the points, the method could look like this:
public int getPoints(int previous)
{
    if (previous == -1) return 0; //if there was no previous card
    return points[typ][previous];
}
If every card needs to have a specific score for each other card which was previous, you will need to store numCards*numCards values in the array. For 40 cards, that would already be 1600 values.
You need to login to post a reply.