Advertisement
Guest User

je l

a guest
Oct 3rd, 2012
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class sercomtel {
  4.  
  5.    
  6. // armas
  7.     static String[] weaponname = {"Wooden Stick","Dagger", "Silver Sceptre", "Golden Sword","Magic Sword","Sword of Gods","Sceptre","Furry Club"};
  8.     static int[] weaponatk = {1,2,3,4,5,7,6,3};
  9.     static int selecteditem = 0;
  10.  
  11. // monstros
  12.     static String[] nomes = {"Troll", "Rat", "Worm","Bat","Behemoth"};
  13.     static int[] str  = {10,7,5,5,15}; // força
  14.     static int[] hps  = {10,7,5,3,20};
  15.     static int[] exps  = {25,5,5,5,60};
  16.     static int[] loot$  = {25,15,10,5,60};
  17.  
  18. // mover
  19.     static boolean up = true;
  20.     static boolean left = true;
  21.     static boolean down = true;
  22.     static boolean right = true;
  23.    
  24.    
  25. // luta
  26.     static int targetmaxhp = 0;
  27.     static int targethp = 0;
  28.  
  29. // char
  30.     static int posx = 0;
  31.     static int posy = 0;
  32.     static int levelxp  = 20;
  33.     static int baseat = 2;
  34.     static int playerattack = baseat;
  35.     static int exp = 0;
  36.     static int level = 1;
  37.     static int potions = 3;
  38.     static int target = 0;
  39.     static int money = 0;
  40.     static int playerhp = 0;
  41.     static int playermaxhp = 0;
  42.     static int heal = 50+((int)Math.floor(Math.random() * 100));
  43.  
  44. // alguns bools
  45.     static boolean battle = false;
  46.     static boolean npc = false;
  47.  
  48. // npc
  49.     static int preco = 100;
  50.     static String nome;
  51.  
  52.     public static void keepMove(String dir){
  53.         int result = (int) Math.floor(Math.random()*100);
  54.         if (result>80) {
  55.             target = (int)Math.floor(Math.random()*nomes.length);
  56.             battle = true;
  57.             targetmaxhp = hps[target];
  58.             targethp = targetmaxhp;
  59.             playerattack = baseat+level+weaponatk[selecteditem];
  60.             System.out.println("A wild "+nomes[target]+" appeared! ["+targethp+"/"+targetmaxhp+"]");
  61.         } else if (result<3) {
  62.             npc = true;
  63.             System.out.println("You have found a person who sells potions for $"+preco+" each. <Buy> or <not>?");
  64.         } else if (result>77 && result<=80) {
  65.             int premmyitem = (int)Math.floor(Math.random()*weaponname.length);
  66.             if(weaponatk[premmyitem]>weaponatk[selecteditem]){
  67.                 System.out.println("You have found an item! ("+weaponname[premmyitem]+": Atk +"+weaponatk[premmyitem]+")");
  68.                 selecteditem = premmyitem;
  69.                 playerattack = playerattack + weaponatk[premmyitem];
  70.             } else {
  71.                 if(premmyitem==selecteditem){
  72.                     System.out.println("You have found an item ("+weaponname[premmyitem]+"), but you have this item already.");
  73.                 } else {
  74.                     System.out.println("You have found an item ("+weaponname[premmyitem]+"), but you have a better item, which is the "+weaponname[selecteditem]+".");
  75.                 }
  76.                 idler(nome);
  77.                 }
  78.         } else if (result > 50 && result <= 60){
  79.             System.out.println("Sorry, it seems that there is something blocking the way. Could not move "+dir+"way.");
  80.                 if (dir.equals("up")){
  81.                     up = false;
  82.                     posy++;
  83.                 } else if (dir.equals("down")){
  84.                     down = false;
  85.                     posy--;
  86.                 } else if (dir.equals("left")){
  87.                     left = false;
  88.                     posx--;
  89.                 } else if (dir.equals("right")){
  90.                     right = false;
  91.                     posx++;
  92.                 }
  93.         } else {
  94.             left = true;
  95.             up = true;
  96.             right = true;
  97.             down = true;
  98.         }
  99.     }
  100.    
  101.     public static void moveDir(String dir){
  102.         String finalizar = "Sorry, it seems that there is something blocking the way. Could not move "+dir+"way.";
  103.        
  104.         // checa se pode andar pra direção , se n puder volta a coordenada anterior
  105.         if (dir.equals("up")) {
  106.             if (up==true){
  107.                 keepMove("up");
  108.             } else {
  109.                 posy++;
  110.                 System.out.println(finalizar);
  111.             }
  112.         } else if (dir.equals("down")) {
  113.             if (down==true){
  114.                 keepMove("down");
  115.             } else {
  116.                 posy--;
  117.                 System.out.println(finalizar);
  118.             }
  119.         } else if (dir.equals("left")) {
  120.             if (left==true){
  121.                 keepMove("left");
  122.             } else {
  123.                 posx++;
  124.                 System.out.println(finalizar);
  125.             }
  126.         } else if (dir.equals("right")) {
  127.             if (right==true){
  128.                 keepMove("right");
  129.             } else {
  130.                 posx--;
  131.                 System.out.println(finalizar);
  132.             }
  133.         }
  134.         }
  135.  
  136.  
  137.     static void tryagain(){
  138.         if ((level*levelxp - exp) < 1) {
  139.             level++;
  140.             System.out.println("You got another level! You are now level "+(level)+"!");
  141.             tryagain();
  142.         }
  143.     }
  144.  
  145.     public static void idler(String nome){
  146.         if (playerhp > 0) {
  147.         playermaxhp = 100 + (level*20);
  148.         Scanner direc = new Scanner(System.in);
  149.         String dir = direc.nextLine();
  150.        
  151.         if (npc == false){
  152.         if (battle == false){
  153.         if ("up".equals(dir)){
  154.             System.out.println("You just walked upway.");
  155.             posy--;
  156.             moveDir("up");
  157.         } else  if ("potion".equals(dir)){
  158.             if (potions>0){
  159.             potions--;
  160.             playerhp = playerhp + heal;
  161.             if (playerhp > playermaxhp) {
  162.                 playerhp = playermaxhp;
  163.             }
  164.             System.out.println("You just used a potion which healed "+heal+" hitpoints.");
  165.             } else {
  166.                 System.out.println("You do not have potions anymore.");
  167.             }
  168.             idler(nome);
  169.         } else if ("weapon".equals(dir)){
  170.             System.out.println("Your actual weapon is: "+weaponname[selecteditem]+".");
  171.         } else if ("level".equals(dir)){
  172.             System.out.println("You are level "+level+".");
  173.         } else if ("exp".equals(dir)){
  174.             System.out.println("You have "+exp+" experience points. "+(level*levelxp - exp)+" exp points left for the next level.");
  175.         } else if ("hp".equals(dir)){
  176.             System.out.println("HP: ["+playerhp+"/"+playermaxhp+"]");
  177.         } else if ("right".equals(dir)){
  178.             System.out.println("You just walked rightway.");
  179.             posx--;
  180.             moveDir("right");
  181.         } else if ("left".equals(dir)){
  182.             System.out.println("You just walked leftway.");
  183.             posx++;
  184.             moveDir("left");
  185.         } else if ("strenght".equals(dir) || "op".equals(dir)){
  186.             System.out.println("Your offensive power: "+(baseat+level+weaponatk[selecteditem])+" [Level:+"+(baseat+level)+"op/Weapon:+"+weaponatk[selecteditem]+"op]");
  187.             posx++;
  188.         } else if ("down".equals(dir)){
  189.             System.out.println("You just walked downway.");
  190.             posy++;
  191.             moveDir("down");
  192.         } else if ("money".equals(dir)){
  193.             System.out.println("You have $"+money+".");
  194.         } else if ("pos".equals(dir)){
  195.             System.out.println("Your position is: [x:"+posx+"|y:"+posy+"]");
  196.         }
  197.         idler(nome);
  198.         } else {
  199.            
  200.             if ("flee".equals(dir)){
  201.                 int chance = (int)Math.floor(Math.random() * 100);
  202.                 if (chance<=80){
  203.                     battle=false;
  204.                     System.out.println("You just got away safely.");
  205.                 } else {
  206.                     System.out.println(nomes[target]+" don\'t let you go!");
  207.                     if(Math.floor((Math.random()*100))<10){
  208.                         System.out.println("["+nomes[target].toUpperCase()+"] misses the attack.");
  209.                     } else {
  210.                         int dmage = (int)Math.floor((Math.random()*str[target]));
  211.                         playerhp = playerhp - dmage;
  212.                         System.out.println("["+nome.toUpperCase()+"] Takes "+nome+" -"+dmage+" hitpoints.");
  213.                     }
  214.                     if (playerhp > 0){
  215.                         System.out.println(nomes[target]+"\'s HP: ["+targethp+"/"+targetmaxhp+"]");
  216.                         System.out.println(nome+"\'s HP: ["+playerhp+"/"+playermaxhp+"]");
  217.                     } else {
  218.                         System.out.println("You died.");
  219.                     }
  220.                     }
  221.                 idler(nome);
  222.             }
  223.             // usar poção na luta
  224.             if ("potion".equals(dir)){
  225.                 if (potions>0){
  226.                 playerhp = playerhp + heal;
  227.                 potions--;
  228.                 playerhp = playerhp + heal;
  229.                 if (playerhp > playermaxhp) {
  230.                     playerhp = playermaxhp;
  231.                 }
  232.                 System.out.println("You just used a potion which healed "+heal+" hitpoints.");
  233.                 } else {
  234.                     System.out.println("You do not have potions anymore.");
  235.                 }
  236.             }
  237.            
  238.             // atacar na luta
  239.             if ("attack".equals(dir)){
  240.                 if(Math.floor((Math.random()*100))<10){
  241.                     System.out.println("["+nomes[target].toUpperCase()+"] misses the attack.");
  242.                 } else {
  243.                     int dmage = (int)Math.floor((Math.random()*str[target]));
  244.                     playerhp = playerhp - dmage;
  245.                     System.out.println("["+nomes[target].toUpperCase()+"] Takes "+nome+" -"+dmage+" hitpoints.");
  246.                 }
  247.                 // chance de errar atk
  248.                 if(playerhp > 0){
  249.                     if(Math.floor((Math.random()*100))<10){
  250.                         System.out.println("["+nome.toUpperCase()+"] misses the attack.");
  251.                     } else {
  252.                         int damage = (int)Math.floor((Math.random()*playerattack));
  253.                 targethp = targethp - damage;
  254.                 System.out.println("["+nome.toUpperCase()+"] Takes "+nomes[target]+" -"+damage+" hitpoints!");
  255.                     }
  256.                 if (targethp>0){
  257.                     System.out.println(nomes[target]+"\'s HP: ["+targethp+"/"+targetmaxhp+"]");
  258.                     System.out.println(nome+"\'s HP: ["+playerhp+"/"+playermaxhp+"]");
  259.                     idler(nome);
  260.                 } else {
  261.                     System.out.println("Enemy defeated!");
  262.                     exp = exp + exps[target];
  263.                     // checa se o jogador upou
  264.                     if ((level*levelxp - exp) < 1) {
  265.                         System.out.println("You won "+exps[target]+" exp points and leveled up!");
  266.                         exp = exp - level*levelxp;
  267.                         level++;
  268.                         playerattack = baseat+level;
  269.                         tryagain();
  270.                         System.out.println("You are now level "+(level)+"!");
  271.                     } else {
  272.                         System.out.println("You won "+exps[target]+" exp points. "+(level*levelxp - exp)+" exp points for level up.");
  273.                     }
  274.                     int prize = (int)Math.floor(Math.random()*(loot$[target]));
  275.                     System.out.println("You got $"+prize+" from "+nomes[target]+"\'s loot.");
  276.                     money = money + prize;
  277.                     battle = false;
  278.                     idler(nome);
  279.                 }
  280.                 } else {
  281.                     System.out.println("You died.");
  282.                 }
  283.             } /* aqui acaba o ataque */ else {
  284.                 idler(nome);
  285.             }
  286.         }
  287.         } else {
  288.             // se npc for true
  289.             String prox = dir;
  290.             // se falar buy
  291.             if("buy".equals(prox)){
  292.                 if (money>preco){
  293.                     money=money-preco;
  294.                     potions++;
  295.                     System.out.println("You just bought a potion and the man got away in the path of the shadows.");
  296.                     npc = false;
  297.                 } else {
  298.                     System.out.println("You just don\'t have enought money, the man got away.");
  299.                     npc = false;
  300.                 }
  301.                 // se falar not
  302.             } else if ("not".equals(prox)){
  303.                 System.out.println("You refuse to buy anything and the man gets away in the path of the shadows.");
  304.                 npc = false;
  305.             }
  306.             idler(nome);
  307.         }
  308.         direc.close();
  309.         }
  310.     }
  311.    
  312.     public static void main(String[] args){
  313.     System.out.println("Welcome to your worst nightmare. Tell me your name, little piece of soul.");
  314.     Scanner objeto = new Scanner(System.in);
  315.     String prox = objeto.nextLine();
  316.     nome = prox;
  317.     System.out.println("So it all began, "+nome+".");
  318.     playermaxhp = 100 + (level*20);
  319.     playerhp = playermaxhp;
  320.     idler(nome);
  321.     objeto.close();
  322.     }
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement