Results 1 to 7 of 7
  1. #1
    Areptom is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default Illegal argument: n must be positive

    A game im making for teh lulz is working fine, when i boost my stats to 9999 each, the damage formula seems to be glitched, causing an error.

    Damage fomula(s)
    Java Code:
    //calculations
    				cdmg = (estr * eatt)/25 - (def/2);
    				pdmg = ((str * att) * ppot)/25 - (edef/2);
    				elvl = (eatt + estr + edef)/150;
    				addcoin = randdmg.nextInt(5);
    				
    			//xp counter
    
    
    				while(hp > 0 & ehp > 0){
    
    					//computer attack =\
    					dmg = randdmg.nextInt(cdmg);
    Java Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.*;
    import java.util.*;
    
    
    
    public class Game {
    	public static void main(String[] args) throws Exception, IOException, InterruptedException {
    		InputStreamReader input = new InputStreamReader(System.in);
    		BufferedReader reader = new BufferedReader(input);
    		String name = "";
    		System.out.println("Enter name of Character");
    		name = reader.readLine();
    		System.out.println("Welcome " + name + ".");
    		System.out.println("If there is a previous save file for this character");
    		System.out.println("use the load command to load it.");
    
    		//player ints
    		int str = 50;
    		int att = 50;
    		int def = 50;
    		int lvl = 1;
    		int hp = 100;
    		int hplvl = 100;
    		int xp = 0;
    		int pdmg = 0;
    		int ppot = 1;
    		
    		//npc ints		
    		int estr = 0;
    		int eatt = 0;
    		int edef = 0;
    		int ehp = 0;
    		int elvl = 0;
    		int cdmg = 0;
    		
    		//random ints and strings bro =\		
    		int dmg = 1;
    		int txp = 0;
    		String cure = "";
    		int tlvl = 0;
    		int healamount = 0;
    		int addcoin = 0;
    		int cost = 0;
    		
    		//inventory
    		String slot1 = "";
    		String slot2 = "";
    		String slot3 = "";
    		String slot4 = "";
    		String slot5 = "";
    		int food = 0;
    		int coins = 0;
    
    
    		Random randdmg = new Random();
    
    
    		String in = "";
    		while(true){
    			in = reader.readLine();
    
    			//HANNON FOLLOWER CODE
    			if(in.equals("attack hannon follower")){
    				System.out.println("You: " + in + ".");
    				//npc name
    				cure = "Hannon Follower";
    				//npc stats
    				ehp = 200;
    				txp = ehp;
    				estr = 50;
    				eatt = 50;
    				edef = 50;
    				//calculations
    				cdmg = (estr * eatt)/25 - (def/2);
    				pdmg = ((str * att) * ppot)/25 - (edef/2);
    				elvl = (eatt + estr + edef)/150;
    				addcoin = randdmg.nextInt(5);
    				
    			//xp counter
    
    
    				while(hp > 0 & ehp > 0){
    
    					//computer attack =\
    					dmg = randdmg.nextInt(cdmg);
    					System.out.println("-");
    					System.out.println("" + cure + " (level: " + elvl + ") hits " + name + " for " + dmg + " damage!");
    					hp = hp - dmg;
    					System.out.println("" + name + " hp: " + hp + "");
    					Thread.sleep(1000);
    					
    					//player attack bro =\
    					dmg = randdmg.nextInt(pdmg);
    					System.out.println("-");
    					System.out.println("" + name + " hits " + cure + " (level: " + elvl + ") for " + dmg + " damage ");
    					ehp = ehp - dmg;
    					System.out.println("" + cure + " (level: " + elvl + ") hp: " + ehp + "");
    					Thread.sleep(1000);
    
    				}
    				//outcomes
    				if(hp > 1){
    					System.out.println("-------------");
    					System.out.println("" + name + " Wins the fight!");
    					xp = xp + txp;
    					System.out.println("You gain " + txp + " xp; you now have " + xp + " xp.");
    
    					coins = coins + addcoin;
    					System.out.println("You loot " + addcoin + " coins from " + cure + " (level: " + elvl + ").");
    					ppot = 1;
    				}
    				else if(ehp > 1){
    					System.out.println("" + cure + " (level: " + elvl + ") wins the fight");
    					System.out.println("You are injured and lose " + addcoin + " coins.");					
    					coins = coins - addcoin;
    					ppot = 1;
    					hp = hplvl;
    				}
    			}
    			//@@@@@@@@@@      END HANNON
    			//Mega Houghton code
    			if(in.equals("attack mega houghton")){
    				System.out.println("You: " + in + ".");
    				//npc name
    				cure = "Mega Houghton";
    				//npc stats
    			    ehp = 5000;
    			    txp = ehp;
    			    estr = 200;
    			    eatt = 300;
    			    edef = 150;
    				//calculations
    				cdmg = (estr * eatt)/25 - (def/2);
    				pdmg = ((str * att) * ppot)/25 - (edef/2);
    				elvl = (eatt + estr + edef)/150;
    				addcoin = randdmg.nextInt(3000);
    				
    			//xp counter
    
    
    				while(hp > 0 & ehp > 0){
    
    					//computer attack =\
    					dmg = randdmg.nextInt(cdmg);
    					System.out.println("-");
    					System.out.println("" + cure + " (level: " + elvl + ") hits " + name + " for " + dmg + " damage!");
    					hp = hp - dmg;
    					System.out.println("" + name + " hp: " + hp + "");
    					Thread.sleep(1000);
    					
    					//player attack bro =\
    					dmg = randdmg.nextInt(pdmg);
    					System.out.println("-");
    					System.out.println("" + name + " hits " + cure + " (level: " + elvl + ") for " + dmg + " damage ");
    					ehp = ehp - dmg;
    					System.out.println("" + cure + " (level: " + elvl + ") hp: " + ehp + "");
    					Thread.sleep(1000);
    
    				}
    				//outcomes
    				if(hp > 1){
    					System.out.println("-------------");
    					System.out.println("" + name + " Wins the fight!");
    					xp = xp + txp;
    					System.out.println("You gain " + txp + " xp; you now have " + xp + " xp.");
    
    					coins = coins + addcoin;
    					System.out.println("You loot " + addcoin + " coins from " + cure + " (level: " + elvl + ").");
    					ppot = 1;
    				}
    				else if(ehp > 1){
    					System.out.println("" + cure + " (level: " + elvl + ") wins the fight");
    					System.out.println("You are injured and lose " + addcoin + " coins.");	
    					hp = hplvl;
    					coins = coins - addcoin;
    					ppot = 1;
    				}
    			}
    			//@@@@@@@@@@      END Mega Houghton
    			//Cow code
    			if(in.equals("attack cow")){
    				System.out.println("You: " + in + ".");
    				//npc name
    				cure = "Cow";
    				//npc stats
    			    ehp = 25;
    			    txp = ehp;
    			    estr = 30;
    			    eatt = 30;
    			    edef = 30;
    				//calculations
    				cdmg = (estr * eatt)/25 - (def/2);
    				pdmg = ((str * att) * ppot)/25 - (edef/2);
    				elvl = (eatt + estr + edef)/15;
    				addcoin = randdmg.nextInt(2);
    				
    			//xp counter
    
    
    				while(hp > 0 & ehp > 0){
    
    					//computer attack =\
    					dmg = randdmg.nextInt(cdmg);
    					System.out.println("-");
    					System.out.println("" + cure + " (level: " + elvl + ") hits " + name + " for " + dmg + " damage!");
    					hp = hp - dmg;
    					System.out.println("" + name + " hp: " + hp + "");
    					Thread.sleep(1000);
    					
    					//player attack bro =\
    					dmg = randdmg.nextInt(pdmg);
    					System.out.println("-");
    					System.out.println("" + name + " hits " + cure + " (level: " + elvl + ") for " + dmg + " damage ");
    					ehp = ehp - dmg;
    					System.out.println("" + cure + " (level: " + elvl + ") hp: " + ehp + "");
    					Thread.sleep(1000);
    
    				}
    				//outcomes
    				if(hp > 1){
    					System.out.println("-------------");
    					System.out.println("" + name + " Wins the fight!");
    					xp = xp + txp;
    					System.out.println("You gain " + txp + " xp; you now have " + xp + " xp.");
    
    					coins = coins + addcoin;
    					System.out.println("You loot " + addcoin + " coins from " + cure + " (level: " + elvl + ").");
    					ppot = 1;
    				}
    				else if(ehp > 1){
    					System.out.println("" + cure + " (level: " + elvl + ") wins the fight");
    					System.out.println("You are injured and lose " + addcoin + " coins.");					
    					coins = coins - addcoin;
    					ppot = 1;
    					hp = hplvl;
    				}
    			}
    			//@@@@@@@@@@      END COW
    
    
    			//BEGIN LEVEL CODE
    			else if(in.equals("level even")){
    				tlvl = lvl;
    				System.out.println("-------------");
    				System.out.println("You exchange " + xp + " xp for " + xp/25 + " attack, strength and defense levels.");
    				att = att + xp/25;
    				str = str + xp/25;
    				def = def + xp/25;
    			    hplvl = hplvl + xp/25;
    				lvl = (att + str + def)/150;
    				System.out.println("Your level goes from " + tlvl + " to " + lvl + ".");
    				xp = 0;
    
    			}
    			else if(in.equals("level att")){
    				tlvl = lvl;
    				System.out.println("-------------");
    				System.out.println("You exchange " + xp + " xp for " + xp/10 + " attack levels.");
    				att = att + xp/10;
    				lvl = (att + str + def)/150;
    				System.out.println("Your level goes from " + tlvl + " to " + lvl + ".");
    				xp = 0;
    
    			}
    			else if(in.equals("level str")){
    				tlvl = lvl;
    				System.out.println("-------------");
    				System.out.println("You exchange " + xp + " xp for " + xp/10 + " strength levels.");
    				str = str + xp/10;
    				lvl = (att + str + def)/150;
    				System.out.println("Your level goes from " + tlvl + " to " + lvl + ".");
    				xp = 0;
    
    			}
    			else if(in.equals("level def")){
    				tlvl = lvl;
    				System.out.println("-------------");
    				System.out.println("You exchange " + xp + " xp for " + xp/10 + " strength levels.");
    				str = str + xp/10;
    				lvl = (att + str + def)/150;
    				System.out.println("Your level goes from " + tlvl + " to " + lvl + ".");
    				xp = 0;
    
    			}
    			else if(in.equals("level")){
    				System.out.println("-------------");
    				System.out.println("Level shop:");	
    				System.out.println("level even: exchanges xp evenly");
    				System.out.println("level att: exchanges xp to attack");
    				System.out.println("level str: exchanges xp to strength");
    				System.out.println("level def: exchanges xp to defense");
    			}
    			//END LEVEL CODE
    			else if(in.equals("stats")){
    				System.out.println("-------------");
    				System.out.println("Current Stats:");	
    				System.out.println("Level: " + lvl + "");
    				System.out.println("Attack: " + att + "");
    				System.out.println("Strength: " + str + "");
    				System.out.println("Defense: " + def + "");
    				System.out.println("Hitpoints: " + hplvl + "");
    			}
    			else if(in.equals("inventory") || in.equals("inv")){
    				System.out.println("-------------");
    				System.out.println("Inventory:");	
    				System.out.println("Slot 1: " + slot1 + ".");
    				System.out.println("Slot 2: " + slot2 + ".");
    				System.out.println("Slot 3: " + slot3 + ".");
    				System.out.println("Slot 4: " + slot4 + ".");
    				System.out.println("Slot 5: " + slot5 + ".");
    				System.out.println("Food Slot: " + food + ".");
    				System.out.println("Coin pouch: " + coins + ".");
    			}
    			else if(in.equals("shop")){
    				System.out.println("-------------");
    				System.out.println("Shop Owner Marissa:");
    				Thread.sleep(500);
    				System.out.println("Welcome to the Genital store!");
    				Thread.sleep(250);
    				System.out.println("To buy an item, just type the slot number.");
    				System.out.println("Item: Food (cost 2)");
    				System.out.println("Item 1: One fitty one rum (cost 20)");
    				
    			}
    			//begin item "food"
    			else if(in.equals("buy food")){
    				cost = 2;
    				if(coins >= cost){
    					System.out.println("You buy one food.");
    					food = food + 1;
    					coins = coins - cost;
    				}
    					else if(coins < cost){
    						System.out.println("Not enough coins");
    					}
    				
    				}
    			//end item 
    			//begin item "151"
    			else if(in.equals("buy 1")){
    				cost = 20;
    				if(coins >= cost){
    					System.out.println("You buy one shot of one fitty one rum.");
    					slot1 = "151 rum";
    					coins = coins - cost;
    				}
    					else if(coins < cost){
    						System.out.println("Not enough coins");
    					}
    				
    				}
    			//end item 	
    			//use items section
    			else if(in.equals("heal")){
    				if(hp <= hplvl & food >= 1){
    					hp = hp + 25;
    					food = food - 1;
    					System.out.println("-------------");
    				System.out.println("You heal for 25 hp.");	
    				} else if(hp >= hplvl & food >= 1){
    					System.out.println("-------------");
    					System.out.println("You are already at full or over full health.");
    				} else {
    					System.out.println("-------------");
    					System.out.println("You have no food. Go to Riss's shop to buy some.");
    				}
    
    	}
    			else if(in.equals("slot1")){
    				if(slot1 == "151 rum"){
    					ppot = 2;
    					System.out.println("Used 151 rum.");
    					System.out.println("The effectiveness of your stats has increased temporarily.");
    					slot1 = "";				
    				}
    			}
    			else if(in.equals("examine")){
    				System.out.println("-------------");
    	            System.out.println("In your area");
                System.out.println("Cow (level 6 (wild))");
                System.out.println("Hannon Follower (level 1)");
                System.out.println("In your area");
                System.out.println("In your area");
                System.out.println("In your area");
    
    			}
    			else if(in.equals("dildo")){
    				System.out.println("-------------");
    				System.out.println("Debugging mode entered.");
    				att = 9999;
    				str = 9999;
    				def = 9999;
    			    hplvl = 9999;
    				lvl = (att + str + def)/150;
    				System.out.println("Your level goes from " + tlvl + " to " + lvl + ".");
    
    			}
    			//end use item section
    
    			
    }//end of while loop =)
    }
    }

  2. #2
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default

    Try printing the value of the argument you are using when you get the random number:

    Java Code:
    //computer attack =\
    System.out.println("Calling nextInt() with cdmg=" + cdmg);
    dmg = randdmg.nextInt(cdmg);
    If this shows that cdmg is not positive go back through your code to see where you assigned it a nonpositive value.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by Areptom View Post
    the damage formula seems to be glitched, causing an error.
    What is the glitch? What is the error?

    I doubt anyone is going to wade through a gazillion lines of code without some information from you as to what they should be looking for.

  4. #4
    Areptom is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    I fixed my problem, by just adding a
    Java Code:
    			    if(def/2 > (estr * eatt)/25){
    			    	cdmg = 1;
    			    }
    			    if(edef/2 > (str * att)/25){
    			    	pdmg = 1;
    			    }
    thanks pbrockway2, when i start cleaning up my code i might try it ;)

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You may want to take advantage of oop instead of just putting everything in the main method.

  6. #6
    Areptom is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    You may want to take advantage of oop instead of just putting everything in the main method.
    Haha, ik... its my horribly inefficient programming showing =\

    At first the game was too simple for it to even matter, now i probably should

  7. #7
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Nothing is too simple to utilize OOP. OOP allows for you to expand without messing with previous code.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. convert negative int to positive
    By aconti in forum New To Java
    Replies: 4
    Last Post: 05-30-2011, 10:43 AM
  2. Negative,Positive and Zero
    By dipowo in forum New To Java
    Replies: 2
    Last Post: 04-04-2011, 06:49 AM
  3. Return positive values only
    By DomBrown in forum New To Java
    Replies: 14
    Last Post: 03-31-2011, 08:48 PM
  4. Sum positive numbers using 10 inputs from user
    By pvictory1 in forum New To Java
    Replies: 15
    Last Post: 10-10-2010, 02:30 AM
  5. Positive Divisor of int
    By starchildren3317 in forum New To Java
    Replies: 16
    Last Post: 02-20-2009, 04:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •