From Idiotic Octupus, 8 Months ago, written in Java.
Embed
  1. package com.attila2;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.  
  8.         /*Monster monster1 = new Monster(200, 35, "Bearsharkpig");
  9.         Monster monster2 = new Monster(300, 50, "Hobo");
  10.         Monster monster3 = new Monster(400, 65, "King-Wong");*/
  11.  
  12. // /If I create these objects here, then Room.plot1 does not see them.../
  13. Player player1 = new Player(300, 50, "Drizzt", 75, false, 0);
  14.  
  15.  
  16.  
  17.         Room room1 = new Room(1);
  18.  
  19.         room1.plot1();
  20.     }
  21. }
  22.  
  23. package com.attila2;
  24.  
  25. /**
  26.  * Created by Attila on 2018. 01. 16..
  27.  */
  28. public class Creatures {
  29.  
  30.     public Creatures() {
  31.     }
  32.  
  33.     public Creatures(int hp, int attackPower, String name) {
  34.         this.hp = hp;
  35.         this.attackPower = attackPower;
  36.         this.name = name;
  37.     }
  38.  
  39.     private int hp;
  40.     private int attackPower;
  41.     private String name;
  42.  
  43.     public int getHp() {
  44.         return hp;
  45.     }
  46.  
  47.     public void setHp(int hp) {
  48.         this.hp = hp;
  49.     }
  50.  
  51.     public int getAttackPower() {
  52.         return attackPower;
  53.     }
  54.  
  55.     public void setAttackPower(int attackPower) {
  56.         this.attackPower = attackPower;
  57.     }
  58.  
  59.     public String getName() {
  60.         return name;
  61.     }
  62.  
  63.     public void setName(String name) {
  64.         this.name = name;
  65.     }
  66.  
  67.  
  68. }
  69.  
  70. package com.attila2;
  71.  
  72. /**
  73.  * Created by Attila on 2018. 01. 16..
  74.  */
  75. public class Monster extends Creatures {
  76.  
  77.     public Monster(int hp, int attackPower, String name) {
  78.         super(hp, attackPower, name);
  79.     }
  80.  
  81.     Monster monster1 = new Monster(200, 35, "Bearsharkpig");
  82.     Monster monster2 = new Monster(300, 50, "Hobo");
  83.     Monster monster3 = new Monster(400, 65, "King-Wong");
  84.  
  85.  
  86.  
  87. }
  88.  
  89. package com.attila2;
  90.  
  91. /**
  92.  * Created by Attila on 2018. 01. 16..
  93.  */
  94.  
  95. public class Player extends Creatures {
  96.  
  97.     private int healPower;
  98.     private boolean lucky = false;
  99.     private int choice;
  100.  
  101.     public Player(int hp, int attackPower, String name, int healPower, boolean lucky, int choice) {
  102.         super(hp, attackPower, name);
  103.         this.healPower = healPower;
  104.         this.lucky = lucky;
  105.     }
  106.  
  107.     public int getHealPower() {
  108.         return healPower;
  109.     }
  110.  
  111.     public void setHealPower(int healPower) {
  112.         this.healPower = healPower;
  113.     }
  114.  
  115.     public boolean isLucky() {
  116.         return lucky;
  117.     }
  118.  
  119.     public void setLucky(boolean lucky) {
  120.         this.lucky = lucky;
  121.     }
  122.  
  123.     Player player1 = new Player(300, 50, "Drizzt", 75, false, 0);
  124.  
  125. }
  126.  
  127. package com.attila2;
  128.  
  129. import java.util.Scanner;
  130.  
  131. /**
  132.  * Created by Attila on 2018. 01. 17..
  133.  */
  134. public class Room {
  135.     int id;
  136.     int choice;
  137.     Scanner sc = new Scanner(System.in);
  138.  
  139.     public int getChoice() {
  140.         return choice;
  141.     }
  142.  
  143.     public void setChoice(int choice) {
  144.         this.choice = choice;
  145.     }
  146.  
  147.  
  148.     public Room(int id) {
  149.         this.id = id;
  150.     }
  151.  
  152.     public int getId() {
  153.         return id;
  154.     }
  155.  
  156.     public void setId(int id) {
  157.         this.id = id;
  158.     }
  159.  
  160.     public void plot1() {
  161.  
  162.         int optAmount = 2;
  163.         System.out.println("You wake up in a dark room that smells of decay. The last thing you can remember is" +
  164.                 "\n that you had a few too many beers in the tavern again." +
  165.                 "\n After looking around the room, you see an axe on top of a table in a corner." +
  166.                 "\n It seems a bit suspicious to you, but it might prove useful if this place is really" +
  167.                 "\n as dangerous as it looks...");
  168.         System.out.println();
  169.         System.out.println("What will you do?" +
  170.                 "\n1, Take the axe" +
  171.                 "\n2, Just leave it there, you are not good in melee combat anyway...");
  172.  
  173.         while (sc.next() != "1" || sc.next() != "2")
  174.             System.out.println("Invalid input. Please type in a number between 1 and " + optAmount + " !");
  175.  
  176.  
  177.         choice = sc.nextInt();
  178.  
  179.         if (choice == 1)
  180.             System.out.println(player1.getHealPower);
  181. //        Another access issue here...
  182.  
  183.  
  184.     }
  185. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Diminutive Gibbon java 8 Months ago.