• Advertisement

Archived

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

Text RPG....

This topic is 5192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Since my last post, I have begun work on my text RPG... it isn't much yet, and I am sure that my coding style is awful (or something)... I have run into a problem, which is input... my input checks each character on a key press... maybe I need to find a new way to do input... please suggest
#include <iostream>
#include <windows.h>
#include <conio.h>
#include "MyConsole.h"



int main()
{
	
	char Pressed;
	bool notExit = true;
	Console myConsole;

	int x = 10;
	int y = 10;
	myConsole.clearScreen(' ');
	std::cout << "Welcome to the adventure, press any key" << std::endl;
	while(notExit)
	{
		
		
		if(_getch()=='q')
			notExit=false;

		myConsole.setPos(0,0);
		std::cout << "Checked Quit";
		if(_getch()=='w')
		{
			myConsole.setPos(x,y);
			std::cout<<" ";
			y--;
			myConsole.setPos(x,y);
			std::cout<<"x";
		}
		myConsole.setPos(0,0);
		std::cout << "Checked w";
		if(_getch()=='s')
		{
			myConsole.setPos(x,y);
			std::cout<<" ";
			y++;
			myConsole.setPos(x,y);
			std::cout<<"x";
		}
		myConsole.setPos(0,0);
		std::cout << "Checked s";
		if(_getch()=='a')
		{
			myConsole.setPos(x,y);
			std::cout<<" ";
			x--;
			myConsole.setPos(x,y);
			std::cout<<"x";
		}
		myConsole.setPos(0,0);
		std::cout << "Checked a";
		if(_getch()=='d')
		{
			myConsole.setPos(x,y);
			std::cout<<" ";
			x++;
			myConsole.setPos(x,y);
			std::cout<<"x";
		}
		myConsole.setPos(0,0);
		std::cout << "Checked d";
		


	}
	system("PAUSE");
}

I think myConsole is self explantory, but if not here is its definition (i made it a LONG time ago...) EDIT: ARRRGH STUPID FORUM...ATE MY DAMNED SOURCE TAG!
   
class Console
{
private:
	//Nadda

public:
	bool clearScreen(char fillLetter);
	bool setPos(int x, int y);
	bool setColor(int color);
	bool init();


};

It is pretty basic (init does nothing... I put it there just in case) Edit... ahh what the hay, I will post myConsole definition as well... EDIT: ATE THIS DAMNED SOURCE TAG AS WELL
   
#include <iostream>
#include <cmath>
#include <string>
#include <windows.h>
#include <windowsx.h>
#include "MyConsole.h"


bool Console::clearScreen(char fillLetter)
{
  COORD coordScreen = { 0, 0 }; 
  DWORD cCharsWritten; 
  CONSOLE_SCREEN_BUFFER_INFO csbi; 
  DWORD dwConSize; 
  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 
  
  GetConsoleScreenBufferInfo(hConsole, &csbi); 
  dwConSize = csbi.dwSize.X * csbi.dwSize.Y; 
  FillConsoleOutputCharacter(hConsole, TEXT(fillLetter),
                             dwConSize, 
                             coordScreen,
                             &cCharsWritten); 
  GetConsoleScreenBufferInfo(hConsole, &csbi); 
  FillConsoleOutputAttribute(hConsole,
                             csbi.wAttributes,
                             dwConSize,
                             coordScreen,
                             &cCharsWritten); 
  SetConsoleCursorPosition(hConsole, coordScreen); 


  	return true;
}

bool Console::setPos(int x, int y)
{
  COORD point;
  point.X = x; point.Y = y;
  SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),
                           point);
	return true;
}

bool Console::setColor(int color)
{
	
  switch (color)
  {
  case 0:    // White on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                        FOREGROUND_INTENSITY | FOREGROUND_RED |
                        FOREGROUND_GREEN | FOREGROUND_BLUE);
    break;
  case 1:    // Red on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                         FOREGROUND_INTENSITY | FOREGROUND_RED);
    break;
  case 2:    // Green on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                      FOREGROUND_INTENSITY | FOREGROUND_GREEN);
    break;
  case 3:    // Yellow on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                      FOREGROUND_INTENSITY | FOREGROUND_RED |
                      FOREGROUND_GREEN);
    break;
  case 4:    // Blue on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                      FOREGROUND_INTENSITY | FOREGROUND_BLUE);
    break;
  case 5:    // Magenta on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                     FOREGROUND_INTENSITY | FOREGROUND_RED |
                     FOREGROUND_BLUE);
    break;
  case 6:    // Cyan on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                    FOREGROUND_INTENSITY | FOREGROUND_GREEN |
                    FOREGROUND_BLUE);
    break;
  case 7:    // Black on Gray

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                  BACKGROUND_INTENSITY | BACKGROUND_INTENSITY);
    break;
  case 8:    // Black on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                  BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                  BACKGROUND_RED | BACKGROUND_GREEN |
                  BACKGROUND_BLUE);
    break;
  case 9:    // Red on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                  BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                  BACKGROUND_RED | BACKGROUND_GREEN |
                  BACKGROUND_BLUE |
      FOREGROUND_RED);
    break;
  case 10:    // Green on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                 BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                 BACKGROUND_RED | BACKGROUND_GREEN |
                 BACKGROUND_BLUE | FOREGROUND_GREEN);
    break;
  case 11:    // Yellow on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                 BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                 BACKGROUND_RED | BACKGROUND_GREEN |
                 BACKGROUND_BLUE | FOREGROUND_RED |
                 FOREGROUND_GREEN);
    break;
  case 12:    // Blue on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                 BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                 BACKGROUND_RED | BACKGROUND_GREEN |
                 BACKGROUND_BLUE | FOREGROUND_BLUE);
    break;
  case 13:    // Magenta on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                 BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                 BACKGROUND_RED | BACKGROUND_GREEN |
                 BACKGROUND_BLUE | FOREGROUND_RED |
                 FOREGROUND_BLUE);
    break;
  case 14:    // Cyan on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                 BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                 BACKGROUND_RED | BACKGROUND_GREEN |
                 BACKGROUND_BLUE | FOREGROUND_GREEN |
                 FOREGROUND_BLUE);
    break;
  case 15:    // White on White

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                BACKGROUND_INTENSITY | FOREGROUND_INTENSITY |
                BACKGROUND_RED | BACKGROUND_GREEN |
                BACKGROUND_BLUE | FOREGROUND_RED |
                FOREGROUND_GREEN | FOREGROUND_BLUE);
    break;
  default :    // White on Black

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                FOREGROUND_INTENSITY | FOREGROUND_RED |
                FOREGROUND_GREEN | FOREGROUND_BLUE);
    break;
  }

  
  return true;
}



Feel free to use it, although you probably won't want to Anyways, in case I didn't explain clear enough... when I press one key (any key) it increments through my _getch()'s.. I guess getch waits until it gets a char, I figured it would return ' if no char was pressed...

It's Maxd Gaming, put in an underscore and I will beat you with a rubber ducky! { My Site! - Banner } { My Site! - One time popup }{ My .Net Information }{ A upcoming space RTS codenamed Gruntacktica . }{ . }
Not following the new trend: Looky here mommy! No cow pic!
Phoe's Forums [edited by - Maxd Gaming on February 5, 2004 9:51:46 PM] [edited by - Maxd Gaming on February 5, 2004 9:53:13 PM]
Advertisement
For input for a Text RPG I think you should use language text parsing or something like that. It''s in TOTWGPG near the back of the book.

It will take in what ever the user says and try to understand it.

EXAMPLE:

USER: Move my character north.

The computer parses the sentence and under stands that the user wants to move north.

I’ll post more when I can get at my book.


"Do not flame people you don''t know in a public forum. Only amateurs do that. Professionals in the industry know they will run into each other over and over. The person you flame this year may the person you want to do business with next year. Don''t burn your bridges," (Diana Gruber, http://www.makegames.com/chapt6.html).

Share this post


Link to post
Share on other sites
If you want it to be real time and interactive, then look at the function kbhit() and put it in a while loop.


while(game_running) {
move_monsters();
check_for_encounter();
if(kbhit()) {
ch = getch();
.
.
.
}
}




First make it work, then make it fast. --Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post


Link to post
Share on other sites
im having the same problems in my text RPG... with cin you have to press enter, and im having a bunch of bugs with getche(). id like to know if you ever figured out an answer to this problem of taking input from a user.and i dont want anything complicated like a text parsar or whatever, im just doing something simple like asking the user which kind of attack to do press 1 2 or 3, then those 3 each have sub-menus. using a getch() only the first part works and the submenus dont kick in. you press a key and nothing happends.i gues im stuck with using cin for now unless someone can help me




[edited by - graveyard filla on February 6, 2004 5:39:37 PM]

Share this post


Link to post
Share on other sites

Weren''t you just gathering a team? Next time you post in Help Wanted, I''ll reply with a link to this thread.

.bas

[sPiKie] mmorpg isnt hard in vb

Share this post


Link to post
Share on other sites
quote:
Original post by bastardos

Weren''t you just gathering a team? Next time you post in Help Wanted, I''ll reply with a link to this thread.

.bas

[sPiKie] mmorpg isnt hard in vb



That is for something totally different... I am learning to program, I wasn''t programmer in that thread...





It''s Maxd Gaming, put in an underscore and I will beat you with a rubber ducky!
{ My Site! - Banner } { My Site! - One time popup }{ My .Net Information }{ A upcoming space RTS codenamed Gruntacktica . }{ . }

Not following the new trend:
Looky here mommy! No cow pic!


Phoe''s Forums

  • Advertisement