Story Manager - How to Make a Text Based Adventure Game with Multiple Classes in Java

Поделиться
HTML-код
  • Опубликовано: 24 окт 2024

Комментарии • 42

  • @polymathempire2782
    @polymathempire2782 6 лет назад +4

    Very cool, its so fun to develop such games and to see others do it! :)

  • @antonserjogin4915
    @antonserjogin4915 Год назад

    Thank you for the awesome tutorials, RyiSnow. This has been an immense help in grasping the concepts of OOP and GUI. どうもありがとうございました。

  • @Thebigtc
    @Thebigtc 5 месяцев назад

    4:15 Interesting that he caught this. When I was following this tutorial, I noticed this earlier, when he neglected the fourth position because it was null by default. However, it's worth noting that if the player has already entered another area with four buttons, and the value of that button was not null, then returned to the town gate, the program would not realize that the fourth function was meant to be blank. Upon not recognizing the String in a case, it would revert to the default, which would cause an issue. To avoid this, I would recommend always setting unused nextPosition variables to null, or "". 😇

  • @ankitg6454
    @ankitg6454 Год назад

    awesome series. I am beginning to get a bit more comfortable with OOP because of it

  • @nathanmelville511
    @nathanmelville511 5 лет назад +3

    this is fantastic and I love you

    • @nathanmelville511
      @nathanmelville511 5 лет назад

      Dumb question, but would it be possible to make multiple "Story" files? So like in one .java file I have the Town Gate, and then in a different .java I have the forest, etc.? Sorry if that makes no sense :p

  • @fredericklin3620
    @fredericklin3620 Год назад

    Hello, @RyiSnow I am trying this tutorial and followed up until 9:55 and then trying the talk to the guard button but it doesn't work for me, I've exactly followed the video but it still doesn't work.

  • @jodi-anncurrie9320
    @jodi-anncurrie9320 2 года назад

    Hi, only my start buttons work when I click. I'm not sure what the problem

  • @Thebigtc
    @Thebigtc 5 месяцев назад

    If you're looking to randomize the damage the guard does, this is what I did.
    Random random = new Random();
    int guardDamage = random.nextInt(5)+1;
    ^^

  • @prois5999
    @prois5999 3 года назад +1

    How can I stop it from being editable ? So like, when I run the Programm I can erase the text or change it. How can I fix this ?

    • @RyiSnow
      @RyiSnow  3 года назад +2

      You can change the setting of JTextArea like this: mainTextArea.setEditable(false);

    • @prois5999
      @prois5999 3 года назад +1

      @@RyiSnow Okay thank you so much :) Loved your videos!!!!

    • @RyiSnow
      @RyiSnow  3 года назад +2

      No problem and good luck!

  • @davidl6892
    @davidl6892 3 года назад

    For some reason when my program runs and I click Talk to the Guard, then click the next arrow, it sends me straight to the Attack Guard scene instead of the town gate. I cannot go back to town gate once I've clicked any other option. Any ideas as to why?

    • @RyiSnow
      @RyiSnow  3 года назад +1

      Maybe you forgot to write "break" in the switch statement?

    • @davidl6892
      @davidl6892 3 года назад

      @@RyiSnow Yep, I just looked, thanks for your help, great tutorials!

  • @KamilZegarlicki
    @KamilZegarlicki 4 года назад

    Hello, is it possible to set two different random outcomes for one event; for example: "if you click "go south", then you loose 2hp, otherwise you gain 2 hp"? I tried this method, but i don't know how to determine position in such case:
    double x = 5;
    double y = 10;
    if (x == 5) getRandomIntegerBetweenRange(5,10);
    do {
    player.hp = - 5;
    ui.mainTextArea.setText("(loose 5 hp)");
    game.nextposition1 = ">" ?
    } while (x == 5);
    if (y == 10) getRandomIntegerBetweenRange(5,10);
    do {
    player.hp = + 5;
    ui.mainTextArea.setText("(gain 5 hp)");
    } while (y == 10);
    Method works, but messes up choices. Is it possible to fix it?

    • @RyiSnow
      @RyiSnow  4 года назад

      If you want to subtract 5 from player's hp, it would be:
      player.hp -=5;
      (not =-5;)
      you can also type as: player.hp = player.hp - 5;
      Also, if you want to pick up a random number, you can also type like this:
      int num = new java.util.Random().nextInt(100)+1; // This draws a random number between 1 to 100;
      if(num =31){
      player.hp +=5;
      }
      In this case, the rate that player's hp decreases is 30% and the rate that player's hp increase is 70%.

    • @KamilZegarlicki
      @KamilZegarlicki 4 года назад

      @@RyiSnow Thank You, I was able to implement my idea today after little consideration. But I wouldn't do that without your tutorial, so all glory goes to You.

  • @LazPaz101
    @LazPaz101 5 лет назад

    great video, thank you, but I'm trying to replicate/modify this for learning purposes and when I try to implement the townGate() method, it has no effect. Any idea why that might be?

    • @RyiSnow
      @RyiSnow  5 лет назад

      Could you be more specific? I need more detail to determine what the problem is.

    • @LazPaz101
      @LazPaz101 5 лет назад

      @@RyiSnow Thanks for your quick reply. I'm actually attempting to turn your adventure game into a home tour where the "player/user" can go to various rooms in the house as they wish, so I don't need the health or weapons, but I don't see why leaving out the hp, for example, would make it so that the townGate() method doesn't implement. When I say it doesn't implement, I mean that the game screen does not update, it remains with the generic text saying "This is the main text area" and the 4 choice buttons even though I followed the video and expect the game screen main text to change as well as the button names. Any idea what could be going wrong?

    • @RyiSnow
      @RyiSnow  5 лет назад

      @@LazPaz101 Sounds like ChoiceHandler and the "selectPosition" in Story class is not coordinated properly. If I can see your code, I can test it in my environment though.

    • @LazPaz101
      @LazPaz101 5 лет назад

      @@RyiSnow
      my game package is your "package 01"
      package game;
      import fixtures.Room;
      public class Story {
      Game game;
      Player player;
      RoomManager rm;
      Player1 player1 = new Player1();

      public Story(Game g, Player userInterface, RoomManager rManager) {
      game = g;
      player = userInterface;
      rm = rManager;
      }
      public void defaultSetup() {


      player1.currentRoom = new Room();
      player.titleNameLabel.setText(player1.currentRoom.name);
      }
      public void selectPosition(String nextPosition) {
      switch(nextPosition) {
      case "townGate": townGate(); break;
      case "livingRoom": livingRoom(); break;
      case "masterSuite": masterSuite(); break;
      case "kitchen": kitchen(); break;
      }
      }
      public void townGate() {
      player.mainTextArea.setText("Welcome to this beautiful home overlooking the Pacific Ocean. If you don't buy it, then I will :)!
      Which room would you like to see first?");
      player.choice1.setText("The Living Room");
      player.choice2.setText("The Master Suite");
      player.choice3.setText("The Kitchen");
      player.choice4.setText("");


      game.nextPosition1 = "livingRoom";
      game.nextPosition2 = "masterSuite";
      game.nextPosition3 = "kitchen";


      }
      public void livingRoom() {

      player.mainTextArea.setText("Isn't this living room beautiful? :)!
      Which room would you like to see next?");
      player.choice1.setText(">");
      player.choice2.setText("");
      player.choice3.setText("");
      player.choice4.setText("");


      game.nextPosition1 = "masterSuite";
      game.nextPosition2 = "";
      game.nextPosition3 = "";

      }

      public void masterSuite() {
      player.mainTextArea.setText("Isn't this Master Suite beautiful? Which room would you like to see next?");
      player.choice1.setText("kitchen");
      player.choice2.setText("");
      player.choice3.setText("");
      player.choice4.setText("");


      game.nextPosition1 = "kitchen";
      game.nextPosition2 = "";
      game.nextPosition3 = "";


      }

      public void kitchen() {
      player.mainTextArea.setText("Isn't this kitchen beautiful? So do you want to buy the house?");
      player.choice1.setText("townGate");
      player.choice2.setText("");
      player.choice3.setText("");
      player.choice4.setText("");


      game.nextPosition1 = "";
      game.nextPosition2 = "";
      game.nextPosition3 = "";

      }}

    • @LazPaz101
      @LazPaz101 5 лет назад

      @@RyiSnow package game;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      public class Game {

      ChoiceHandler cHandler = new ChoiceHandler();
      Player player = new Player();
      RoomManager rm = new RoomManager(player);
      Story story = new Story(this, player, rm);
      String nextPosition1, nextPosition2, nextPosition3, nextPostion4;

      public static void main(String[] args) {

      new Game();
      }

      public Game() {

      player.createPlayer(cHandler);
      story.defaultSetup();
      rm.showTitleScreen();

      }

      public class ChoiceHandler implements ActionListener{

      public void actionPerformed(ActionEvent event) {

      String yourChoice = event.getActionCommand();

      switch(yourChoice) {
      case "start": rm.titleRoom(); story.townGate(); break;
      case "c1": story.selectPosition(nextPosition1); break;
      case "c2": story.selectPosition(nextPosition2);break;
      case "c3": story.selectPosition(nextPosition3);break;
      case "c4": story.selectPosition(nextPostion4);break;
      }

      }
      }
      }

  • @davymercado4669
    @davymercado4669 11 месяцев назад

    how to make a back button tho?

    • @Thebigtc
      @Thebigtc 5 месяцев назад

      This is an interesting challenge to approach. If you're referring to a button that always takes you to the last encounter, it would really vary. If this button also reversed combat moves, it could be dangerous. (RNG exploits.) I would just create a variable to log the previous state, then return to it. However, keep in mind where it should and shouldn't be available to the player.