Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class sercomtel {
- // armas
- static String[] weaponname = {"Wooden Stick","Dagger", "Silver Sceptre", "Golden Sword","Magic Sword","Sword of Gods","Sceptre","Furry Club"};
- static int[] weaponatk = {1,2,3,4,5,7,6,3};
- static int selecteditem = 0;
- // monstros
- static String[] nomes = {"Troll", "Rat", "Worm","Bat","Behemoth"};
- static int[] str = {10,7,5,5,15}; // força
- static int[] hps = {10,7,5,3,20};
- static int[] exps = {25,5,5,5,60};
- static int[] loot$ = {25,15,10,5,60};
- // mover
- static boolean up = true;
- static boolean left = true;
- static boolean down = true;
- static boolean right = true;
- // luta
- static int targetmaxhp = 0;
- static int targethp = 0;
- // char
- static int posx = 0;
- static int posy = 0;
- static int levelxp = 20;
- static int baseat = 2;
- static int playerattack = baseat;
- static int exp = 0;
- static int level = 1;
- static int potions = 3;
- static int target = 0;
- static int money = 0;
- static int playerhp = 0;
- static int playermaxhp = 0;
- static int heal = 50+((int)Math.floor(Math.random() * 100));
- // alguns bools
- static boolean battle = false;
- static boolean npc = false;
- // npc
- static int preco = 100;
- static String nome;
- public static void keepMove(String dir){
- int result = (int) Math.floor(Math.random()*100);
- if (result>80) {
- target = (int)Math.floor(Math.random()*nomes.length);
- battle = true;
- targetmaxhp = hps[target];
- targethp = targetmaxhp;
- playerattack = baseat+level+weaponatk[selecteditem];
- System.out.println("A wild "+nomes[target]+" appeared! ["+targethp+"/"+targetmaxhp+"]");
- } else if (result<3) {
- npc = true;
- System.out.println("You have found a person who sells potions for $"+preco+" each. <Buy> or <not>?");
- } else if (result>77 && result<=80) {
- int premmyitem = (int)Math.floor(Math.random()*weaponname.length);
- if(weaponatk[premmyitem]>weaponatk[selecteditem]){
- System.out.println("You have found an item! ("+weaponname[premmyitem]+": Atk +"+weaponatk[premmyitem]+")");
- selecteditem = premmyitem;
- playerattack = playerattack + weaponatk[premmyitem];
- } else {
- if(premmyitem==selecteditem){
- System.out.println("You have found an item ("+weaponname[premmyitem]+"), but you have this item already.");
- } else {
- System.out.println("You have found an item ("+weaponname[premmyitem]+"), but you have a better item, which is the "+weaponname[selecteditem]+".");
- }
- idler(nome);
- }
- } else if (result > 50 && result <= 60){
- System.out.println("Sorry, it seems that there is something blocking the way. Could not move "+dir+"way.");
- if (dir.equals("up")){
- up = false;
- posy++;
- } else if (dir.equals("down")){
- down = false;
- posy--;
- } else if (dir.equals("left")){
- left = false;
- posx--;
- } else if (dir.equals("right")){
- right = false;
- posx++;
- }
- } else {
- left = true;
- up = true;
- right = true;
- down = true;
- }
- }
- public static void moveDir(String dir){
- String finalizar = "Sorry, it seems that there is something blocking the way. Could not move "+dir+"way.";
- // checa se pode andar pra direção , se n puder volta a coordenada anterior
- if (dir.equals("up")) {
- if (up==true){
- keepMove("up");
- } else {
- posy++;
- System.out.println(finalizar);
- }
- } else if (dir.equals("down")) {
- if (down==true){
- keepMove("down");
- } else {
- posy--;
- System.out.println(finalizar);
- }
- } else if (dir.equals("left")) {
- if (left==true){
- keepMove("left");
- } else {
- posx++;
- System.out.println(finalizar);
- }
- } else if (dir.equals("right")) {
- if (right==true){
- keepMove("right");
- } else {
- posx--;
- System.out.println(finalizar);
- }
- }
- }
- static void tryagain(){
- if ((level*levelxp - exp) < 1) {
- level++;
- System.out.println("You got another level! You are now level "+(level)+"!");
- tryagain();
- }
- }
- public static void idler(String nome){
- if (playerhp > 0) {
- playermaxhp = 100 + (level*20);
- Scanner direc = new Scanner(System.in);
- String dir = direc.nextLine();
- if (npc == false){
- if (battle == false){
- if ("up".equals(dir)){
- System.out.println("You just walked upway.");
- posy--;
- moveDir("up");
- } else if ("potion".equals(dir)){
- if (potions>0){
- potions--;
- playerhp = playerhp + heal;
- if (playerhp > playermaxhp) {
- playerhp = playermaxhp;
- }
- System.out.println("You just used a potion which healed "+heal+" hitpoints.");
- } else {
- System.out.println("You do not have potions anymore.");
- }
- idler(nome);
- } else if ("weapon".equals(dir)){
- System.out.println("Your actual weapon is: "+weaponname[selecteditem]+".");
- } else if ("level".equals(dir)){
- System.out.println("You are level "+level+".");
- } else if ("exp".equals(dir)){
- System.out.println("You have "+exp+" experience points. "+(level*levelxp - exp)+" exp points left for the next level.");
- } else if ("hp".equals(dir)){
- System.out.println("HP: ["+playerhp+"/"+playermaxhp+"]");
- } else if ("right".equals(dir)){
- System.out.println("You just walked rightway.");
- posx--;
- moveDir("right");
- } else if ("left".equals(dir)){
- System.out.println("You just walked leftway.");
- posx++;
- moveDir("left");
- } else if ("strenght".equals(dir) || "op".equals(dir)){
- System.out.println("Your offensive power: "+(baseat+level+weaponatk[selecteditem])+" [Level:+"+(baseat+level)+"op/Weapon:+"+weaponatk[selecteditem]+"op]");
- posx++;
- } else if ("down".equals(dir)){
- System.out.println("You just walked downway.");
- posy++;
- moveDir("down");
- } else if ("money".equals(dir)){
- System.out.println("You have $"+money+".");
- } else if ("pos".equals(dir)){
- System.out.println("Your position is: [x:"+posx+"|y:"+posy+"]");
- }
- idler(nome);
- } else {
- if ("flee".equals(dir)){
- int chance = (int)Math.floor(Math.random() * 100);
- if (chance<=80){
- battle=false;
- System.out.println("You just got away safely.");
- } else {
- System.out.println(nomes[target]+" don\'t let you go!");
- if(Math.floor((Math.random()*100))<10){
- System.out.println("["+nomes[target].toUpperCase()+"] misses the attack.");
- } else {
- int dmage = (int)Math.floor((Math.random()*str[target]));
- playerhp = playerhp - dmage;
- System.out.println("["+nome.toUpperCase()+"] Takes "+nome+" -"+dmage+" hitpoints.");
- }
- if (playerhp > 0){
- System.out.println(nomes[target]+"\'s HP: ["+targethp+"/"+targetmaxhp+"]");
- System.out.println(nome+"\'s HP: ["+playerhp+"/"+playermaxhp+"]");
- } else {
- System.out.println("You died.");
- }
- }
- idler(nome);
- }
- // usar poção na luta
- if ("potion".equals(dir)){
- if (potions>0){
- playerhp = playerhp + heal;
- potions--;
- playerhp = playerhp + heal;
- if (playerhp > playermaxhp) {
- playerhp = playermaxhp;
- }
- System.out.println("You just used a potion which healed "+heal+" hitpoints.");
- } else {
- System.out.println("You do not have potions anymore.");
- }
- }
- // atacar na luta
- if ("attack".equals(dir)){
- if(Math.floor((Math.random()*100))<10){
- System.out.println("["+nomes[target].toUpperCase()+"] misses the attack.");
- } else {
- int dmage = (int)Math.floor((Math.random()*str[target]));
- playerhp = playerhp - dmage;
- System.out.println("["+nomes[target].toUpperCase()+"] Takes "+nome+" -"+dmage+" hitpoints.");
- }
- // chance de errar atk
- if(playerhp > 0){
- if(Math.floor((Math.random()*100))<10){
- System.out.println("["+nome.toUpperCase()+"] misses the attack.");
- } else {
- int damage = (int)Math.floor((Math.random()*playerattack));
- targethp = targethp - damage;
- System.out.println("["+nome.toUpperCase()+"] Takes "+nomes[target]+" -"+damage+" hitpoints!");
- }
- if (targethp>0){
- System.out.println(nomes[target]+"\'s HP: ["+targethp+"/"+targetmaxhp+"]");
- System.out.println(nome+"\'s HP: ["+playerhp+"/"+playermaxhp+"]");
- idler(nome);
- } else {
- System.out.println("Enemy defeated!");
- exp = exp + exps[target];
- // checa se o jogador upou
- if ((level*levelxp - exp) < 1) {
- System.out.println("You won "+exps[target]+" exp points and leveled up!");
- exp = exp - level*levelxp;
- level++;
- playerattack = baseat+level;
- tryagain();
- System.out.println("You are now level "+(level)+"!");
- } else {
- System.out.println("You won "+exps[target]+" exp points. "+(level*levelxp - exp)+" exp points for level up.");
- }
- int prize = (int)Math.floor(Math.random()*(loot$[target]));
- System.out.println("You got $"+prize+" from "+nomes[target]+"\'s loot.");
- money = money + prize;
- battle = false;
- idler(nome);
- }
- } else {
- System.out.println("You died.");
- }
- } /* aqui acaba o ataque */ else {
- idler(nome);
- }
- }
- } else {
- // se npc for true
- String prox = dir;
- // se falar buy
- if("buy".equals(prox)){
- if (money>preco){
- money=money-preco;
- potions++;
- System.out.println("You just bought a potion and the man got away in the path of the shadows.");
- npc = false;
- } else {
- System.out.println("You just don\'t have enought money, the man got away.");
- npc = false;
- }
- // se falar not
- } else if ("not".equals(prox)){
- System.out.println("You refuse to buy anything and the man gets away in the path of the shadows.");
- npc = false;
- }
- idler(nome);
- }
- direc.close();
- }
- }
- public static void main(String[] args){
- System.out.println("Welcome to your worst nightmare. Tell me your name, little piece of soul.");
- Scanner objeto = new Scanner(System.in);
- String prox = objeto.nextLine();
- nome = prox;
- System.out.println("So it all began, "+nome+".");
- playermaxhp = 100 + (level*20);
- playerhp = playermaxhp;
- idler(nome);
- objeto.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement