C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-06-2004, 01:02 PM   #1
Registered User
 
Finchie_88's Avatar
 
Join Date: Aug 2004
Posts: 146
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
Finchie_88 is offline   Reply With Quote
Old 09-06-2004, 03:42 PM   #2
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,664
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.
Prelude is offline   Reply With Quote
Old 09-07-2004, 01:42 PM   #3
Registered User
 
Finchie_88's Avatar
 
Join Date: Aug 2004
Posts: 146
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...

Finchie_88 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Button handler Nephiroth Windows Programming 8 03-12-2006 06:23 AM
Type Of Memory In A Control? SMurf Windows Programming 4 03-04-2006 12:23 PM
RickEdit control question nomer Windows Programming 6 03-03-2006 07:00 PM
creating an activex control Benzakhar Windows Programming 9 12-29-2003 06:32 PM
Control class Mithoric Windows Programming 0 11-28-2003 08:35 AM


All times are GMT -6. The time now is 05:32 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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