Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Is this a good way to start making text adventures?


  • Please log in to reply
6 replies to this topic

#1 illusionust

illusionust

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:11:28 PM

Posted 03 July 2012 - 08:47 AM

So, here is a mini text adventure written by me.....As described, you must go in a sqaure. MY question, is this a good way to START making text adventures? Also what should I add/delete/change? P.S. I'm really young so excuse my bad(Semantically incorrrect?) or unconventional programming. Anyway, here it is....

import java.util.Scanner;

public class newSquare {
static Scanner input = new Scanner(System.in);
static String next, dir;

public static void main(String[] args){
intro();
}

public static void intro(){
System.out.println("Your job is to go in a sqaure. The commands are: right and left.");
System.out.println("If you go in the wrong way, you will be told and the character will not move.");
System.out.println("Once you have read these, type continue");
introCalculation();
}

public static void introCalculation(){
next = input.next();
if(next.equals("continue")){
first();
}else{intro();}
}

public static void first(){
System.out.println("You wake up and appear to be in a long corridor. You can't \n see where it leads, but will have to try to get out. Which way do you go?");
dir = input.next();
if(dir.equals("right")){
second();
}else if(dir.equals("left")){
System.out.println("Try again?");
first();
}else{System.out.println("Try again?");
first();}
}


public static void second(){
System.out.println("You successfully walked through without hitting any walls. \n Which way now?");
dir = input.next();
if(dir.equals("right")){
third();
}else if(dir.equals("left")){
System.out.println("Try Again");
second();
}else{System.out.println("BAD COMMAND! Try Again.");
second();}
}


public static void third(){
System.out.println("That's two so far. You still can't see much of anything except for \n some light coming in. Maybe try right again?");
dir = input.next();
if(dir.equals("right")){
fourth();
}else if(dir.equals("left")){
System.out.println("Try Again");
third();
}else{System.out.println("BAD COMMAND! Try Again.");
third();}
}

public static void fourth(){
System.out.println("You see a strong light coming from a certain direction. \n I wonder which one it is. Right or Left?");
dir = input.next();
if(dir.equals("right")){
completion();
}else if(dir.equals("left")){
System.out.println("Try Again");
fourth();
}else{System.out.println("BAD COMMAND! Try Again.");
fourth();}
}

public static void completion(){
System.out.println("You made it out! Horray for you!");
System.out.println("Type restart or finish to continue");
String end;
end = input.next();
if(end.equals("finish")){
System.exit(0);
}else if(end.equals("restart")){
intro();
}
}


}


Edited by illusionust, 03 July 2012 - 08:51 AM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:28 PM

Posted 03 July 2012 - 04:04 PM

I am not sure what you mean by 'a good way to start'? Do you mean from a programming standpoint, a software engineering standpoint, or a creative standpoint?

#3 Fsmv

Fsmv

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Ohio
  • Local time:11:28 PM

Posted 03 July 2012 - 10:10 PM

It seems to me that your intent isn't necessarily to make a text-based adventure but to learn to program, otherwise you would have used a text-based-game creator and just provided the story. On that assumption I'll try to offer a some help in improving your skill as a programmer.

This is a great start. You may have noticed that the way you're coding so far the computer just runs straight down the file. The way you're using functions right now, they should be replaced with more simple control structures like loops. This could all be done in the main function and it would be easier to read and understand as well as maintain or add to. Revising what you have to fit into one function would be a great next step. To do that you'll need to read up on loops, there's one type that will easily replace all of your function calls, however you really should look into and know how to use all of the others as well. Maybe you can even work each type of loop into your current story as well so you can get used to them.

Once you've done that you'll notice that the game is basically forced to follow a very linear path, the whole game will be directed very carefully by you and you'll have to print an error every time the user tries to turn the wrong way. To get around this, and make the game feel more like a world than a hallway, the program has to be written more generally which means it has to get more complicated. To do that you'll have to make a few leaps in knowledge so I'd suggest that you attempt a few intermediate programs before trying to go for a general approach to the text-based adventure. You'll first need to learn about File I/O, proper function design, the difference between static and instance variables and finally object oriented class design and class inheritance.

All of this will take a long time to learn and will take a lot of hard work but, as you may already be able to tell, learning to program is fun and rewarding. If you want me to explain anything more or you have any questions I'd be glad to help.

Finally, welcome to the world of computer science.

#4 illusionust

illusionust
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:11:28 PM

Posted 04 July 2012 - 07:11 AM

Thanks FSMV! I thought about using loops but couldn't figure out how....maybe you could do one of my functions! Thanks anyway! -Illusionust

Edited by illusionust, 04 July 2012 - 09:14 AM.


#5 Fsmv

Fsmv

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Ohio
  • Local time:11:28 PM

Posted 04 July 2012 - 11:45 AM

What you need is the do-while loop.

Instead of the intro and introCalculation methods, for example, you could do this:
Spoiler

Edited by Fsmv, 04 July 2012 - 11:46 AM.


#6 illusionust

illusionust
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:11:28 PM

Posted 04 July 2012 - 03:26 PM

Ohhhhhhhhh! Thanks soooo much! I didn't know you could do that "while(!next..." I guess I just never thought using the not equals operator like that.. Oh well. You have taught me a valuable lesson, good sir! I wish more people in the world(not just programmers) were like you! Also, what did you mean by intermediate projects? Maybe another example?

Edited by illusionust, 04 July 2012 - 03:27 PM.


#7 Fsmv

Fsmv

  • Members
  • 8 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Ohio
  • Local time:11:28 PM

Posted 05 July 2012 - 05:15 PM

Ohhhhhhhhh! Thanks soooo much! I didn't know you could do that "while(!next..." I guess I just never thought using the not equals operator like that.. Oh well. You have taught me a valuable lesson, good sir! I wish more people in the world(not just programmers) were like you! Also, what did you mean by intermediate projects? Maybe another example?


As for intermediate projects, I was thinking something like these challenges at cplusplus.com. They can all be done in Java instead of C++ and although the posted solutions are in C++ you should have little problem understanding the code and they should be able to help you if you have problems. I did most of these back in 2009 and I felt like they really helped me learn the fundamentals of object oriented programming.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users