Tuesday, 10 April 2012

WordRpg Working v1

ok the colour code is, yellow is Home.java ,Green is Battle.java and red is Varaibles.java

package client;


import java.util.Scanner;
public class Home {


public static void main(String[] args) {
String Name;
// variables, high value.
MainMenu();
System.out.println("Please type in your name");
Scanner input = new Scanner(System.in);
Name = input.next();
System.out.println("Hello " + Name);
Battle ShowBattle = new Battle();
// HOMETOWN.
String HomeCommand;
Scanner input1 = new Scanner(System.in);
boolean Homeloop = false;
while (Homeloop == false) {
System.out.println("Welcome Home " + Name);
System.out.println("Your level is: " + ShowBattle.UseVariables.getLevel());
System.out.println("Your Health is: " + ShowBattle.UseVariables.getHealth() + "/" + ShowBattle.UseVariables.getMaxHealth());
System.out.println("Your Current exp is: " + ShowBattle.UseVariables.getExp());
System.out.println("exp need for leveling up: " + ShowBattle.UseVariables.getExpNeed());
System.out.println("Your Current Gold is: " + ShowBattle.UseVariables.getGold());
System.out.println("This is HomeTown, Type in, 'battle', 'heal', 'blacksmith' and 'quit'");
HomeCommand = input1.next();
// HomeTown Command
if (HomeCommand.equalsIgnoreCase("battle")) {
System.out.println("You are in Fight, To begin Fight, type in 'fight'");
if (ShowBattle.UseVariables.getLevel()<=1) {
ShowBattle.UseVariables.SetEnemyName("Man");
}
else if (ShowBattle.UseVariables.getLevel()<=2) {
ShowBattle.UseVariables.SetEnemyName("Guard");
}
else if (ShowBattle.UseVariables.getLevel()<=3) {
ShowBattle.UseVariables.SetEnemyName("LightGuard");
}
else if (ShowBattle.UseVariables.getLevel()<=4) {
ShowBattle.UseVariables.SetEnemyName("HeavyGuard");
}
else if (ShowBattle.UseVariables.getLevel()<=5) {
ShowBattle.UseVariables.SetEnemyName("Palidin");
}
else if (ShowBattle.UseVariables.getLevel()<=6) {
ShowBattle.UseVariables.SetEnemyName("Knight");
}
else if (ShowBattle.UseVariables.getLevel()<=7) {
ShowBattle.UseVariables.SetEnemyName("Goblin");
}
else if (ShowBattle.UseVariables.getLevel()<=8) {
ShowBattle.UseVariables.SetEnemyName("Orc");
}
else if (ShowBattle.UseVariables.getLevel()<=9) {
ShowBattle.UseVariables.SetEnemyName("Troll");
}
else if (ShowBattle.UseVariables.getLevel()<=10) {
ShowBattle.UseVariables.SetEnemyName("DeathNight");
}
else if (ShowBattle.UseVariables.getLevel()>=11) {
ShowBattle.UseVariables.SetEnemyName("DeathKing");
}
ShowBattle.BattleCommence();
}
else if (HomeCommand.equalsIgnoreCase("blacksmith")) {
System.out.println("Display blacksmith class");
boolean BlackSmithloop = false;
while (BlackSmithloop == false) {
String BlackSmithOption;
// if statement for blacksmith.
Scanner input11 = new Scanner(System.in);
System.out.println("Welcome to BlackSmith");
System.out.println("Type in 'upgrade' or 'back'");
BlackSmithOption = input11.next();
if (BlackSmithOption.equalsIgnoreCase("upgrade")) {
System.out.println("Upgrading");
int Price = 0;
System.out.println("Would you like to upgrade your weapon Skill.");
if (ShowBattle.UseVariables.getWeaponLvl()<=0) {
Price = 50;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=1) {
Price = 100;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=2) {
Price = 200;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=3) {
Price = 400;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=4) {
Price = 800;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=5) {
Price = 1600;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=6) {
Price = 3200;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=7) {
Price = 6400;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=8) {
Price = 12800;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=9) {
Price = 25600;
}
else if (ShowBattle.UseVariables.getWeaponLvl()<=10) {
Price = 51200;
}
else {
System.out.println("Sorry you cant upgrad anymore...");
BlackSmithloop = true;
}
System.out.println("it will cost you " + Price + " Gold, Type in 'yes' or 'no'");
boolean Priceloop = false;
while (Priceloop == false) {
String Answer2;
Scanner input2 = new Scanner(System.in);
Answer2 = input2.next();
if (Answer2.equalsIgnoreCase("yes")) {
if (ShowBattle.UseVariables.getGold() >= Price) {
ShowBattle.UseVariables.SetGold(ShowBattle.UseVariables.getGold()-Price);
Priceloop = true;
}
else if (ShowBattle.UseVariables.getGold() < Price) {
System.out.println("Sorry you can't afford that...");
Priceloop = true;
}
else {
System.out.println("Unkown Command");
}
}
}
}
else if (BlackSmithOption.equalsIgnoreCase("back")) {
System.out.println("You leave store");
BlackSmithloop = true;
}
else {
System.out.println("Unkown Command");
}
}
}
else if (HomeCommand.equalsIgnoreCase("heal")) {
System.out.println("You are HEALED");
ShowBattle.UseVariables.SetHealth(ShowBattle.UseVariables.getMaxHealth());
}
else if (HomeCommand.equalsIgnoreCase("quit")) {
System.out.println("You are quiting... Bye");
Homeloop = true;
}
else {
System.out.println("Unkown Command");
}
} // End of boolean
System.exit(0);
}
public static void MainMenu () {
boolean MainMenuloop = false;
while (MainMenuloop == false) {
System.out.println("Welcome To RPG");
System.out.println("Would you like to play this Game, 'yes' or 'no'");
Scanner input1 = new Scanner(System.in);
String AnswerMain;
AnswerMain = input1.next();
if (AnswerMain.equalsIgnoreCase("yes")) {
MainMenuloop = true;
}
else if (AnswerMain.equalsIgnoreCase("no")) {
System.out.println("You are Leaving Game");
System.exit(0);
}
else {
System.out.println("Unkown Command");
}
}

}


}
/// that was main class.

