Hello everyone! So I wrote a program that simulates a dice game, almost like the game of Craps. I want to turn this normal console app into a dialogue based MFC. So I would create a button labeled "Roll" and the window would show two die being rolled.
Here is the code I have for the condole app. It works perfectly, but I am so confused as to how to assign the code to the button and also how to assign the die faces to its respective bitmaps. I appreciate the help!

//Game of chance "Craps"


#include "stdafx.h"
using namespace std;

void dice(void)
{//start dice
    //variables
    string  input;
    int     i,roll,gamePoint,val,val_1,val_2,roll_1,roll_2,sumRoll;
    long    winnings,losses,wager,odds,oddsNumer,oddsDenom;
    bool    A=false;
    //declarations
    roll=0;gamePoint=0;val=0;val_1=0;val_2=0;roll_1=0;roll_2=0;sumRoll=0;
    //user input
    cout<<"Enter your odds ratio:\nNumerator: ";
    cin>>oddsNumer;
    cout<<setw(8)<<"Denominator: ";
    cin>>oddsDenom;
    cout<<"Enter your wager for the game: ";
    cin>>wager;
    odds=abs((oddsNumer/oddsDenom)+1);
    winnings=abs(odds*wager-wager);
    cout<<winnings;
    //dice output
    do
    {
        srand (unsigned(time(NULL)));
        sumRoll=0;
        for(i=0;i<2;i++)
        {
            val_1=rollDice();
            //cout<<"***test1***";
            switch (val_1)
            {//start switch
                case 1:
                    dieFace(val_1);
                    break;
                case 2:
                    dieFace(val_1);
                    break;
                case 3:
                    dieFace(val_1);
                    break;
                case 4:
                    dieFace(val_1);
                    break;
                case 5:
                    dieFace(val_1);
                    break;
                case 6:
                    dieFace(val_1);
                    break;
            }//end switch
            sumRoll=val_1+sumRoll;      
        }//end for loop dice roll
        cout<<endl<<endl<<"\tYou rolled a: "<<sumRoll<<endl;
        system("pause");
        if (sumRoll==7 ||sumRoll==11)
        {   
            cout<<"Hurray! You win!\n"<<
                "Your total winnings: $"<<winnings<<endl;
            A=true;
            system("pause");
        }//and if winner statement
        else if(sumRoll==2 ||sumRoll==3||sumRoll==12)
        {
            losses=abs(odds*wager);
            cout<<"Sorry, you lose. The house wins. Total lost is $"<<
                losses<<endl;
            A=true;
            system("pause");
        }
        else 
        {

            gamePoint=sumRoll;  
            roll=0;

            do
            {
                srand (unsigned(time(NULL)));
                sumRoll=0;
                roll++;
                for(i=0;i<2;i++)
                {
                    val_1=rollDice();

                    switch (val_1)
                    {//start switch
                        case 1:
                            dieFace(val_1);
                            break;
                        case 2:
                            dieFace(val_1);
                            break;
                        case 3:
                            dieFace(val_1);
                            break;
                        case 4:
                            dieFace(val_1);
                            break;
                        case 5:
                            dieFace(val_1);
                            break;
                        case 6:
                            dieFace(val_1);
                            break;
                    }//end switch
                    sumRoll=val_1+sumRoll;
                }//end for loop dice roll
                cout<<endl<<endl<<"\tYou rolled a: "<<sumRoll<<endl;
                system("pause");
                if (sumRoll==7)
                {   
                    losses=abs(wager*roll*odds);
                    cout<<"Sorry, you lose. The house wins."<<
                        "Total lost is $"<<losses<<endl;
                    A=true;
                    system("pause");
                }
                else if(sumRoll==gamePoint)
                {
                    winnings=abs(wager*roll*odds-wager);
                    cout<<"Hurray! You win!\n"<<
                        "Your total winnings are $"<<winnings<<endl;
                    A=true;
                    system("pause");
                }
            }while(A==false);
        }
    }while(A==false);
    system("pause");
    system("cls");
    return ;
}

int rollDice(void)
{
    //srand (unsigned(time(0)));
    return((rand()%6)+1);
}
void dieFace(int val)
{

    switch (val)
    {//start switch
        case 1:
            cout<<endl<<endl<<endl;
            cout<<"       *************"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *     O     *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *************"<<endl<<endl;

            break;
        case 2:
            cout<<endl<<endl<<endl;
            cout<<"       *************"<<endl;
            cout<<"       *         O *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       * O         *"<<endl;
            cout<<"       *************"<<endl<<endl;

            break;
        case 3:
            cout<<endl<<endl<<endl;
            cout<<"       *************"<<endl;
            cout<<"       *         O *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *     O     *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       * O         *"<<endl;
            cout<<"       *************"<<endl<<endl;

            break;
        case 4:
            cout<<endl<<endl<<endl;
            cout<<"       *************"<<endl;
            cout<<"       * O       O *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       * O       O *"<<endl;
            cout<<"       *************"<<endl<<endl;

            break;  
        case 5:
            cout<<endl<<endl<<endl;
            cout<<"       *************"<<endl;
            cout<<"       * O       O *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       *     O     *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       * O       O *"<<endl;
            cout<<"       *************"<<endl<<endl;

            break;
        case 6:
            cout<<endl<<endl<<endl;
            cout<<"       *************"<<endl;
            cout<<"       * O       O *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       * O       O *"<<endl;
            cout<<"       *           *"<<endl;
            cout<<"       * O       O *"<<endl;
            cout<<"       *************"<<endl<<endl;

            break;
    }
    return  ;
}

This is a very good tutorial for mfc dialog based application beginers
http://www.codeproject.com/Articles/589/A-Beginners-Guide-to-Dialog-Based-Applications-Par

It's a 15 minute read and once you complete it i am sure you will be able to create a dialog with a button that executes some code. Also how to parse input from textboxes.

You could use your existing ascii drawing inside a textbox to create the feel of visual interaction, but if you want to use real images you will have to dig a little deeper by reading something like this:

http://www.codeproject.com/Articles/356/Bitmap-Basics-A-GDI-tutorial

Hope that helped.

commented: Wow thank you for those links! Real helpful. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.