Hi there... I am a new member here. If my request is not appropriate anyone can delete it. I desperately need help with my school work. I have been doing this for about a week but still don't get how to do. This is a big programming work, so I uploaded the source data here http://www.mediafire.com/?akft3w1dxul

If anyone can help me out or drop a hint with this I would really appreciate it.

Thank you very much in advance.

Recommended Answers

All 18 Replies

Welcome to the forum.
Your post would be appropriated if it is pertaining to C programming. As it stands we don't know until people download the attachment, and many do have apprehensions about doing so.
You forgot to ask a question concerning where you are having problems.
I would like to invite you to try again. Ask your question and post the related portion of the code concerning it.
Read this short guide of how to properly post parts of code.

commented: i need to learn from your example on how to handle these people +2

Heres their program's header file

/**
 * StopDice.h
 * Defines  constants used for StopDice program logic and graphics
 *
 * NOTE that string constants are NOT declared constants in order
 * to conform to the requirements of WinBGIm functions that do 
 * not define constant string parameters when they should. This will
 * be fixed when WinBGIm is itself fixed.
 *
 * @author . . .
 * @version 1.0 May 2008
 */
 
/*------------- Program Constants ------------------*/
char GAME_NAME[]   = "Stop the Dice";
char GAME_CLAIM[]  = "- Extreme Challenge!";
char GAME_INTRO1[] = "* Stop with 2 dice showing the same value => Score 1 point";
char GAME_INTRO2[] = "* Stop with 3 dice of the same value => Bingo! add 1 and multiply by value";
char GAME_INTRO3[] = "Press the [Space bar] to start or stop";

const int DELAY        = 160;/* milliseconds between dice rolls */
const int NUM_DICE     = 3;  /* number of dice displayed        */
const int NUM_IMAGES   = 6;  /* number of different dice images */

/*------------- Graphics Constants -----------------*/
const int IMAGE_SIDE    = 142; /* pixel length of a die side */ 
const int WINDOW_WIDTH  = 4 * IMAGE_SIDE;
const int WINDOW_HEIGHT = 2 * IMAGE_SIDE;
const int IMAGE_TOP		= IMAGE_SIDE / 3;
const int IMAGE_BOTTOM	= IMAGE_TOP + IMAGE_SIDE;
const int BK_COLOR      = WHITE; /* Screen background colour */

and the program's source code

/**
 * StopDice.c
 * Implements the "immortal" StopDice game
 *
 * @author . . . 
 * @version 1.0 - May 2008
 */
 
#include <stdio.h>
#include <stdlib.h>

#include <stdbool.h>  /* Available in C99 for bool type */
#include <graphics.h> /* Defines the WinBGIm functions  */

#include "StopDice.h" /* Defines the program constants  */

/* Function Prototypes */

/**
 * Initialise the game screen
 * Loads dice images to memory 
 * @param images void *[] array for storage of dice images
 */ 
void initialise(void *images[]);

/**
 * Loads dice images from disk to memory 
 * @param images void *[] array for storage of dice images
 */ 
void initImages(void *images[]);

/**
 * Display game intro to screen 
 */
void gameIntro(void);

/**
 * Display a die image given its value (1 to 6) and its position
 * on the screen (1, 2, or 3 = left, middle or right).
 * @param value int, the value of the die between 1 and 6.
 * @param position int, the position of the die between 1 and 3
 * @param images void *[], image array to get the die picture from
 */ 
void displayDie(int value, int position, void *images[]);

/* TEMPORARY FUNCTION to get dice moving. REPLACE by proper game logic */
void changeDice(void *images[], int key);

/*--------------------------------------------------------------------------*/

int main()
{
    void *images[NUM_IMAGES]; /* Array of dice images */
    int key;
    /* Initialise application (open window, load images...) */
    initialise(images);

    /* LOOP is TEMPORARY CODE: change dice until space bar is pressed */
    do 
    {
        key = 0; /* Reset key to any non-meaningful value */
        if(kbhit()) /* If the keyboard has been used, get a character */
            key = getch();
        
        /* Take proper action in function of key pressed */
        changeDice(images, key);
        
        delay(DELAY);
    } while(true);
    return 0;
}


