
-----------------------------------
Tat
Wed Feb 04, 2004 9:02 pm

Text Based RPG(wacky kind)
-----------------------------------
/*Tat Ho
Me=Newb in Java 
this program wasn't fully finished but finished enough to play around with
this program was also done for my java class
save it as thRPGMain.java
u also need KeyboardReader
which i will post after this
 *PRPG Project*/
class CharacterType
{
	String name;
	KeyboardReader reader=new KeyboardReader();
	int money, hp, mp, strength, mstrength, choice;
	boolean isTurn;
	Special item;
	int curAtt;
	
	CharacterType()
	{
		name="Character";
		money=100;
	}
	void displayInfo()
	{
		System.out.println("Name: " + name);
		System.out.println("Money: " + money);
		System.out.println("Health: " + hp);
		System.out.println("Mana: " + mp);
		System.out.println("Strength: " + strength);
		System.out.println("MStrength: " + mstrength);
	}
	int attack()
	{
		curAtt=(int)Math.floor(Math.random()*strength);
		return curAtt;
	}
	int useSpecial()
	{
		if(item instanceof Weapon){
			curAtt=(int)Math.floor(Math.random()*(strength+item.strength));
			return curAtt;
		}else{
			if(mp>=((Spell)item).manacost){
				mp-=((Spell)item).manacost;
				curAtt=(int)Math.floor(Math.random()*(mstrength+item.strength));
				return curAtt;
			}else{
				System.out.print("Not enough mana for that spell, therefore you will only use your fist!!!");
				curAtt=(int)Math.floor(Math.random()*(strength));
				return curAtt;
			}
		}
	}
	boolean isDead()
	{
		if(hp0 || choiceboss.hp){
			System.out.println();
			player.wins(900);
			boss.loses();
			player.displayInfo();
		}else if(boss.hp>player.hp){
			System.out.println();
			boss.wins(0);
			player.loses();
			boss.displayInfo();
		}
	}

	void run()
	{
		do{
		boss.hp=200;
		chooseCharacter();
		shop();
		fight();
		again=reader.readChar("Want to play again, enter y or Y to do so");
		}while(again=='y' || again=='Y');
	}
}

class thRPGMain
{
	static Fight fight=new Fight();
	public static void main(String args[])
	{
		fight.run();
	}
}

-----------------------------------
Tat
Wed Feb 04, 2004 9:03 pm


-----------------------------------
/*you need to save it as KeyboardReader.java in the same folder with the other file
*/ 

//Copyright Martin Osborne and Ken Lambert 1998-2001 
//All rights reserved 



import java.io.*; 

/** 
* The class KeyboardReader contains input methods for terminal I/O. Type-specific 
* methods read characters, integers, doubles, and strings. Another 
* method pauses output and waits for the user to press the enter key 
* to continue. Examples: 
* 

 *

 *   KeyboardReader reader = new KeyboardReader();

 *   char letter = reader.readChar  ("Enter a letter: ");

 *   double    d = reader.readDouble("Enter a real number: ");

 *   int       i = reader.readInt   ("Enter an integer: ");

 *   String name = reader.readLine  ("Enter your full name: ");

 *   reader.pause();

 *

 * 

*/ 

public class KeyboardReader{ 

private InputStreamReader reader; 
private BufferedReader buffer; 

public KeyboardReader(){ 
reader = new InputStreamReader (System.in); 
buffer = new BufferedReader (reader); 
} 

/** 
* Used with non-GUI applications to prevents a "fly-by" 
* disappearance of the terminal window 
* in some environments by pausing execution until the user 
* presses the Enter key. Usage: reader.pause(); 
*/ 
public void pause(){ 
System.out.print ("\nPress Enter to continue . . . "); 
try { 
buffer.readLine(); 
}catch (Exception e){ 
System.exit(0); 
} 
} 

/** 
* Prompts the user and waits for integer input. Throws an exception 
* if the input doesn't represent an integer. Returns the integer entered. 
* @param prompt the prompt to the user. 
*/ 
public int readInt(String prompt){ 
int value = 0; 
String s = ""; 
System.out.print (prompt); 
try { 
s = (buffer.readLine()).trim(); 
value = (new Integer(s)).intValue(); 
}catch (Exception e){ 
System.out.println 
("\n\nError: your input doesn't represent a valid integer value\n"); 
pause(); 
System.exit(0); 
} 
return value; 
} 

/** 
* Waits for integer input without prompting the user. Throws an exception 
* if the input doesn't represent an integer. Returns the integer entered. 
*/ 
public int readInt(){ 
return readInt (""); 
} 

/** 
* Prompts the user and waits for double input. Throws an exception 
* if the input doesn't represent a double. Returns the double entered. 
* @param prompt the prompt to the user. 
*/ 
public double readDouble(String prompt){ 
double value = 0; 
String s = ""; 
System.out.print (prompt); 
try { 
s = (buffer.readLine()).trim(); 
value = (new Double(s)).doubleValue(); 
}catch (Exception e){ 
System.out.println 
("\n\nError: your input doesn't represent a valid double value\n"); 
pause(); 
System.exit(0); 
} 
return value; 
} 

/** 
* Waits for double input without prompting the user. Throws an exception 
* if the input doesn't represent a double. Returns the double entered. 
*/ 
public double readDouble(){ 
return readDouble(""); 
} 

/** 
* Prompts the user and waits for character input. Returns the char entered. 
* @param prompt the prompt to the user. 
*/ 
public char readChar(String prompt){ 
int value = 0; 
String s = ""; 
System.out.print (prompt); 
try { 
s = buffer.readLine(); 
s += "?"; 
value = s.charAt(0); 
}catch (Exception e){ 
System.out.println 
("\n\nError in method readChar:\n" + e.toString() + "\n"); 
pause(); 
System.exit(0); 
} 
return (char)value; 
} 

/** 
* Waits for character input without prompting the user. Returns the char entered. 
*/ 
public char readChar(){ 
return readChar(""); 
} 

/** 
* Prompts the user and waits for string input. Returns the entire line 
* of text entered. 
* @param prompt the prompt to the user. 
*/ 
public String readLine(String prompt){ 
String value = ""; 
System.out.print (prompt); 
try { 
value = buffer.readLine(); 
}catch (Exception e){ 
System.out.println 
("\n\nError in Console.readLine\n" + e.toString() + "\n"); 
pause(); 
System.exit(0); 
} 
return value; 
} 

/** 
* Waits for string input without prompting the user. Returns the entire line 
* of text entered. 
*/ 
public String readLine(){ 
return readLine(""); 
} 
}

-----------------------------------
shorthair
Wed Feb 04, 2004 9:06 pm


-----------------------------------
How long have you been coding , this is quality stuff especially cause its writtin in such a unique language ,well done your doing awsome keep up the amazing code

-----------------------------------
Tat
Wed Feb 04, 2004 9:13 pm


-----------------------------------
ty for ur complement
this is only um....text based stuff
i took java for half a year already 1 period a day
now 2 periods a day in ap java(starting this week)

-----------------------------------
Tony
Wed Feb 04, 2004 11:12 pm


-----------------------------------
I'm supposedly taking java in AP CS, but things aren't working out too great :roll: I dont know much Java... I have no clue how I'm gonna do CCC this year and I'm really hoping that AP exam is multiple choice :lol:
