• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ZorkLover23

Zork like text input

9 posts in this topic

Hey I have just started programming not so long ago and I was thinking about making a Zork like game but I keep getting stuck. I really want it to have text input like Zork so the player can type for example "Hello" and the game will respond with "Hi" or "Greetings". can any one help me with this Thanks.
0

Share this post


Link to post
Share on other sites
Well, the actual implementation depends on the language you are using, but the basic idea is:
[code]if(playerInput == "hello")
{
Display("Greetings!");
}
else if(playerInput == "goodbye")
{
Display("Cya later!");
}
else
{
Display("I don't recognize that sentence.");
}
[/code]

To further expand on it, you could add verbs and nouns:
[code]
Words = BreakIntoWords(playerInput);
if(FirstWord == "Use")
{
if(SecondWord == "Banana" AND PlayerHas("banana"))
{
Display("You threw the banana at the Rhino in disgust!")
}
else if(SecondWord == "Apple" AND PlayerHas("apple"))
{
Display("You fed the Rhino your apple, and he munches on it thoughtfully.")
Display("Rhino: 'Mmm, that was delicious. Here, you can have my extra backup horn as thanks.")

GivePlayer("Rhino Horn");
Display("Dun dun dun duhhh! You got the Rhino Horn! You can now go gore some Kangaroos.")
}
else if(SecondWord == "")
{
Display("What do you want to use?")
}
else
{
Display("You don't have any " + SecondWord)
}
}
else if(FirstWord == "Take")
{
if(ExistsInRoom(SecondWord))
{
Display("You take the " + SecondWord)
GivePlayer(SecondWord);
RemoveFromRoom(SecondWord);
}
else if(SecondWord == "")
{
Display("What do you want to take?")
}
else
{
Display("You can't take any " + SecondWord)
}
}
else
{
Display("I don't know what you said. Could you try: 'Use', 'Take', 'Look', 'Go', or 'Talk'?")
}[/code]

[b]Required knowledge:[/b][list]
[*]'if()' statements
[*]'if else()' statements
[*]'else' statements
[*]'while' loops
[*]What kind of food rhinos like
[*]Strings
[*]String comparison
[/list]
[b]Tips:[/b][list]
[*]If you convert player input to lowercase before comparing it, you only have to check for "the word", and you automaticly handle "The Word", "THE WORD", and "ThE WoRd".
[*]If you break things into small functions, you can make your program more stable, easy to read, easy to expand, and also save alot of typing.
[*]Any time you find yourself copying and pasting your code into multiple places, turn it into a function instead.
[*]If you want to do something, and find out that you can't, instead of getting frustrated, ask yourself how you can use the limitation to improve your game, or how you can work around the limitation.
[*]A quick google search shows that Rhinos actually do like apples. Odd.
[*]Quick google searches can also answer most problems you encounter - but make sure you actually [i]understand[/i] the answer, don't just copy and paste the answer.
[*]A sense of humor in your game might help you feel better about the lack of graphics.
[*]Everyone knows that mules have a [i]terrific[/i] sense of humor... which is why they make such great game designers.
[*]Using graph paper (or plain computer paper and a ruler) map out the rooms, location of items, and the required order of getting/using each item, before you actually start adding anything other than test rooms.
[*]Hard code everything if you have to. Use global variables if you need to.
[*]Aim small for your first game (20 rooms top). For your [u]second[/u] game, figure out how to load text files, and make rooms, items, npcs, and the connections between rooms be as much as possible controlled by files and not hard-coded. Also try to not use a single global variable. Consider it a challenge or puzzle to solve.
[/list]
2

Share this post


Link to post
Share on other sites
I'd actually do not direct string comparison. It's easy in the beginning, but will grow too fast to be managable.

Back then the programmer had a list of verb strings (with index so different verbs with the same id existed) and list of object strings.

Then you would parse the input string, split for spaces and try to find all the single words in the lists. The puzzle logic would then analyse the verb and object indices and act accordingly.
If you want to get fancy allow for a secondary object (put xxx in yyy) and fill words that would be discardid ("the", "in", etc.).


Steps:
* Split a string by a separator (space)
* Handle string to index maps (std::map<std::string,int>) Edited by Endurion
1

Share this post


Link to post
Share on other sites
If you could use .net i'm sure a dictionary would work fine as well. :) http://msdn.microsoft.com/en-us/library/xfhwa508.aspx

To me, if you're using C++ at first I would say string comparison as well. (From if this == this) or possibly with an array? Just store an array of commands for a subset of the program. (ie. Attacking, moving, talking, etc)
0

Share this post


Link to post
Share on other sites
[quote name='Endurion' timestamp='1347003698' post='4977518']
I'd actually do not direct string comparison. It's easy in the beginning, but will grow too fast to be managable.
[/quote]
I wouldn't use it either, but I don't know the OP's skill level, and am guessing from his post he hasn't yet mastered basic comparison. I could be wrong though! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites
[quote name='Servant of the Lord' timestamp='1347036202' post='4977712']
[quote name='Endurion' timestamp='1347003698' post='4977518']
I'd actually do not direct string comparison. It's easy in the beginning, but will grow too fast to be managable.
[/quote]
I wouldn't use it either, but I don't know the OP's skill level, and am guessing from his post he hasn't yet mastered basic comparison. I could be wrong though! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

Instead of direct comparison what should be used? Because that's what pops into my head first when i think of string and comparing.
0

Share this post


Link to post
Share on other sites
If just making interactive fiction games (text adventures) is your goal, there are a few good game-makers available, and pretty dang cool.

[url="http://inform7.com/"]http://inform7.com/[/url] Inform is a good one
[url="http://www.tads.org/"]http://www.tads.org/[/url] I personally like TADS even better
[url="http://www.adrift.org.uk/cgi/adrift.cgi"]http://www.adrift.org.uk/cgi/adrift.cgi[/url] ADRIFT is a common one as well.

Take a look at them, and see if it fits what you're looking for.

If you want to do it specifically in C++, then these may at least give you an idea of how to move forward.

Good luck, and have fun!
1

Share this post


Link to post
Share on other sites
Essentially you're trying to write something that parses English (or whatever language), which is challenging as human speech is generally not strictly rule-based and is sometimes ambiguous. Generally assume that there will be limitations on your program's ability to parse text, so you will have to draw a line somewhere.

On to practicalities, the guys here have suggested some good stuff. The solution depends upon your programming skill and whether you just wan results or want to do it yourself. The interactive fiction engines mentioned do a pretty good job of interpreting text.

If you want to write your own you can do what the guys mentioned above. Or you could take the more complex route and create a grammar and parse the text into trees based on the grammars and see which fits best, for example the rules "[verb] [noun phrase]" (e.g. "go north") and "[noun]" (e.g. "north"). If you want to be really smart, interpret the nouns (and maybe even verbs) in a context-sensitive way, e.g. if they say "pick up the sword" interpret sword as a nearby sword that they are not holding. You can rule out interpretations if there are no matching nouns in the context.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0