🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Need direction java text based game

Started by
1 comment, last by slshustle110@gmail.com 2 years, 10 months ago

Hi All,

Making a text game but need some guidance on how to proceed. It works but want help with the best way forward for understanding user input and interaction with the game. I have googled parser but cant find any good tutorials. Eventually i would like to move around like a map but this is what i can manage at the moment with my basic skill of java.

Any sort of advice would be good because the way i see it i can now just bash out a hundered different stories and iterate through my loops and waiting for the user to jag common commands like “look” and “open door”. not sure if that is improving my coding skill though :S

package main;

import java.util.Random;

import java.util.Scanner;

public class Main {

static String player = "";

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

Random random = new Random();

System.out.println("You awake from a daze with the taste of ash and gin on your breath. "

+ "\nLooking around you see your in a dimly lit room with a flickering red neon light pulsating overhead"

+ "\nAs you stare around you notice a mirror infront of you."

+ "\nyou gingerly step up, shakey on your feet you look into a mirror"

+ "\nyou are dressed in your work cloths from the night before and your name badge reads");

String input = in.nextLine();

player = input;

System.out.println("You tell yourself, woah man what happened,"

+ "\nyou cant keep doing this to yourself"

+ "\n" + player + " you gotta get your shit together" );

boolean running1 = true;

Room1:

while(running1) {

System.out.println("Your in a room with 4 walls, a light switch, a bed, a door");

String input1 = in.nextLine();

if(input1.equals("look")){

System.out.println("gee that bed looks nice");

continue Room1;

}

else if (input1.equals("open door")) {

System.out.println("the door opened");

running1 = false;

break;

}

else if (input1.equals("use bed")) {

System.out.println("now is not the time for sleeping");

continue Room1;

}

else if (input1.equals("kick bed")) {

System.out.println("one way to break a toe");

continue Room1;

}

else {

System.out.println("that wont work");

continue Room1;

}

}

System.out.println("Welcome to the rest of the game");

boolean running2 = true;

Room2:

while(running2) {

System.out.println("A new room");

String input1 = in.nextLine();

if(input1.equals("look")){

System.out.println("not very exciting");

continue Room2;

}

}

}

}

Advertisement

I would suggest you watch this approx 1 hour playlist to understand how a text based game is structured. He uses Java so you can even get code snippets to use.

https://www.youtube.com/watch?v=V1CGof9PdMI&list=PLZHx5heVfgEvT5BD8TgLmGrr-V64pX7MD&index=1

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Thanks fleabay,

Your help in my game creation adventure is much appreciated.

This topic is closed to new replies.

Advertisement