serhatyucell

SpaceGame

Jan 15th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.54 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3. import java.util.Random;
  4.  
  5. public class main {
  6. public static void main(String[] args) {
  7.    
  8.     ArrayList<NPC> allNPC = new ArrayList<NPC>();
  9.     // NPC'leri oluştur
  10.                     //Name , FHP , HP , SP , Damage , XP
  11.     NPC N0 = new NPC("Zagolar",25000,25000,25000,250,50);
  12.     NPC N1 = new NPC("Riginmon",50000,50000,50000,500,100);
  13.     NPC N2 = new NPC("Schetkov",100000,100000,100000,1000,150);
  14.     NPC N3 = new NPC("Tortugate",200000,200000,200000,2000,200);
  15.     NPC N4 = new NPC("Echonia",225000,225000,225000,2500,400);
  16.     NPC N5 = new NPC("Cajsa",250000,250000,250000,2750,500);
  17.     NPC N6 = new NPC("Vaula",300000,300000,300000,3500,700);
  18.     // Array'e tüm NPCleri ekle
  19.     allNPC.add(N0);
  20.     allNPC.add(N1);
  21.     allNPC.add(N2);
  22.     allNPC.add(N3);
  23.     allNPC.add(N4);
  24.     allNPC.add(N5);
  25.     allNPC.add(N6);
  26.     // Rastgele NPC ver
  27.     Random k = new Random();
  28.     int randomk = k.nextInt(allNPC.size());
  29.     NPC currentNPC = allNPC.get(randomk);
  30.  
  31.     // Silah ve kahramanı oluştur
  32.    
  33.     GUN gun1 = new GUN ("FireTrap", 5000);
  34.     HERO me = new HERO ("Vince Floyd", 1000, 1000,0);
  35.    
  36.     // İşe yarayacak değişkenleri tanımla
  37.    
  38.     String NPC_name, HERO_name;
  39.     int NPC_fLife, NPC_life, NPC_damage, NPC_wonxp, GUN_damage, HERO_life, HERO_fLife, HERO_xp;
  40.    
  41.     // Programı başlat, sürekli çalışsın
  42.    
  43.     while (1>0) {
  44.        
  45.         // Ne yapalım? Savaşalım mı? Kaçalım mı? Sonuçlanana kadar sürekli sor.
  46.         Scanner s = new Scanner (System.in);
  47.         System.out.println("1: Hit the NPC | 2: Escape");
  48.         int choice = s.nextInt();
  49.        
  50.         // Kontrolleri sağlamak için bilgileri çek
  51.         NPC_name = currentNPC.getName();
  52.         NPC_fLife = currentNPC.getFristHp();
  53.         NPC_life = currentNPC.getLife();
  54.         NPC_damage = currentNPC.getDamage();
  55.         NPC_wonxp = currentNPC.getWonXP();
  56.         GUN_damage = gun1.getDamage();
  57.         HERO_name = me.getName();
  58.         HERO_fLife = me.getFlife();
  59.         HERO_life = me.getLife();
  60.         HERO_xp = me.getExp();
  61.        
  62.         // 0 ile 99 arasında random sayı ver, 50'den küçükse NPC bize hasar versin.
  63.         Random r = new Random();
  64.         int random = r.nextInt(100);
  65.         // NPC normal gücünden +50, -50 arasında random şekilde kritik vursun
  66.         int low = NPC_damage-50;
  67.         int high = NPC_damage+50;
  68.         int randomNPCdamage = r.nextInt(high-low)+ low;
  69.        
  70.        
  71.     // 1'i seçerse savaş başlasın.
  72.     if (choice == 1) {
  73.             // Savaş başladı NPC'ye silahımızla vuruyoruz
  74.             currentNPC.setLife(NPC_life-GUN_damage);
  75.             NPC_life = currentNPC.getLife();
  76.            
  77.         // NPC'ye vurduk. Eğer ölmememişse değerleri yazdır
  78.         if (NPC_life > 0) {
  79.            
  80.             // NPC bize vurmadıysa
  81.             if (random > 50) {
  82.             System.out.println("[" + NPC_name + "]");
  83.             System.out.println("DMG: Miss!");
  84.             print_NPC_Hp(NPC_fLife,NPC_life);
  85.             System.out.println("[" + HERO_name + "]");
  86.             System.out.println("DMG: BAM! +" + GUN_damage);
  87.             print_HERO_Hp(HERO_fLife,HERO_life);
  88.             }
  89.            
  90.             //NPC bize vurduysa
  91.             else {
  92.             me.setLife(HERO_life-randomNPCdamage);
  93.             HERO_life = me.getLife();
  94.             // Öldük mü?
  95.             if (HERO_life <= 0) {
  96.                 me.setLife(0);
  97.                 HERO_life = me.getLife();
  98.                 System.out.println("[" + NPC_name + "]");
  99.                 System.out.println("DMG: BAM! +" + randomNPCdamage);
  100.                 print_NPC_Hp(NPC_fLife,NPC_life);
  101.                 System.out.println("[" + HERO_name + "]");
  102.                 print_HERO_Hp(HERO_fLife,HERO_life);
  103.                 System.out.println("R.I.P: " + HERO_name);
  104.                
  105.                 break;
  106.             }
  107.             // Vurursun ama ölmezsem sıkıntı...
  108.             else {
  109.                 System.out.println("[" + NPC_name + "]");
  110.                 System.out.println("DMG: BAM! +" + randomNPCdamage);
  111.                 print_NPC_Hp(NPC_fLife,NPC_life);
  112.                 System.out.println("[" + HERO_name + "]");
  113.                 System.out.println("DMG: BAM! +" + GUN_damage);
  114.                 print_HERO_Hp(HERO_fLife,HERO_life);
  115.             }
  116.            
  117.             }
  118.            
  119.             }
  120.        
  121.        
  122.         // NPC'yi kestik hurray!   
  123.         else {
  124.                 currentNPC.setLife(0);
  125.                 NPC_life = currentNPC.getLife();
  126.                 System.out.println("[" + NPC_name + "]");
  127.                 print_NPC_Hp(NPC_fLife,NPC_life);
  128.                 System.out.println("[" + HERO_name + "]");
  129.                 System.out.println("DMG: BAM! +" + GUN_damage);
  130.                 print_HERO_Hp(HERO_fLife,HERO_life);
  131.                 System.out.println(NPC_name + " is dead!");
  132.                 HERO_xp = NPC_wonxp + HERO_xp;
  133.                 me.setExp(HERO_xp);
  134.                 System.out.println("You won " + NPC_wonxp + "XP. You have totally " + HERO_xp + "XP.");
  135.                 break;
  136.             }
  137.        
  138.     }
  139.    
  140.     // 2'yi sçerse hemen tüysün
  141.     else if (choice == 2) {
  142.         System.out.println("You escaped before the die.");
  143.         break;
  144.     }
  145.    
  146.     // 1 veya 2'den farklı değer girerse hata bas
  147.     else {
  148.         System.out.println("Please choose the valid option!");
  149.     }
  150.    
  151.     }
  152.    
  153. }
  154.  
  155. public static void print_NPC_Hp (int NPC_fLife, int NPC_life) {
  156.    
  157.     int yuzde1 = 100*NPC_life/NPC_fLife;
  158.     int cubuk1 = yuzde1/10;
  159.     String[] showNHp = new String[10];
  160.     for (int i = 0; i < showNHp.length; i++) {
  161.         showNHp[i] = "_";
  162.     }
  163.    
  164.     for (int i = 0; i < cubuk1; i++) {
  165.         showNHp[i] = "|";
  166.     }
  167.    
  168.     System.out.print("HP: [");
  169.     for (int i = 0; i < showNHp.length; i++) {
  170.         System.out.print(showNHp[i]);
  171.     }
  172.     System.out.print("] %" + yuzde1 + " (" + NPC_life + ")\n\n");
  173. }
  174.  
  175.  
  176. public static void print_HERO_Hp (int HERO_fLife, int HERO_life) {
  177.    
  178.     int yuzde2 = 100*HERO_life/HERO_fLife;
  179.     int cubuk2 = yuzde2/10;
  180.     String[] showHHp = new String[10];
  181.     for (int i = 0; i < showHHp.length; i++) {
  182.         showHHp[i] = "_";
  183.     }
  184.    
  185.     for (int i = 0; i < cubuk2; i++) {
  186.         showHHp[i] = "|";
  187.     }
  188.    
  189.     System.out.print("HP: [");
  190.     for (int i = 0; i < showHHp.length; i++) {
  191.         System.out.print(showHHp[i]);
  192.     }
  193.     System.out.print("] %" + yuzde2 + " (" + HERO_life + ")\n\n");
  194.     System.out.println("______________END OF ROUND____________\n");
  195. }
  196.  
  197.  
  198. }
Advertisement
Add Comment
Please, Sign In to add comment