/* Initialise application (open window, load images draw first screen) */
void initialise(void *images[])
{          
    /* Open a window in background colour with double-buffering off */      
    initwindow(WINDOW_WIDTH, WINDOW_HEIGHT, GAME_NAME, 150, 80, false, true);
    setbkcolor(BK_COLOR);
    cleardevice();
    
    /* Load images to memory */
    initImages(images);
    
    /* Display game introduction */
    gameIntro();
       
}

/* Load images from disk to memory */
void initImages(void *images[])
{     
    int i, j;
    unsigned int imageSize; /* The size of an image in memory (in bytes) */
    int imageNo; /* Image number */
    int left;     /* Left coordinate of an image */
    int right;     /* Right coordinate of an image */
    char imageFilename[8]; 
    
    /* Load the dice images */
    for(i = 0; i < NUM_IMAGES / NUM_DICE; i++)
    {
        for(j = 0; j < NUM_DICE; j++)
        {
            imageNo = (j + 1) + (i * NUM_DICE); /* 1 to 6 */
            
            /* Left and right corners of image */
            left = j * (IMAGE_SIDE + IMAGE_SIDE / 4) + IMAGE_SIDE / 4; 
            right = left + IMAGE_SIDE;
            
            sprintf(imageFilename, "%i.gif", imageNo ); /* Build up filename */

            /* Read from file and get size */
            readimagefile(imageFilename, left, IMAGE_TOP, right, IMAGE_BOTTOM);
            imageSize = imagesize(left, IMAGE_TOP, right, IMAGE_BOTTOM);

            /* Store each image in turn into the image array */
            images[imageNo - 1] = malloc(imageSize); /* allocate storage */
            getimage(left, IMAGE_TOP, right, IMAGE_BOTTOM, images[imageNo - 1]);
        }
    }      
}

/* Print flash screen information */
void gameIntro(void)
{
    /* Print game name and claim */
    settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
    setcolor(GREEN);
    moveto(20, IMAGE_TOP / 3);
    outtext( GAME_NAME);
    outtextxy(getx() + 10, gety(), GAME_CLAIM);
    /* Print game rules */
    settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 1);
    setcolor(BLUE);
    moveto(12, IMAGE_BOTTOM + 14);
    outtext(GAME_INTRO1);
    moveto(12, gety() + 24);
    outtext(GAME_INTRO2);
    setcolor(RED);
    moveto(110, gety() + 28);
    outtext(GAME_INTRO3);
}

/* Display a die image given its value and its position on screen */
void displayDie(int value, int position, void *images[])
{
    /* Left corners of image */
    int left = (position - 1) * (IMAGE_SIDE + IMAGE_SIDE / 4) + IMAGE_SIDE / 4; 
        
    putimage(left, IMAGE_TOP, images[value - 1], COPY_PUT);
}


/* ============== DISCARD BELOW THIS LINE. TEMPORARY CODE ============== */
/* Temporary function to get dice moving. Does not implement the game. 
   REPLACE by proper game logic */
void changeDice(void *images[], int key)
{
    static bool started = false;
    static int value = 1; /* static to remember next time we come in */
    
    switch(key)
    {
    case ' ': /* Space bar has been hit */
        if(started)
        {
            delay(1000); /* pause for 1 sec, then exit program */
            exit(0);
        }
           else
            started = true;
    break;
    default:
    break;
    }
    
     /* dice go round and round in endless loop*/
    if (started)
    {
        value = ((value + 1) % 7);
        if (!value)
            ++value;
        displayDie(value, 1, images);
        displayDie((value + 4) % 6 + 1, 2, images);
        displayDie((value + 5) % 6 + 1, 3, images);
    }
}

now don't say i never did nothin' for no one :P

but yeah, what AIA said... what exactly is your problem now?

