CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2012
    Posts
    1

    C++ Text based game..

    Hello everyone, am new. I wondered if could help me get my head around the coding side of things.
    I have started to make a text based game for uni, its part of the course.
    I know what I need in it, I know what to do.. but for the life of me I cant code the thing.

    My first mission on this is to first display a random x and y coordinates of both you (the player and 10 enemies on a 10x10 grid)
    Bare in mind that i dont have to make the grid, just put if statements on the coordinates to limit the number from going any higher than 10.

    Here are the classes... I would i go about doing this?
    Code:
    class Characters
    {
    protected:
    	int x,y; // co-ordinate position
    	
    public:
    	Characters(int pos_x,int pos_y) {
    		x=pos_x;
    		y=pos_y;
    				
    	}
    };
    
    class Bunnymonsters : public Characters
    {
    	
    };
    
    class Hero : public Characters 
    {
    public:
    	//Create Hero
    
    
    	};

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: C++ Text based game..

    C++ does not have a default means to directly access screen coordinates or to display text at a specific location.

    The Windows API does have functions to more directly control a console window, which among others includes querying the window size, the buffer size, changing both, accessing/reading/writing characters at a specific x,y coordinate, changing color and color background. But of course, this will make your game windows specific (it won't be recompilable and runnable for a linux machine).

    An alternative approach is to 'redraw' the entire playing field on every change, but that has some visual issues of it's own.

    depending on what you really want to do, it may be simpler even to write your own simple GUI based application.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured