Archived

This topic is now archived and is closed to further replies.

phil05

I got it going..

Recommended Posts

http://phil.webula.net/game.JPG You ask the NPC questions, and he responds to certain keywords you type in. Even if you type in ''swords'' and not ''sword'' he still recognizes it without any error checking. Here''s the source code. If any improvements can be made, lemme know Thanks for everyone helping me getting this going. If you''re familiar with Everquest, talking to NPC''s is almost the same here.
#include <iostream>
#include <string>

void armorer(std::string buffer);

int main()
{
	system("color 1f");

    std::string buffer;
    
	//Gets Player Input

	std::cout << "\nPlayer -> ";
	std::getline(std::cin,buffer);
	std::cin.ignore(1, ''\n'');
	
	armorer(buffer);
	

	return 0;
}

void armorer(std::string buffer)
{
	// Armorer

    if	(buffer.find("sword") != std::string::npos)	{
        std::cout << "Armorer -> Yes, I have one lying around here." << std::endl;
	}
	else if (buffer.find("cost") != std::string::npos) {	
		std::cout << "Armorer -> It''s 500 gold for the sword. Take it, or leave it." << std::endl;
	}
	else if (buffer.find("shield") != std::string::npos) {
		std::cout << "Armorer -> I surely do. Would you like to ''buy one'' today?" << std::endl;
	}
	else if (buffer.find("buy one") != std::string::npos) {
		std::cout << "Armorer -> That will be 300 gold." << std::endl;
	}
	else if (buffer.find("Hello") != std::string::npos) {
		std::cout << "Armorer -> Hello there. What can I do for you?" << std::endl;
	}
	else
		std::cout << "Armorer -> Excuse me?" << std::endl;


	main();
}


Share this post


Link to post
Share on other sites
New screenshot. I thought it was funny..

http://phil.webula.net/game3.JPG

[edited by - philvaira on March 22, 2004 2:31:35 AM]

Share this post


Link to post
Share on other sites
Thats some pretty good syntax recognition there... though id love it if you let some of us see how muc hwe could confuse it :-D
-Dan

Share this post


Link to post
Share on other sites