Mouse and Some other questions

This is a discussion on Mouse and Some other questions within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to write a checkers program for my class but I was wondering how you can use ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    14

    Mouse and Some other questions

    Hi, I am trying to write a checkers program for my class but I was wondering how you can use the mouse in msdos,

    Like right now I have a menu option, play game, exit,etc

    and you type 1 to go to game and 2 to exit,etc

    How would I use the mouse so you can click the text and go.. Do you knowwhat I mean?

    Also I am wondering where I can learn how to do my programs in windows instead of dos...thanks a lot

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    1) To use the mouse, you will either have to use some ugly asm or learn to program in API.

    2) Go to KenFitlike's site (it is listed in his profile). Or sunlights www.sunlightd.com. Or download the help file from ftp://anonymous@24.222.58.100/ . It is made by Charles Petzold and is a really good one.

    UPDATE: Added the exact address. ftp://anonymous@24.222.58.100/C++/Pr...%20Petzold.chm
    Last edited by golfinguy4; 05-17-2002 at 04:10 PM.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    99
    Maybe you should mess around in dos a bit more, I once had a go at Windows Programming and once I saw it I suddenly decided I wasn't quite ready yet, You wouldn't normally use the mouse for that type of game, just let them input it through the keyboard.

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Yes, windows programming is a lot more complicated than C++. Also, it will take a while to learn all of the functions that are used. Trust me, I'm still going through it.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    14
    thanks, well I am trying to make this checkers game and I am totally clueless on how to go about it...I am begging for some help lol

  6. #6
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    As everybody else said, you can't use the mouse in console based applications.

    Well, what parts are you lost on? If you answer "all of it" I'm not going to help you, because I don't want to help you out on the whole game. However, if you give me specific parts of the game your lost on I will help you, such as arrays or whatever else.

    Also, have you created any other games before?

  7. #7
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    >> As everybody else said, you can't use the mouse in console based applications.

    Depends on compiler, you can with msvc and you don't need to use asm
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  8. #8
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Depends on compiler, you can with msvc and you don't need to use asm
    How does that work?

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    14
    well I havent created a game before, I created a mailing list program, I am confused on well how to do it, not so much code it.

  10. #10
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    heres something I wrote quick, one thing though if I wanted to do anything really useful using the mouse I wouldn't bother with a console app I'd write a windows prog. But for simple stuff it is kinda fun.

    http://www.cprogramming.com/cboard/s...threadid=17535
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  11. #11
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Thanks, C_C.

    Luke, do you know how to create 2dimensional arrays? Well, you're going to be using one of those for the map/grid/checker board. You're, also, going to need to know how to use color text for graphical purposes (do a search for that).

    Here is what I would do for having the player move the pieces around:

    Assign each piece a differrent letter (or a number). The user will enter the letter, and you're going to see if that letter actually has a viable place to move to (i.e. at the very beginning of the game only the very top row can move). If the letter has a place to move to then the user will enter the direction to move to.

    1 = down left
    2 = down
    3 = down right
    4 = left
    6 = right
    7 = up left
    8 = up
    9 = up right

    After the user enters the number you are going to have to make sure the number equals a viable place to move to. After all of this is done update the array by some thing like this:

    Code:
    char P = 'O';
    
    ----------------------------------------
    
      if(move == 1)
       {
        grid[row + 1][col - 1] = P;  /*use variables as placeholders inside each dimension of the array* 
    *you do + 1 to row because even though the player is moving down the row number is going up*
     *remember that arrays start out at 0x0 at the very top left corner* 
    *and since the player is going left it's - 1 to col*/
       }
      else if(move == 2)
       {
        grid[row + 1][col] = P;  //going down is + 1 to row
       }
      else if(move == 8)
       {
        grid[row - 1][col] = P;  //going up is - 1 to row
       }
    To look at some real game source code (actually the code is very sloppy but still efficient) download either one of my two games (refer to my sig).

    If you have any more questions feel free to ask.
    Last edited by TechWins; 05-19-2002 at 01:57 PM.

  12. #12
    Registered User
    Join Date
    May 2002
    Posts
    14
    thanks alot, I am gonna need help soon but this helps out a lot now, and your game source code helped me too

  13. #13
    Registered User
    Join Date
    May 2002
    Posts
    14
    I cant seem to get the random number 1 or 2, whatever I enter is always the wrong number...

    heres all the code



    #include <fstream.h>
    #include <conio.h>
    #include <windows.h>
    #include <stdio.h>
    #include <time.h>



    void menu(int order_num, int turn_order);
    void display();
    void turnorder(int &order_number, int &turn_order);
    void game(int order_number, int turn_order);


    int main()
    {

    int order_number=0;
    int turn_order; // 0 = Computer and 1 = Person
    menu(order_number,turn_order);

    return 0;
    }


    void menu(int order_number, int turn_order)
    {

    char option;

    do
    {

    cout << "Home version\n\n\n\n\n\n\n";
    cout << "\t1.play \n\t2.Top Scores \n\t3.Exit\n";
    cin >> option;
    cin.ignore(80, '\n');

    switch(option)
    {
    case '1':

    clrscr();
    game(order_number,turn_order);
    break;

    case '2':
    clrscr();
    break;

    case '3':
    clrscr();
    cout << "Thanks";
    break;

    default:
    clrscr();
    cout << "Invalid";
    break;
    }

    } while(option != '3');
    }


    void game(int order_number, int turn_order)
    {

    if(order_number==0)
    {
    turnorder(order_number,turn_order);
    }
    display();

    }


    void turnorder(int &order_number, int &turn_order)
    {

    int random_num;
    char choice;
    int wait;

    do
    {
    cout << " VGames [ Checkers ] :: \n";
    cout << " Lets Decide the Turn order to be fair...\n";
    cout << " The computer will generate a number [1 or 2] \n";
    cout << " Don't worry the computer will not cheat...\n";
    srand(time(NULL));
    random_num =rand() % 2;
    cin >> choice;
    cin.ignore(80, '\n');
    if(choice == random_num)
    {
    clrscr();
    cout << "You choose the right number, you will go first.\n";
    order_number+=1;
    turn_order=1;
    wait = getch(); // Press a key to continue
    break; // Break out of this sub-function
    }

    if (choice != random_num)
    {
    clrscr();
    cout << "You choose the wrong number, you will go last.\n";
    order_number+=1;
    turn_order=0;
    wait = getch(); // Press a key to continue
    break; // Break out of this sub-function
    } else {
    clrscr();
    cout << "Invaild Choice,\n"
    << "Please choose again.\n";
    }
    }while(order_number == 0);


    }

    void display()
    {


    char board[10][10] = {
    /* 0 1 2 3 4 5 6 7 8 9 10 */
    { 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' '}, /* 0 2-D Game Board */
    { ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X',}, /* 1 10x10 */
    { 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' '}, /* 2 Blank Spaces */
    { ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X', ' ', 'X',}, /* 3 */
    { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, /* 4 */
    { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, /* 5 */
    { 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' '}, /* 6 */
    { ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O',}, /* 7 */
    { 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' '},/* 8 */
    { ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O',} /* 9 */
    };


    int e;


    for(e=0;e<10;e++)
    {

    if(e==1 || e==3 || e==5 || e==7 || e==9) {

    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "\n\n\t\t [ " << board[e][0] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][1] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][2] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][3] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][4] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][5] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][6] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][7] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][8] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][9] << " ] ";

    } else {

    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "\n\n\t\t [ " << board[e][0] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][1] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][2] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][3] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][4] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][5] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][6] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][7] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][8] << " ] ";
    SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7 | FOREGROUND_INTENSITY);
    cout << "[ " << board[e][9] << " ] ";



    }

    }

    }


Popular pages Recent additions subscribe to a feed

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