Need some direction

This is a discussion on Need some direction within the C++ Programming forums, part of the General Programming Boards category; I posted here a couple of months ago as a newbie C++ programmer. Rather than dig up that old thread, ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    5

    Need some direction

    I posted here a couple of months ago as a newbie C++ programmer. Rather than dig up that old thread, I thought I'd create a new one, as my circumstances have changed.

    I've been teaching myself c++ for three months now, and am becoming comfortable with such things as classes, objects, pointers, arrays and so on. However, my ultimate goal is to create a two-dimensional air traffic control simulation (with x and y axis). I don't intend on becoming a C++ master programmer; I just want to create this little game.

    From the basics of c++, I can clearly see how my data would be organized. Each aircraft would be an object of an "aircraft class". Each would have properties such as position, speed, altitude and heading. Each would have methods such as climb, descend, turn, etc.

    At this point, however, I don't see a light at the end of my study tunnel. Obviously I will need more knowledge than basic C++. In my last thread, someone suggested also learning STL, data structures, and DirectX. I really wish there was some way I could focus my learning a bit more. Like I said, I have a very specific goal, and I don't want to learn all there is to know about programming if I don't have to.

    I need some direction. Any thoughts or ideas of any kind would be greatly appreciated.

    Kenny

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Well. If your goal is just "simple" 2d graphics then you can use SDL or Allegro(My Choice ). I would learn a little about vectors to replace arrays so you can have an "unlimited" amount of planes. Maybe have an airtraffic interface class that takes an plane to modify. It's really up to you how advance you want it to be and what you need to learn.
    Woop?

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    5
    SDL or Allegro are things I've never heard of, but I will look into them. I will also investigate vectors, though I do not really have an understanding of the principle you mentioned.

    I've started writing my program already, which consists of an "aircraft class", from which every aircraft is an object containing variables such as X-position, Y-position, altitude, speed, heading, and several methods like climb, turn, reduce speed, etc.

    On a real radar scope, very little actually happens. Aircraft "blips" move around, each with a data tag to display altitude and speed.

    Should I be trying to write this in a DOS window, or WIN32 application? The books say to learn C++ by writing into a DOS window, then advance into WIN32.

    Coould you let me know if the "class" concept above is a reasonable method of data management?

    Kenny

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    The Airplane class is just fine. This is what I was talking about.
    Note: This is a very basic example
    Code:
    class Airplane
    {
        public:
            Airplane()
            {
                height = 10000;
                x = 100;
                y = 100;
            }
            void Climb()
            {
                height += 1000;
            }
            void Descend()
            {
                y -= 1000;
            }
            void Turn(int dir)
            {
                if(dir == 0)
                {
                    //Go right
                    x++;
                }
                if(dir == 1)
                {
                    //Go Left
                    x--;
                }
            }
        private:
            int x;
            int y;
            int height;
    }
    
    class FlightScope
    {
        public:
            void Draw()
            {
                //Draw however method you are using
            }
            void AddPlane(const AirPlane &toAdd)
            {
                //Add a new plane to our scope
                FlightPlanes.push_back(toAdd);
            }
        private:
            std::vector<Airplane> FlightPlanes;
    };
    Last edited by prog-bman; 11-17-2005 at 02:32 PM.
    Woop?

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    I will also investigate vectors, though I do not really have an understanding of the principle you mentioned.
    Do you know what an array is? A vector is like an array, but it starts off with size 0 and you can add as many elements to it as you want. It should take you no more than 30 minutes to learn how to use a vector. The notation can look a little scary, but it's really simple. One beginning C++ book actually starts off teaching about vectors instead of arrays.

    If you learn about vectors, you should also check out maps. Have you ever wanted to use an array with strings as the index values? Maybe like this:
    Code:
    myArray[10];
    myArray["Betty"] = "245-0012";
    myArray["Mike"] = "312-6789";
    cout<<myArray["Mike"]<<endl; //"312-6789";
    With a map you can do that. Vectors and maps are known as STL 'containers', and the C++ language has all the facilities to use them. Here are some examples:

    Code:
    //Vectors:
    
    #include<iostream>
    #include<vector>
    using namespace std;
    
    int main()
    {
    	//Declare a vector(#include <vector>). The type indicated 
    	//between the <> is the type you are allowed to store in 
    	//the vector.  It can be a user defined class as well.
    	vector<int> myNums;
    
    	int n1 = 10;
    	int n2 = 20;
    	int n3 = 30;
    
    	//Add int's to the vector using the push_back() function.
    	//push_back() adds elements to the end of the vector:
    	myNums.push_back(n1);
    	myNums.push_back(n2);
    	myNums.push_back(n3);
    
    	//Display the int's in the vector:
    	for(int i = 0; i < myNums.size(); ++i)
    	{
    		cout<<myNums[i]<<" ";
    	}
    	cout<<endl;
    
    	//Erase an element in the vector:
    	myNums.erase(&myNums[0]); 
    
    	for(int j = 0; j < myNums.size(); ++j)
    	{
    		cout<<myNums[j]<<" ";
    	}
    	cout<<endl;
    
    	return 0;
    }
    Code:
    //Maps
    
    #include<iostream>
    #include<map>
    #include<string>
    using namespace std;
    
    int main()
    {
    	//Declare a map(#include <map>).
    	//The first type between the <> is the type of the index
    	//value, and the second type is the type you want to store
    	//at that index value.
    	map<string, string> PhoneBook;
    	
    	PhoneBook["Betty"] = "245-0012";
    	PhoneBook["Mike"] = "312-6789";
    
    	cout<<PhoneBook["Mike"]<<endl<<endl;
    
    	//Declare a different map:
    	map<string, int> myHeadings;
    	myHeadings["plane1"] = 30;
    	myHeadings["plane2"] = 45;
    
    	//Display headings:
    	cout<<myHeadings["plane1"]<<endl;
    	
    	//Get an "iterator"(which is like a pointer) to the
    	//beginning of the map.  You indicate the type of the map
    	//you are dealing with and then use the word "iterator":
    	map<string, int>::iterator i = myHeadings.begin();
    	
    	//Use the pointer to move along the map and display all
    	//the elements.  There's a little twist though: map's 
    	//actually store the index and the element together in a 
    	//struct called a 'pair'.  That means the pointer you have is
            //actually pointing to a pair struct.  In a pair, the
            //index is stored in a member variable called 'first' and
    	//the element is stored in a member variable called 'second':
    	
    	for(; i != myHeadings.end(); ++i)
    	{
    		cout<<"index: "<<i->first<<" element: "<<i->second<<endl;
    	}
    	cout<<endl;
    
    	return 0;
    }
    Should I be trying to write this in a DOS window, or WIN32 application?
    If you want to do it in Win32, you're going to need to start reading a 1500 page book called Windows Programming(Petzold).
    Last edited by 7stud; 11-17-2005 at 03:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some Direction Needed
    By Bidamin in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2009, 10:15 AM
  2. Mouse Maze Problem
    By Furbiesandbeans in forum C++ Programming
    Replies: 13
    Last Post: 04-28-2008, 04:20 PM
  3. What's your hair whorl direction?
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 02-24-2003, 07:28 PM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 12:54 AM
  5. Classic problem doesn't accept direction
    By cheesehead in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2001, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21