Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / I need help with programming

Author
Message
sylena2286
14
Years of Service
User Offline
Joined: 15th Jun 2010
Location:
Posted: 15th Jun 2010 09:20
Hello everyone!!!!

I;m a student @ college taking a C++ programming class.
I have no experience with programming whatsoever. I was wondering if you could please help figure this out

This is an assignment for my class:

I have to create an application that clears the screen every one second to 4 random colors (red, green, blue, magenta).
The code I've got so far does it but sometimes I notice that sometimes it appears to wait longer than one second between color changes and that is because the program sometimes generates the same random number two or more times consecutively.

What my goal is, however, is for the screen to never clear to the same color two times consecutively.

Please HELP ME

HERE IS THE CODE I HAVE SO FAR:

/* This program randomly clears the screen every second to one of these
four colors: red, green, blue, or magenta, never clearing the screen to the
same color two times consecutively.
*/

#include "DarkGDK.h"

void DarkGDK()
{
// Color constants
const DWORD RED = dbRGB(255, 0, 0);
const DWORD GREEN = dbRGB(0, 255, 0);
const DWORD BLUE = dbRGB(0, 0, 255);
const DWORD MAGENTA = dbRGB(255, 0, 255);

// Constant for the time delay (one second)
const int DELAY = 1000;

// Contant for the array size
const int SIZE = 4;

// Array of colors
DWORD colors[SIZE] = { RED, GREEN, BLUE, MAGENTA };

// Variable to use as an array index
int index;

// Seed the random generator
dbRandomize( dbTimer() );

// Repeatedly clear the screen with random colors.
while ( LoopGDK() )
{
// Get a random number
index = dbRND(SIZE - 1);

// Clear the screen to a random color.
dbCLS( colors[index] );

// Wait one second
dbWait(DELAY);
}
}
bloodmage2
15
Years of Service
User Offline
Joined: 14th Jun 2009
Location:
Posted: 15th Jun 2010 17:41
well, i don't want to do your work for you, but you could make an int for the current color, and which color was last. you set the current to the last at the beginning, and set last to current at the end (of the main loop, that is) when you call dbRND, put this in a while loop where the condition is the current is not equal to the last. this way, if the loop will execute the first time, because the last var is equal to current because you set it, but as soon as dbRND is called, if it is not the same, it will redo it.

-to the optimist, the glass is half full. to the pessimist, it is half empty, to the engineer, it is twice as big as it needs to be.
http://www.lionsbloodstudios.justinman.net/index.htm
mjmaurer
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location:
Posted: 15th Jun 2010 18:41
Try this, it worked for me.

http://forum.thegamecreators.com/?m=forum_view&t=169192&b=22

P.S. Forum advice: use the "code" button to enclose your code between two code tags, so that it can be opened/closed with a pushbutton like in Matty's post. It will preserve the indentation as well so the code will be much easier to read.
Back to top

Login to post a reply

Server time is: 2024-11-19 23:29:38
Your offset time is: 2024-11-19 23:29:38