Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a Recruit Army System on my Java Text Based Strategy RPG, so here are the integers by the way:

    public int Swordsman; //Price: 10 each
public int Ronin; //Price: 10 each
public int Rider; //Price: 20 each
public int Archer; //Price: 10 each
public int Wizard; //Price: 20 each
public int Mage; //Prince: 20 each
public int Destroyer; //Price: 40 each
public int Soldiers; //Price: 30 each
public int totalarmies = Swordsman+Archer+Wizard+Mage+Destroyer+Soldiers;

So first off, I made some dialogues that will display the ones I will recruit:

                System.out.println("=========RECRUIT============");
            System.out.println("Coins: " + coins);
            System.out.println("Swordsman - 10 Coins Each");
            System.out.println("Ronin - 30 Coins Each");
            System.out.println("Rider - 20 Coins Each");
            System.out.println("Archer - 10 Coins Each");
            System.out.println("Wizard - 10 Coins Each");
            System.out.println("Mage - 20 Coins Each");
            System.out.println("Destroyer - 40 Coins Each");
            System.out.println("Soldier - 10 Coins Each");
            System.out.println("===========================");

Say for example I have the user input how many Swordsman he or she likes to recruit. I set up a Scanner to scan the number the user inputs and say the user inputs 20 (as max).

How can I determine the amount of coins needed to the number of the recruits the user inputs and if the coins I have on my pack can sustain the amount of recruits?

Second question is, how can I limit the user to recruit 20 units max to each class, so that the user can only recruit 20 swordsmen, 20 ronins etc?

Thank you in advance

share|improve this question

1 Answer 1

up vote 4 down vote accepted

This seems like a very rudimentary programming problem and probably off topic for the site.

How can I determine the amount of coins needed to the number of the recruits the user inputs

coinsRequired = SwordsMen * playerInputNumber

if the coins I have on my pack can sustain the amount of recruits

if( coins >= coinsRequired ) { ... }

how can I limit the user to recruit 20 units max to each class

I'd just set up a dictionary of id (type of unit) to int (number of that unit) and keep track of the number of units that way.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.