fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Player p=new HealPlayer();
  13. sim(p);
  14. }
  15. public static void sim(Player p){
  16. while(p.isAlive()){
  17. p.prnt();
  18. p.work();
  19. }
  20. p.prnt();
  21. }
  22. }
  23.  
  24. class Player{
  25. protected int hp,place;
  26. public Player(){
  27. hp=5;
  28. place=0;
  29. }
  30. public boolean isAlive(){
  31. if(1<=hp) return true;
  32. else return false;
  33. }
  34. public void prnt(){
  35. System.out.println("hp="+hp+" palce="+place);
  36. }
  37. public void work(){
  38. if(hp>=1){
  39. hp--;
  40. place++;
  41. }
  42. }
  43.  
  44. }
  45.  
  46. class HealPlayer extends Player{
  47. private int mp,maxHp;
  48. public HealPlayer(){
  49. mp=3;
  50. maxHp=hp;
  51. }
  52. public void work(){
  53. super.work();
  54. if(mp>=0 && hp<maxHp/2){
  55. hp=maxHp;
  56. mp--;
  57. }
  58. }
  59. }
  60.  
  61.  
  62.  
Success #stdin #stdout 0.11s 39116KB
stdin
Standard input is empty
stdout
hp=5 palce=0
hp=4 palce=1
hp=3 palce=2
hp=2 palce=3
hp=5 palce=4
hp=4 palce=5
hp=3 palce=6
hp=2 palce=7
hp=5 palce=8
hp=4 palce=9
hp=3 palce=10
hp=2 palce=11
hp=5 palce=12
hp=4 palce=13
hp=3 palce=14
hp=2 palce=15
hp=5 palce=16
hp=4 palce=17
hp=3 palce=18
hp=2 palce=19
hp=1 palce=20
hp=0 palce=21