package client;


import java.util.Random;
import java.util.Scanner;


public class Battle {
// put stuff in here
Variables UseVariables = new Variables();
public Battle() {

}
// put other publics in here
public void BattleCommence() {
boolean Battleloop = false;
while (Battleloop == false) {
UseVariables.SetEnemyLevel(UseVariables.getLevel());
UseVariables.SetEnemyHealth(UseVariables.getEnemyLevel()*9);
UseVariables.SetEnemyDamage(UseVariables.getMinDamage()+UseVariables.getMaxHealth()-UseVariables.getLevel()-5);
String BattleOption;
// This is where the if statement goes.
Scanner input = new Scanner(System.in);
BattleOption = input.next();
if (BattleOption.equalsIgnoreCase("fight")) {
System.out.println("Fight Commands, 'hit' and 'flee'");
System.out.println("Name of Monster is: " + UseVariables.getEnemyName());
System.out.println("Enemy level: " + UseVariables.getEnemyLevel());
boolean Hitloop = false;
while (Hitloop == false) {
BattleOption = input.next();
System.out.println("Your Health is: " + UseVariables.getHealth());
System.out.println("Enemy Health is: " + UseVariables.getEnemyHealth());
if (BattleOption.equalsIgnoreCase("hit")) {
System.out.println("ShowDamage Taken off Enemy");
Random randomGenerator = new Random();
UseVariables.SetDealDamageOff(UseVariables.getMinDamage()+randomGenerator.nextInt(UseVariables.getMaxDamage()));
UseVariables.SetEnemyHealth(UseVariables.getEnemyHealth()-UseVariables.getDealDamageOff());
System.out.println("You Hit: "+UseVariables.getDealDamageOff() + " Enemy Health is: " + UseVariables.getEnemyHealth());
if  (UseVariables.getEnemyHealth()<= 0) {
System.out.println("You have Kill the Enemy");
UseVariables.SetExp(UseVariables.getExp() + UseVariables.getEnemyLevel()*10);
Random randomGenerator2 = new Random();
int RandomGold;
RandomGold = 1+randomGenerator2.nextInt(UseVariables.getLevel()*5);
UseVariables.SetGold(UseVariables.getGold()+RandomGold);
System.out.println("You have received exp * your level...");
System.out.println("You have Looted " + RandomGold + " Gold");
System.out.println("Current exp " + UseVariables.getExp());
System.out.println("Current Gold " + UseVariables.getGold());

if (UseVariables.getExp() >= UseVariables.getExpNeed()) {
UseVariables.SetLevel(+1);
UseVariables.SetMaxHealth(UseVariables.getLevel()*10);
UseVariables.SetHealth(UseVariables.getMaxHealth());
UseVariables.SetMinDamage(UseVariables.getLevel());
UseVariables.SetMaxDamage(UseVariables.getMaxDamage()+UseVariables.getMaxHealth()-UseVariables.getLevel()-5+UseVariables.getWeaponLvl());
UseVariables.SetExp(0);
UseVariables.SetExpNeed(UseVariables.getLevel()*100+UseVariables.getMaxHealth());
System.out.println("you level up");
}
Hitloop = true;
}
if (UseVariables.getEnemyHealth()>=1) {
System.out.println("Enemy's turn now");
Random randomGenerator1 = new Random();
UseVariables.SetDealDamageOff(UseVariables.getEnemyLevel()+randomGenerator1.nextInt(UseVariables.getEnemyDamage()));
UseVariables.SetHealth(UseVariables.getHealth()-UseVariables.getDealDamageOff());
System.out.println("Enemy Hit: "+UseVariables.getDealDamageOff() + " Your Health is: " + UseVariables.getHealth());
if (UseVariables.getHealth()<= 0) {
System.out.println("You have died.");
UseVariables.SetHealth(0);
System.out.println("Please go back and heal");
Hitloop = true;
}
}

}
else if (BattleOption.equalsIgnoreCase("flee")) {
Hitloop = true;
}
else {
System.out.println("Unkown Command");
}
}
}
else if (BattleOption.equalsIgnoreCase("back")) {
System.out.println("You leave battle");
Battleloop = true;
}
else {
System.out.println("Unkown Command");
}
Battleloop = true;

}
}


}
// that was battle class
package client;