my problem is :( I don't know how to make it run by following the tasks given. I really have poor knowledge in programming. I tried many times but all in vain. Error...error.. and not even compiled. So If anyone can help, just help me. My problem is I totally don't know how to do it :( want to cry....

umm... well, how did you get this program as far as you did?

where in the program, exactly, are you having problems?

and don't tell me "everywhere".

:( If u read the uploaded pdf file, u will know the purpose of this program. It is to modify the existent program. But I don't even know how to start it. That's why I am asking for help. :) so .. please if you can. But if my request was not under the condition, so be it.

ah... dangit, my sarcasm generator is down this morning. *sigh* ... This is my own fault. I should have followed AIA's lead and left it alone.

Okay... as a final parting gift, here's what you need to do:

take each of the provided stubs (function headers) and fill each of them in with code to make each of them do the task that is specified.

then in the main() routine, tie them all together.

and in the meantime, if you can ever formulate a SPECIFIC, COHERENT question, come back, and maybe I'll care again.

I tried many times but all in vain. Error...error.. and not even compiled.

One practical approach, to get you started, would be to post the code that is not compiling (along with the error message(s)).

hi did u fix ur program

NO..no . :( i wan to die ... this is really important but my brain is dead. heloo... mitrmkar i don't have any draft codes to upload here, I tried to do the task and after that is wasn't compile and I stop doing that. It will be really great if someone can do this for me or give step by step instruction to accomplish the tasks given????????? HELP HELP HELP, If u can. Anyway.... I appreciate ur concern. Thank u.

I tried to do the task and after that is wasn't compile and I stop doing that. [blabla] HELP HELP HELP, If u can.

Alright, I'll try to be gentle....

Please read this about your language.

Then read this about how to describe problems

Now post your compiler-errors and the lines where they occur.

I can't help you with this code because it uses the <graphics.h> header, which can't be used on standard-compilers.

NO..no . :( i wan to die ...

Stop the whining and come back with a decent question. You'll get help if you describe you problem in a clear manner.

:) G'day ... Okkkk.. I give up QUESTIONING 'cus I don't know how to ask help from someone >>but I ll be back with very decent and clear questions next time Bye bye everybody :P

okay its early still, and im feeling pleasant:

PHOENIX,

you need to back up, and get some basics. I dont know how you got this far being so helpless.

look, do this simple exercise:

write a short program to "roll three dice" and print the results to the screen, without graphics or using any of that stuff your instructor gave you.

just start like this

#include <stdio.h>

int main ()
{

   // insert your code here

}

and make it print to a simple terminal something like this example:

Press Enter To Roll Dice...

Dice Rolled Are:  [6] [3] [5]

Press Enter To Roll Dice...

once you get that working, apply what you've learned to filling out the stubs in the rest of the assignment program.

and at the very minimum, you need to be able to do this by yourself. if you cant even handle this simple assignment, I suggest you seriously consider dropping your class.

Thanks for ur concern. I worked out it.

glad to hear it

Welcome to the forum.
Your post would be appropriated if it is pertaining to C programming. As it stands we don't know until people download the attachment, and many do have apprehensions about doing so.
You forgot to ask a question concerning where you are having problems.
I would like to invite you to try again. Ask your question and post the related portion of the code concerning it.
Read this short guide of how to properly post parts of code.

I need to know how to make a c programm with dice.

Looks straight forward to me. Basiclly you have been given a working demo. You need to install and load into Quincy 2005. Looks like you need WinBGIm and MingW installed.

After that, its just basic user input logic. You have been given a stop/start user interface.

therefore, you are being asked to add the code to check the dice values and increment the score are per the requirement.

It also looks like you need to adjust the game loop so the game doesn't restart, unless you press 'N' to reset the score, or 'Q' to quit.

This is basic coding. Its testing if you can:
logically read though instructions.

I need to know how to make a c programm with dice.

Forum policy is We only give homework help to those who show effort. Therefore come back with some code you did, create new thread, explain where you have difficulties and maybe somebody will help you.

Thread closed

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.