Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 23rd, 2012  |  syntax: Java  |  size: 2.64 KB  |  views: 56  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Skill {
  2.     private int level, xp, xpborder;
  3.  
  4.     public Skill() {
  5.         level = 1;
  6.         xp = 0;
  7.         xpborder = 100;
  8.     }
  9.    
  10.    
  11.     public int getLevel(){
  12.         return level;
  13.     }
  14.     /**     *
  15.      * @return
  16.      * true if the added XP changed the level
  17.      */
  18.     public boolean addXP(int amount){
  19.         xp += amount;
  20.         if(xp > xpborder)
  21.         {
  22.             ++level;
  23.             xp -= xpborder;
  24.             xpborder *= 2;
  25.             return true;
  26.         }
  27.         return false;
  28.     }
  29. }
  30.  
  31. public final class CharacterStats {
  32.  
  33.     public final String firstName;
  34.     public final String lastName;
  35.     public final Zodiac zodiac;
  36.     public final Date birtdate;
  37.     public final Skill bravery, willpower, agility, intelligence, comprehension;
  38.  
  39.     public CharacterStats(String firstName, String lastName, Zodiac zodiac, Date birtdate) {
  40.         this.firstName = firstName;
  41.         this.lastName = lastName;
  42.         this.zodiac = zodiac;
  43.         this.birtdate = birtdate;
  44.  
  45.         bravery = new Skill();
  46.         willpower = new Skill();
  47.         agility = new Skill();
  48.         intelligence = new Skill();
  49.         comprehension = new Skill();
  50.     }
  51. }
  52.  
  53. public class Character {
  54.     private final CharacterStats stats;
  55.     private Weapon weapon;
  56.     private int life;
  57.     ...
  58.  
  59.     public Character(...) {
  60.         ...
  61.     }
  62.        
  63.    
  64.    
  65.     public Damage getAttack();
  66.    
  67.     public void defendAttack(Damage dmg);
  68.    
  69.     public void grantWinOver(Character char);
  70.    
  71.     public int getLife()
  72.     {
  73.         return life;
  74.     }
  75. }
  76.  
  77. public class Game {
  78.  
  79.     public enum TimeOfDay {
  80.  
  81.         MORNING, MIDDAY, EVENING, NIGHT;
  82.     }
  83.     private final Date date;
  84.     private final Character player, enemy;
  85.  
  86.     public Game() {
  87.         date = new Date(21, 12, 2012);
  88.         ...
  89.        
  90.         fight(player, enemy);
  91.     }    
  92.    
  93.     public void fight(Character a, Character b)
  94.     {
  95.         while(a.getLife() > 0 && b.getLife() > 0)
  96.         {
  97.             a.defendAttack(b.getAttack());
  98.             b.defendAttack(a.getAttack());
  99.         }
  100.        
  101.         if(a.getLife() > 0)
  102.             a.grantWinOver(b);
  103.         else if(b.getLife() > 0)
  104.             b.grantWinOver(a);
  105.        
  106.     }
  107.  
  108.     public TimeOfDay getTimeOfDay() {
  109.         int h = date.getHours();
  110.         if (h >= 4 && h < 10) {
  111.             return TimeOfDay.MORNING;
  112.         } else if (h >= 10 && h < 16) {
  113.             return TimeOfDay.MIDDAY;
  114.         } else if (h >= 16 && h < 22) {
  115.             return TimeOfDay.EVENING;
  116.         } else {
  117.             return TimeOfDay.NIGHT;
  118.         }
  119.     }
  120. }