Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7185775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:29:23+00:00 2026-05-28T18:29:23+00:00

I’m working on a Monopoly based game with properties, money, cards, etc. I recently

  • 0

I’m working on a Monopoly based game with properties, money, cards, etc. I recently ran into a problem when working on the chance card aspect of the game…

I have an array of Strings that say things, ex,”Tax refund; collect $25″ or “You lose money due to stocks; -$100”. Each card does something different, not all of them just deal with money. My question: how can i store these cards to each hold a string with its description but also any action that is involved. For example, card1 has a String and an int value (-25), but on the other hand another card, card2 has a String, an int value(+10) and a property. Sorry if the question is really vague but I don’t know how else to describe it.

Just to clarify:

A card could contain simply the description and a money value. While another card might contain a description, money value and move certain spaces.

Thanks to everyone who gave out awesome ideas so quickly!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:29:24+00:00Added an answer on May 28, 2026 at 6:29 pm

    If your range of actions is very limited (say, 2 or 3 actions involving money, move squares, etc) then I might use the following class:

    class Card {
        // It would be a good practice to not make the following fields
        // public and use getters/setters instead but I've made them this
        // way just for illustration purposes
    
        public String text;
        public String action;
        public int value;
    
        Card(String text, String action, int value) {
            this.text = text;
            this.action = action;
            this.value = value;
        }
    }
    

    This way (as already pointed out by some other answers), you can use an array of Cards instead of array of Strings. You can then have text in one field, the action in a separate field, and the value associated with that action in a third field. For example, you could have the following cards:

    Card lose25 = new Card("You lose $25", "money", -25);
    Card move5squares = new Card("Move 5 squares ahead!", "move", 5);
    

    When you’re ‘processing’ the cards, you can do so in the following manner:

    ...
    if (card.action.equals("money") {
        // Update user's money with card.value
    } else if (card.action.equals("move") {
        // Update user's position with card.value
    } else if (card.action.equals("...") {
        // and so on...
    }
    ...
    

    EDIT:
    If the cards can hold more than one action, you can use a HashMap to store actions for that card:

    class Card {
    
        public String text;
        public HashMap<String, Integer> actions;
    
        Card(String text) {
            this.text = text;
            actions = new HashMap<String, Integer>();
        }
    
        addAction(String action, int value) {
            actions.put(action, value);
        }
    }
    

    A HashMap is a collection that can store key-value pairs. So for a card that has 2 actions, you can use the above code as:

    Card aCard = new Card("Lose $25 and move back 3 spaces!");
    aCard.addAction("money", -25);
    aCard.addAction("move", -3);
    

    Now, when you’re actually processing the cards, you need to check the HashMap for all actions stored in this card. One way to iterate through the HashMap is to do the following:

    Card processCard = ...;
    
    for (Map.Entry<String, Integer> entry : processCard.actions.entrySet()) {
        // This loop will get each 'action' and 'value' that you added to
        // the HashSet for this card and process it.
    
        String action = entry.getKey();
        int value = entry.getValue();
    
        // Add the earlier 'card processing' code here...
    
        if (action.equals("money") {
            // Update user's money with value
        } else if (action.equals("move") {
            // Update user's position with value
        } else if (action.equals("...") {
            // and so on...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.