Thread: Making control...

  1. #1
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154

    Question Making control...

    Now, this is my problem, and I was wondering, is there a way that the following can be done???

    1) My plan is to make a small console program, where you have a space craft moving about the screen, but the problem is the control. My idea was to do this to make up movement (the other directions I haven't programmed in yet)...

    My idea was that I could make a basic space craft using ASCII letters (space craft not the finished product), now, the way I was going to do the control bit was to make it so that it printed an empty new line above the picture, therefore making it drop a line, also, for moving up, I was thinking of making it so that it printed a line above itself so that the space craft looked like it was moving down. This idea would then be expanded on horizontal directions, and so give control, but the problem is making it do that...

    Code:
    system ("cls");
        cout << "" << endl;
        
        cout << "                |    A   |" << endl;
        cout << "                |  A  A |" << endl;
        cout << "                AAAAAA" << endl;
        
        cin >> a;
        if(a == 1)
        {
            cout << "" << endl;  \\This line of code needs to be
                                              \\shown above the space craft
        }
        else if(a == 2)
        {
            
        }
    I no, this is a tall order, but r there any ideas

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    I make no guarantees as to whether this will work for you, I made two big assumptions about your system and compiler.
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <conio.h>
    #include <windows.h>
    
    using namespace std;
    
    void gotoxy ( short x, short y )
    {
      COORD coord = {x, y};
      SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
    }
    
    void draw_ship ( short x, short y )
    {
      gotoxy ( x, y );
      cout<<"|     |";
      gotoxy ( x, ++y );
      cout<<"|=[@]=|";
      gotoxy ( x, ++y );
      cout<<"   ^   ";
    }
    
    void redraw ( short x, short y )
    {
      system ( "cls" );
      draw_ship ( x, y );
    }
    
    int main()
    {
      short x = 10, y = 10;
    
      while ( y > 0 && y < 17 && x > 0 && x < 20 ) {
        redraw ( x, y );
    
        switch ( getch() ) {
        case 'w': --y; break;
        case 's': ++y; break;
        case 'a': --x; break;
        case 'd': ++x; break;
        }
      }
    }
    My best code is written with the delete key.

  3. #3
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    sorry, but I having a bit of difficulty making it so that you can shoot on the game... I need tips/helpful advice/example code/hyperlinks etc...


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  2. Type Of Memory In A Control?
    By SMurf in forum Windows Programming
    Replies: 4
    Last Post: 03-04-2006, 12:23 PM
  3. RickEdit control question
    By nomer in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2006, 07:00 PM
  4. creating an activex control
    By Benzakhar in forum Windows Programming
    Replies: 9
    Last Post: 12-29-2003, 06:32 PM
  5. Control class
    By Mithoric in forum Windows Programming
    Replies: 0
    Last Post: 11-28-2003, 08:35 AM