Text adventure game [HELP]

Discussion in 'Indie Basics' started by Sir8BitHero, Jan 29, 2013.

  1. Sir8BitHero

    Sir8BitHero New Member

    Joined:
    Nov 10, 2012
    Messages:
    2
    Likes Received:
    0
    All of this was made with eclipse.

    So this is one of the first programs I've made, I have been using a guide but it was very vague and it ended before telling me how to create a second option.
    My problem is when the player answers the first question in the game the second question appears, but the player can't type anything into the console anymore.

    My code:

    please keep in mind I'm new to coding in general so if you could keep the answers as easy to understand as possible I'd appreciate it.
     
  2. Shaz

    Moderator Original Member

    Joined:
    Feb 9, 2006
    Messages:
    405
    Likes Received:
    0
    Where is the loop to tell it to get user input more than once?
     
  3. nbkolchin

    nbkolchin New Member

    Joined:
    Nov 28, 2006
    Messages:
    19
    Likes Received:
    0
    Offtopic: Why not use inform or TADS for text game development?

    You probably miss 'a = s.nextInt()' before second switch statement.
     
  4. shay.yizhak

    shay.yizhak New Member

    Joined:
    Feb 3, 2013
    Messages:
    27
    Likes Received:
    0
    This is how the code should be:

    import java.util.Scanner;


    public class Kynarthain {
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    System.out.println("You awake in a burning forest and are presented with 3 items.");
    System.out.println("A Key, A Map and A Sword.");
    System.out.println("You only have time to choose which item, which item do you choose?\n\nOptions:\n1:The Key\n2:The Map\n3:The Sword");

    int a = s.nextInt();

    switch (a) {
    case 1:
    System.out.println("You grab the key and run as fast as you can away from the fire");
    System.out.println("Sadly their is a locked gate in your way but your key manages to unlock it");
    break;
    case 2:
    System.out.println("You grab the Map and run as fast as you can away from the fire");
    System.out.println("Using your map you notice there's a locked gate ahead, so you use the shortcut shown on your map");
    break;
    case 3:
    System.out.println("You grab the Sword and run as fast as you can away from the fire");
    System.out.println("Eventually you reach a locked gate, you make a desperate attempt to look for another way.");
    System.out.println("You find another gate but there's a demonic fiend guarding it.");
    System.out.println("You pull out your sword and with a swift blow it's gone.");
    System.out.println("You walk out of the burning forest unscathed.");
    break;
    }

    System.out.println("Eventually you end up at a fork in the road");
    System.out.println("You can either choose the Path of Dismay, or the Road of Broken Dreams\nOptions\n1:path of Dismay\n2:Road of Broken Dreams");

    int a = s.nextInt();

    switch (a) {
    case 1:
    System.out.println("1");
    break;
    case 2:
    System.out.println("2");
    break;
    }
    }
    }


    --However, this code hold many many bad coding practices. I would recommend reading a book about programming first.
     
  5. Arkadesh

    Original Member

    Joined:
    Apr 29, 2005
    Messages:
    86
    Likes Received:
    0
    If you're serious about writing a text adventure and not just treating it as a way to learn programming in general take a closer look at some specialized language like Inform. You'll avoid reinventing the wheel and focus on your game.
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer