Thread: 2 Semi-Newbie Questions.

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    15

    Angry 2 Semi-Newbie Questions.

    Ok so I'm relatively new to C++, I'm writing a text-based RPG, similar to LoRD and running into a few problems.

    First off, I use getch(), to pause the program and wait for key presses at certain points. Now in 90% of the program, it works fine. But at a couple points it does not. I see no difference in the 2 places. Maybe you can help, here is an example:

    This Part Works:
    int newgame() //Starting a New Game
    {

    playermaxlife=50, playermaxmana=5, playercurrentlife=50, playercurrentmana=5, playerlevel=1, playerexperience=0, playergold=5000000, playerarmor=1, playerweapon=1;

    system("CLS");

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE),FOREGROUND_BLUE | FOREGROUND_INTENSITY);
    cout << "Welcome once again to Darkwood, " << playername << ".\n";
    cout << '\n';
    cout << "The town of Darkwood is in emmence danger.\n";
    cout << "The Dragon of Darkwood is terrorizing the town, and slaughtering innocents.\n";
    cout << "It is now you job to kill the Dragon, hopefully you will succeed, where so many have failed!\n";
    cout << '\n';
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE),FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    cout << "Hit Enter to go on...";
    getch();
    town();

    }

    This Part Does NOT:
    int theanimaltrail()
    {
    system("CLS");

    cout << "Check it out";
    cout << "Hit Enter to return...";
    getch();
    town();
    }

    Any Clue?

    Second:

    I need a variable (weaponname) to be given a value that is a string (the name of the weapon) how do I do this?

    All I wanna do is weaponname="a short sword"; but can't figure it out for the life of me.

    I need to be able to change it at will, hence it being a variable, the name will change.

    Thanx, for you help.
    Darkflame

    P.S. - Real quick. What's the RandomInteger function? I wanna do a random number between 1-6.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156

    2 Semi-Newbie Questions.

    I'm not having any problems with either getchar( )s, although I did get rid of town( ), and made playermaxlife=50, playermaxmana=5, ... ints. That should not have affected anything.

    For the second question I made an enum and a very stripped down class for getting you started. That is of course if I understood the question.



    Code:
    #include "stdafx.h"
    #include <cstring>
    #include <iostream>
    using std::string;
    using std::cout;
    using std::endl;
    
    
    enum WeaponType
    {
    	shortsword,
    	longsword,
    	mondosward
    };
    
    
    class CWeaponName
    {
    
    protected:
    
    	WeaponType      m_wt;
    	string                  m_sWeaponName;
    
    public:
    
    	CWeaponName( ) : m_wt(shortsword), m_sWeaponName( "" )
    	{}
    
    	const char * getweapon(  )
    	{
    		return m_sWeaponName.data( );
    	}
    
    	void setweapon( WeaponType wt )
    	{
    		switch( wt )
    		{
    			case shortsword:
    				m_wt = shortsword;
    				m_sWeaponName = "shortsword";
    				break;
    			case longsword:
    				m_wt = longsword;
    				m_sWeaponName = "mondosward";
    				break;
    			case mondosward:
    				m_wt = mondosward;
    				m_sWeaponName = "mondosward";
    				break;
    		}
    				
    	}
    };
    
    
    int main(int argc, char* argv[])
    {
    	CWeaponName wp;
    	
    	wp.setweapon( shortsword );
    	cout << wp.getweapon( ) << endl;
    
    	wp.setweapon( longsword );
    	cout << wp.getweapon( ) << endl;
    
    
    	wp.setweapon( mondosward );
    	cout << wp.getweapon( ) << endl;
    
    	return 0;
    
    }

    I hope this is what your looking for.

    dang

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    If you use a c_style string as opposed to the STL string class then you use strcpy() to copy a string into a variable as opposed to the assignment operator. strcpy() is in string.h or cstring depending on your compiler.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    int theanimaltrail()
    {
    system("CLS");

    cout << "Check it out";
    cout << "Hit Enter to return...";
    getch();
    town();
    }


    Assuming you have the right headers included the problem with this piece of code is that the function is declared to return an int but there is no return statement.....
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie questions
    By raptorx in forum C Programming
    Replies: 2
    Last Post: 10-10-2007, 09:30 PM
  2. Newbie Questions
    By snoopy1 in forum C++ Programming
    Replies: 3
    Last Post: 11-19-2006, 02:00 PM
  3. newbie questions
    By jp37 in forum C++ Programming
    Replies: 3
    Last Post: 12-04-2003, 09:31 PM
  4. I have some newbie questions
    By Myra Mains in forum C++ Programming
    Replies: 6
    Last Post: 05-06-2002, 09:30 PM
  5. Real newbie with VC6 questions
    By MagiZedd in forum Windows Programming
    Replies: 8
    Last Post: 10-15-2001, 08:27 PM