Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Code for skill point distrubition in a simple game

$
0
0
public static void distr(Character chr){
		System.out.println("Please set your character's skills... You have 20 skill points in total");
		Scanner scan = new Scanner(System.in);
		int k = 21;
		int dec;
		int n;
		while(k>0){
			if(k!=1){
				System.out.println("Type:\n 1 for Mana \n 2 for Strength");
				dec = scan.nextInt();
				if(dec == 1){
					System.out.println("How many points do you want to add?");
					n = scan.nextInt();
					chr.setMana(chr.getMana() + n);
					k = k - n;
					System.out.println("You have " + (k-1) + " skill points left.");
				}
				else if(dec ==2){
					System.out.println("How many points do you want to add?");
					n = scan.nextInt();
					chr.setStr(chr.getStr() + n);
					k = k - n;
					System.out.println("You have " + (k-1) + " skill points left.");
				}
				else{
					System.out.println("error!");
				}
			}
			//user check of the character's skills
			if(k == 1){
				String str;
				System.out.print("Do you want to reset your skill points?(Y/N)");
				str = scan.nextLine();
				str = scan.nextLine();
				if(str.equalsIgnoreCase("n")){
					System.out.println("OK. Your stats: ");
					k--;
				}
				if(str.equalsIgnoreCase("y")){
					k = 21;
					chr.setMana(0);
					chr.setStr(0);
				}
			}
			
		}
		System.out.println("Mana:"+chr.getMana() + "\n" + "Strength: "+ chr.getStr());
								
	}

I'm very new in Java coding and we did not learn about break, switch and continue statements. Is this code OK for a distrubition system. By the way, when the user is distrubuting the skill points he is expected to distrubute them considering the points left..(I will fix that later. And of course the character has not only two skills this is just an example). Thank you for your help!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>