zopiac

UItest

Feb 8th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.08 KB | None | 0 0
  1. package gameTest;
  2. import java.awt.*;
  3. import java.util.Random;
  4. import java.applet.*;
  5. import java.awt.event.*;
  6. import gameTest.RandomWeapon;
  7.  
  8. import butka.Wait;
  9. public class UItest extends Applet implements KeyListener{
  10.     Image dbImage;
  11.     Graphics dbg;
  12.     private static Random randInt = new Random();
  13.     private static int t;                                                           //Counter
  14.     private static int k,l;                                                         //Keyboard keys (instantaneous and last pressed)
  15.     private static int level=1;                                                     //level
  16.     //      private static int STR, CON, INT, WIS,DEX, CHA=6;       //Character Stats TODO
  17.     private static int hp=100;                                                      //Instantaneous health
  18.     private static int maxhp=100;                                           //Max health
  19.     private static int mp=100;                                                      //Instantaneous mana
  20.     private static int maxmp=100;                                           //Max mana
  21.     private static int hpot,mpot=5;                                         //Potions (health and mana)
  22.     private static int money;                                                       //Total money
  23.     private static int cp, sp, gp, pp;                                      //Monetary denominations
  24.     private static int exp, nextLevel;                                      //Experience
  25.     private static int arm1,arm2,enc;                                       //Armour values
  26.     private static int item,cost;                                           //Store  values
  27.     private static int moneyGive, moneyGiveRep;                     //Random money gift and reported monetary gain
  28.     private static int dmg, repdmg=0;                                       //Damage and reported damage
  29.     private static int edmg, repedmg;
  30.     private static int hitMin, hitMax;                                      //Random weapon hit boundaries
  31.     private static int hit1, hit2, hit3;                            //Player attack variables
  32.     private static int ehit1, ehit2, ehit3;                         //Enemy  attack variables
  33.     private static int hpercdisp, mpercdisp;                        //Health and Mana percentages to be displayed
  34.     private static int bestmax;                                                     //Best weapon's max so far
  35.     private static double hperc, mperc;                                     //Health and Mana percentages to be calculated
  36.     private static int skillPTs=50;                                         //Skill Points
  37.     //      private static int[] stats;                                                     //level, skillPTS, maxhp, hp, maxmp, mp
  38.     private static int moneydrop;                                           //Money dropped by enemy
  39.     private static int[] enemy;                                                     //Enemy stats
  40.     private static String enemyName;                                        //Enemy Name
  41.     private static double hitMult;                                          //Random weapon's hit multiplier
  42.     private static double[] randStats;                                      //Stats of random weapon
  43.     private static boolean enemycheck;                                      //If enemy is there~~
  44.     private static boolean dead=false;                      //if(dead==true)Game Over;
  45.     private static boolean godmode;                         //God Mode
  46.     private static String weaponName="Unarmed";                     //Weapon name
  47.     //MONSTER INITIALISATION                             ID, MaxHP,    HP, HP%,  A d B,      exp,      moneyR,        moneyP
  48.     private static final int[] rat          = new int[]{  1,    32,    32, 100,  2,  4,        6,          30,          30};   //Rat stats          //LEVEL//00002
  49.     private static final int[] goblin       = new int[]{  2,    48,    48, 100,  3,  5,       12,         150,         100};   //Goblin stats       //LEVEL//00006
  50.     private static final int[] skeleton     = new int[]{  3,    80,    80, 100,  6,  3,       36,000000000000,000000000000};   //Skeleton stats     //LEVEL//00012
  51.     private static final int[] zombie       = new int[]{  4,   100,   100, 100,  8,  3,       60,000000000000,000000000000};   //Zombie stats       //LEVEL//00020
  52.     private static final int[] spectre      = new int[]{  5,   240,   240, 100,  1, 20,      120,000000000000,000000000000};   //Spectre stats      //LEVEL//00040
  53.     private static final int[] ghoul        = new int[]{  6,   180,   180, 100, 12,  3,      162,000000000000,000000000000};   //Ghoul stats        //LEVEL//00054
  54.     private static final int[] wraith       = new int[]{  7,   240,   240, 100,  4, 12,      288,000000000000,000000000000};   //Wraith stats       //LEVEL//00096
  55.     private static final int[] ghast        = new int[]{  8,   200,   200, 100, 20,  6,      600,000000000000,000000000000};   //Ghast stats        //LEVEL//00200
  56.     private static final int[] ogre         = new int[]{  9,   400,   400, 100, 12,  6,      164,       20000,       20000};   //Ogre stats         //LEVEL//00240
  57.     private static final int[] vampire      = new int[]{ 10,  1000,  1000, 100, 12, 12,     5000,000000000000,000000000000};   //Vampire stats      //LEVEL//01200
  58.     //ivate static final int[] NAME         = new int[]{000,000000,000000, 100,000,000,000000000,000000000000,000000000000};   //NAME stats         //LEVEL//00000
  59.  
  60.     String armourm = "Cloth";
  61.     String armourt = "Shirt";
  62.     //      Toolkit tk=Toolkit.getDefaultToolkit();
  63.     //      Image graphic = tk.getImage("C:\\Zopiac\\Graphics\\Wheel.png");
  64.     public void init(){
  65.         this.setSize(800,600);
  66.         addKeyListener(this);
  67.         //Adb, adB, Material, Enchant, Quality
  68.         randStats       = new double[]{0, 0, 0, 0, 0};
  69.         //              stats           = new int[]{0, 0, 0, 0, 0, 0};
  70.         //MonsterID, MaxHP, HP, hperc, dnumber, dvalue, exp, moneyR, moneyP
  71.         enemy           = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  72.         //              rat                     = new int[]{1, 16, 16, 100, 2, 4, 8};
  73.         //              goblin          = new int[]{2, 24, 24, 100, 3, 5, 12};
  74.         //              ogre            = new int[]{ 3,  400,  400, 100, 6, 8, 164};
  75.     }
  76.     public void paint(Graphics g){
  77.         //Upkeep phase
  78.                         Wait.mSec(50);
  79.  
  80.         this.setSize(800,600);
  81.         if(!dead){
  82.             upkeep();
  83.             keyCheck();
  84.             upkeep();
  85.         }
  86.         if(godmode){
  87.         hp=maxhp;                                                                       //Unlimited Health
  88.         if(bestmax<=90){newWeapon();repaint();}                                         //Auto Weapon
  89.         money = 99999999;                                                               //Infinite Money
  90.        
  91.         }
  92.         //Display phase
  93.         g.drawString("Key Pressed: "+l, 100, 180);
  94.         g.drawString(""+t,20, 150);
  95.         //Status
  96.         g.drawString("Level:    "+level, 20, 15);
  97.         g.drawString("Skill Points: "+skillPTs, 80, 15);
  98.         g.drawString("Experience:    "+exp+" Next: "+nextLevel, 20, 35);
  99.         g.drawString("Health:  "+hp+"/"+maxhp+" "+hpercdisp+"%", 20, 55);
  100.         g.drawString("Mana:    "+mp+"/"+maxmp+" "+mpercdisp+"%", 20, 75);
  101.         g.drawString("Health Potions: "+hpot, 10, 100);
  102.         g.drawString("Mana Potions  : "+mpot, 10, 120);
  103.         if(enemycheck&&repdmg>0)g.drawString("Your attack did "+repdmg+" damage to "+enemyName+"!", 210, 110);
  104.         if(repedmg>0)g.drawString("Enemy attack did "+repedmg+" damage!", 210, 130);
  105.         //Equipment
  106.         g.drawString("Weapon: "+weaponName,50, 450);
  107.         g.drawString("Armour: "+armourm+" "+armourt,50, 470);
  108.         g.drawString("Attack: "+hitMin+"-"+hitMax, 50, 500);
  109.         g.drawString(
  110.                 "Defence: "+arm1+"d"+arm2
  111.                 +", "+arm1+"-"+(arm1*arm2),
  112.                 50, 520);
  113.         g.drawString("Encumbrance: "+enc, 50, 540);
  114.         //Money
  115.         g.drawString("Money:", 740,  40);
  116.         g.drawString(cp+"",    740,  60);
  117.         g.drawString(sp+"",    740,  80);
  118.         g.drawString(gp+"",    740, 100);
  119.         g.drawString(pp+"",    740, 120);
  120.         g.drawString("CP",     770,  60);
  121.         g.drawString("SP",     770,  80);
  122.         g.drawString("GP",     770, 100);
  123.         g.drawString("PP",     770, 120);
  124.         g.drawString("Total Money: ",700, 150);
  125.         g.drawString(""+money, 700, 170);
  126.         //Commands
  127.         g.drawString("Q to hit yourself",100, 200);
  128.         g.drawString("W to use magic",100, 220);
  129.         g.drawString("E to generate new weapon",100, 240);
  130.         g.drawString("A to use HP Pot",100, 260);
  131.         g.drawString("S to use MP Pot",100, 280);
  132.         g.drawString("D to disarm",100, 300);
  133.         g.drawString("Z to buy HP Pot (cost 4s50c)",100, 320);
  134.         g.drawString("X to buy MP Pot (cost 6s50c)",100, 340);
  135.         //Money Gift
  136.         g.drawString("G to give small  amount of money", 300, 300);
  137.         g.drawString("H to give medium amount of money", 300, 315);
  138.         g.drawString("J to give large  amount of money", 300, 330);
  139.         g.drawString("K to give giant  amount of money", 300, 345);
  140.         g.drawString("L to give insane amount of money", 300, 360);
  141.         g.drawString(moneyGiveRep+" copper received.", 300, 380);
  142.  
  143.         g.drawString("Y to initialise battle phase", 300, 255);
  144.         g.drawString("I to summon/recall enemy", 300, 270);
  145.        
  146.         g.drawString("P to toggle God Mode", 300, 550);
  147.  
  148.         //                g.drawString("Best Max: "+bestmax, 500, 500);
  149.  
  150.         if(enemycheck)g.drawString(enemyName+": HP: "+enemy[3], 200, 50);
  151.         //              g.drawString(enemy[0]+" "+enemy[1]+" "+enemy[2]+" "+enemy[3]+" "+enemy[4]+" "+enemy[5]+" "+enemy[6],500, 500);
  152.         //              g.drawString(rat[0]+" "+rat[1]+" "+rat[2]+" "+rat[3]+" "+rat[4]+" "+rat[5]+" "+rat[6],500, 520);
  153.         //              g.drawString(goblin[0]+" "+goblin[1]+" "+goblin[2]+" "+goblin[3]+" "+goblin[4]+" "+goblin[5]+" "+goblin[6],500, 540);
  154.  
  155.         t++;
  156.     }
  157.     public void update(Graphics g){
  158.         if (dbImage == null){
  159.             dbImage = createImage (800, 600);
  160.             dbg = dbImage.getGraphics ();
  161.         }
  162.         dbg.setColor (getBackground ());
  163.         dbg.fillRect (0, 0, 800, 600);
  164.         dbg.setColor (getForeground());
  165.         paint (dbg);
  166.         g.drawImage (dbImage, 0, 0, this);
  167.     }
  168.     public void keyPressed   (KeyEvent   e) {
  169.         k=e.getKeyCode();
  170.         l=e.getKeyCode();
  171.         repaint();
  172.     }
  173.     public void keyReleased  (KeyEvent   e) {
  174.         k=0;
  175.         repaint();
  176.     }
  177.     static void keyCheck(){
  178.         switch (k) {
  179.         case 81://Attack Self
  180.         attackSelf();
  181.         k=0;
  182.         break;
  183.         case 87://Use Magic
  184.         mp-=10;
  185.         k=0;
  186.         break;
  187.         case 65://Use HPot
  188.             if (hpot>0&&hp!=maxhp){hpot--;hp+=20;}
  189.             k=0;
  190.             break;
  191.         case 83://Use MPot
  192.             if (mpot>0&&mp!=maxmp){mpot--;mp+=20;}
  193.             k=0;
  194.             break;
  195.         case 90:
  196.             item=1;//Buy HPot
  197.             buy();
  198.             k=0;
  199.             break;
  200.         case 88://Buy MPot
  201.             item=2;
  202.             buy();
  203.             k=0;
  204.             break;
  205.         case 71:
  206.             moneyGive=randInt.nextInt(100)+50;
  207.             k=0;
  208.             break;
  209.         case 72:
  210.             moneyGive=randInt.nextInt(600)+400;
  211.             k=0;
  212.             break;
  213.         case 74:
  214.             moneyGive=randInt.nextInt(2500)+4000;
  215.             k=0;
  216.             break;
  217.         case 75:
  218.             moneyGive=randInt.nextInt(25000)+40000;
  219.             k=0;
  220.             break;
  221.         case 76:
  222.             moneyGive=randInt.nextInt(5000000)+8000000;
  223.             moneyGive=randInt.nextInt(2500000)+40000000;
  224.             k=0;
  225.             break;                  
  226.         case 69:
  227.             if(bestmax<90)newWeapon();
  228.             //                        k=0;
  229.             break;
  230.         case 68:
  231.             disarm();
  232.             k=0;
  233.             break;
  234.         case 86:
  235.             k=0;
  236.             break;
  237.         case 67:
  238.             levelup();
  239.             k=0;
  240.             break;
  241.         case 89:
  242.             attackEnemy();
  243.             k=0;
  244.             break;
  245.         case 85:
  246.             attackPlayer();
  247.             k=0;
  248.             break;
  249.         case 73:
  250.             addsubEnemy();
  251.             k=0;
  252.             break;
  253.         case 84:
  254.             bestmax=0;
  255.             k=0;
  256.         case 80:
  257.             godmode=(godmode)?false:true;
  258.             k=0;
  259.             break;
  260.         case 27:System.exit(0);
  261.         }
  262.     }
  263.     public static void attackEnemy(){
  264.         hit1=(int)randStats[0];
  265.         hit2=(int)randStats[1];
  266.         for(int i=0;i<hit1;i++){
  267.             hit3=randInt.nextInt(hit2)+1;
  268.             dmg+=hit3;
  269.         }
  270.         dmg=(int)(dmg*hitMult);
  271.         enemy[2]-=dmg;
  272.         repdmg=dmg;
  273.         dmg=0;
  274.  
  275.         //Enemy attack player
  276.         if(enemycheck)attackPlayer();
  277.     }
  278.     public static void attackSelf() {
  279.         hit1=(int)randStats[0];
  280.         hit2=(int)randStats[1];
  281.         for(int i=0;i<hit1;i++){
  282.             hit3=randInt.nextInt(hit2)+1;
  283.             dmg+=hit3;
  284.         }
  285.         dmg=(int)(dmg*hitMult);
  286.         hp-=dmg;
  287.         repdmg=dmg;
  288.         dmg=0;
  289.     }
  290.     public static void attackPlayer(){
  291.         ehit1=enemy[4];
  292.         ehit2=enemy[5];
  293.         for(int i=0;i<enemy[4];i++){
  294.             ehit3=randInt.nextInt(ehit2)+1;
  295.             edmg+=ehit3;
  296.         }
  297.         hp-=edmg;
  298.         repedmg=edmg;
  299.         edmg=0;
  300.     }
  301.     public static void addsubEnemy(){
  302.         if (!enemycheck) {
  303.             enemy[0]=(randInt.nextInt(3)+level-2);
  304.         }
  305.         if (enemycheck) {
  306.             enemy[0]=0;
  307.  
  308.         }
  309.         //Enemy checker
  310.         switch (enemy[0]){
  311.         case 0:
  312.             enemycheck=false;
  313.             for(int i=0;i<9;i++)enemy[i]=0;
  314.             enemyName="";
  315.             break;
  316.         case 1:
  317.             enemycheck=true;
  318.             for(int i=0;i<9;i++)enemy[i]=rat[i];
  319.             enemyName="Rat";
  320.             break;
  321.         case 2:
  322.             enemycheck=true;
  323.             for(int i=0;i<9;i++)enemy[i]=goblin[i];
  324.             enemyName="Goblin";
  325.             break;
  326.         case 3:
  327.             enemycheck=true;
  328.             for(int i=0;i<9;i++)enemy[i]=skeleton[i];
  329.             enemyName="Skeleton";
  330.             break;
  331.         case 4:
  332.             enemycheck=true;
  333.             for(int i=0;i<9;i++)enemy[i]=zombie[i];
  334.             enemyName="Zombie";
  335.             break;
  336.         case 5:
  337.             enemycheck=true;
  338.             for(int i=0;i<9;i++)enemy[i]=spectre[i];
  339.             enemyName="Spectre";
  340.             break;
  341.         case 6:
  342.             enemycheck=true;
  343.             for(int i=0;i<9;i++)enemy[i]=ghoul[i];
  344.             enemyName="ghoul";
  345.             break;
  346.         case 7:
  347.             enemycheck=true;
  348.             for(int i=0;i<9;i++)enemy[i]=wraith[i];
  349.             enemyName="Wraith";
  350.             break;
  351.         case 8:
  352.             enemycheck=true;
  353.             for(int i=0;i<9;i++)enemy[i]=ghast[i];
  354.             enemyName="Ghast";
  355.             break;
  356.         case 9:
  357.             enemycheck=true;
  358.             for(int i=0;i<9;i++)enemy[i]=ogre[i];
  359.             enemyName="Ogre";
  360.             break;
  361.         case 10:
  362.             enemycheck=true;
  363.             for(int i=0;i<9;i++)enemy[i]=vampire[i];
  364.             enemyName="Vampire";
  365.             break;
  366.         }
  367.     }
  368.     public static void buy(){
  369.         switch (item) {
  370.         case 1:
  371.             cost=450;
  372.             break;
  373.         case 2:
  374.             cost=650;
  375.             break;
  376.         case 3:
  377.         }
  378.         if(money>=cost){
  379.             money-=cost;
  380.             switch (item) {
  381.             case 1:
  382.                 hpot++;
  383.                 break;
  384.             case 2:
  385.                 mpot++;
  386.                 break;
  387.             case 3:
  388.             }
  389.         }
  390.         item=0;
  391.         cost=0;
  392.     }
  393.     static void upkeep(){
  394.         //Starting money
  395.         if(money==0)moneyGive=12575;
  396.  
  397.         //Health/Mana Percentages
  398.         if (hperc<=0){hperc=0;hpercdisp=0;}
  399.         hpercdisp=(int)(100*(double)hp/(double)maxhp);
  400.         mpercdisp=(int)(100*(double)mp/(double)maxmp);
  401.  
  402.         //Random Money Gift
  403.         if(moneyGive!=0)moneyGiveRep=moneyGive;
  404.         money+=moneyGive;
  405.         moneyGive=0;
  406.  
  407.         //Levelup Check
  408.         nextLevel=(100*level^2)-80;//(int)(100*Math.pow(level, 2));
  409.         if(exp>nextLevel)levelup();
  410.         //Unarmed checker
  411.         if(weaponName.equals("Unarmed")){
  412.             randStats[0]=1;
  413.             randStats[1]=4;
  414.             randStats[2]=1;
  415.             randStats[3]=1;
  416.             randStats[4]=1;
  417.         }
  418.  
  419.         //Min/Max damage calculator
  420.         hitMult=randStats[2]*randStats[3]*randStats[4];
  421.         hitMin=(int)(randStats[0]*hitMult);
  422.         hitMax=(int)(randStats[0]*randStats[1]*hitMult);
  423.  
  424.         //Money Calculation
  425.         if (money>99999999){
  426.             money=99999999;
  427.         }
  428.         pp=money/1000000;
  429.         gp=(money-(10000*(100*pp)))/10000;
  430.         sp=(money-(100*(100*gp))-(100*(10000*pp)))/100;
  431.         cp=(money-(100*sp)-(10000*gp)-(1000000*pp));
  432.         //              if(pp>99)pp=99;
  433.  
  434.         //Status bounds checker
  435.         if(hp<=0){hp=0;dead=true;}
  436.         if(hp>maxhp)hp=maxhp;
  437.         if(hp<0)        hp=0;
  438.         if(mp>maxmp)mp=maxmp;
  439.         if(mp<0)        mp=0;
  440.  
  441.         //Best Max
  442.         if(hitMax>bestmax)bestmax=hitMax;
  443.  
  444.         //Enemy health checker
  445.         if(enemycheck){
  446.             moneydrop=0;
  447.             if(enemy[3]>0)enemy[3]=(int)(100*((double)enemy[2]/(double)enemy[1]));
  448.             if(enemy[3]<=0){
  449.                 exp+=enemy[6];
  450.                 if(enemy[7]>0)moneydrop=randInt.nextInt(enemy[7])+enemy[8];
  451.                 money+=moneydrop;
  452.                 moneyGiveRep=moneydrop;
  453.                 addsubEnemy();
  454.             }
  455.         }
  456.        
  457.         if(!enemycheck)addsubEnemy();
  458.        
  459.  
  460.     }
  461.     public static void levelup(){
  462.         if (level<100){
  463.             level++;                                        //Update Level
  464.             skillPTs+=5;                            //Give five spendable skill points
  465.             hperc=(double)maxhp/(double)hp;                         //Calculate HP %age
  466.             mperc=(double)maxmp/(double)mp;                         //Calculate MP %age
  467.             maxhp=(int)(1.1*maxhp);         //Set new MaxHP
  468.             maxmp=(int)(1.05*maxmp);         //Set new MaxMP
  469.             hp=(int)(maxhp*hperc);          //Calculate new instantaneous HP
  470.             mp=(int)(maxmp*mperc);          //Calculate new instantaneous MP
  471.             //                        exp=0;
  472.         }
  473.     }
  474.     public static void newWeapon(){
  475.         randStats  = RandomWeapon.statWeapon();
  476.         weaponName = RandomWeapon.nameWeapon();
  477.     }
  478.     public static void disarm(){
  479.         randStats[0]=1;
  480.         randStats[1]=4;
  481.         randStats[2]=1;
  482.         randStats[3]=1;
  483.         randStats[4]=1;
  484.         weaponName="Unarmed";
  485.     }
  486.     public void keyTyped     (KeyEvent   e) {}
  487. }
Add Comment
Please, Sign In to add comment