public class Variables {
private int Level = 1;
private int MaxHealth = Level*11;
private int Health = MaxHealth;
private int MinDamage = Level;
private int MaxDamage = MinDamage+MaxHealth-Level-3;
private int Exp;
private int ExpNeed = Level*100+MaxDamage;
private int EnemyLevel = Level;
private int EnemyHealth = EnemyLevel*9;
private int EnemyDamage = MinDamage+MaxHealth-Level-5;
private int DealDamageOff;
private String EnemyName;
private int WeaponLvl;
private int Gold;
public Variables () {
}
public void SetLevel (int NameLevel) {
Level = NameLevel;
}
public int getLevel () {
return Level;
} // new line
public void SetMaxHealth (int NameMaxHealth) {
MaxHealth = NameMaxHealth;
}
public int getMaxHealth () {
return MaxHealth;
} // new line
public void SetHealth (int NameHealth) {
Health = NameHealth;
}
public int getHealth () {
return Health;
} // new line
public void SetMinDamage (int NameMinDamage) {
MinDamage = NameMinDamage;
}
public int getMinDamage () {
return MinDamage;
} // new line
public void SetMaxDamage (int NameMaxDamage) {
MaxDamage = NameMaxDamage;
}
public int getMaxDamage () {
return MaxDamage;
} // new line
public void SetDealDamageOff (int NameDealDamageOff) {
DealDamageOff = NameDealDamageOff;
}
public int getDealDamageOff () {
return DealDamageOff;
} // new line
public void SetEnemyDamage (int NameEnemyDamage) {
EnemyDamage = NameEnemyDamage;
}
public int getEnemyDamage () {
return EnemyDamage;
} // new line
public void SetEnemyLevel (int NameEnemyLevel) {
EnemyLevel = NameEnemyLevel;
}
public int getEnemyLevel () {
return EnemyLevel;
} // new line
public void SetEnemyHealth (int NameEnemyHealth) {
EnemyHealth = NameEnemyHealth;
}
public int getEnemyHealth () {
return EnemyHealth;
} // new line
public void SetExp (int NameExp) {
Exp = NameExp;
}
public int getExp () {
return Exp;
} // new line
public void SetExpNeed (int NameExpNeed) {
ExpNeed = NameExpNeed;
}
public int getExpNeed () {
return ExpNeed;
} // new line
public void SetEnemyName (String NameEnemyName) {
EnemyName = NameEnemyName;
}
public String getEnemyName () {
return EnemyName;
} // new line
public void SetWeaponLvl (int NameWeaponLvl) {
WeaponLvl = NameWeaponLvl;
}
public int getWeaponLvl () {
return WeaponLvl;
} // new line
public void SetGold (int NameGold) {
Gold = NameGold;
}
public int getGold () {
return Gold;
} // new line
}
// that was where the variables are kept.

all rights reserved to Samuel Grahame (c) copyright of wordrpg.




1 comment:

  1. it all works as far as i know it, post if you find errors

    ReplyDelete