Well I am still playing with my spirograph program, but I thought this question should be put in a different thread as to the specific problem. I have successfully made a class and it compiles fine. Phew first step done. Temporily I used a void. Now I know void can't return values, but I have a bigger problem than that. I need to return multiple values and I know a function can only return one value. I have googled a bit, but nothing has come up that I understand.
I need to return the r,g, b values so that is 3 values I need to return from the function. Or is there a better way to do this?
I will now paste my code so far. I will paste my header file first and then my cpp. I use I shouldn't leave the user variable in the game.h. They are only there at the moment because I still have my own code there. Also I had a small problem creating the class at first. Visual C++ decided to put my head file and cpp file in the root folder instead of the assets folder. Solved that problem by manually moving them afterwards.
Oh and one more question. I think pragma is something to do with memory. Could you tell me the reason it is used?
PS: Just found out I can make it work by making my int r; int g; int b; public in my Colour class and accessing it with int fb=Colour.b;, but I think this is considered bad programming. As it is dangerous to have too many public variables.
Colour.h
Code: Select all
#pragma once
#include <Windows.h>
class Colour
{
public:
Colour();
void Colour::RColour();
private:
int colchange;
int r;
int g;
int b;
};
Code: Select all
#include "Colour.h"
Colour::Colour()
:colchange (0),
r (255),
g (255),
b( 255 )
{
}
void Colour::RColour()
{
if (colchange>100)
{
r=(rand() % 255);
g=(rand() % 255);
b=(rand() % 255);
colchange=0;
}
colchange++;
}
Code: Select all
#pragma once
#include "D3DGraphics.h"
#include "Keyboard.h"
#include "Mouse.h"
#include "Sound.h"
#include "Colour.h"
class Game
{
public:
Game( HWND hWnd,const KeyboardServer& kServer,const MouseServer& mServer );
void Go();
private:
void ComposeFrame();
/********************************/
/* User Functions */
void Draw( float theta,int tx,int ty,int r,int g,int b );
/********************************/
private:
D3DGraphics gfx;
KeyboardClient kbd;
MouseClient mouse;
DSound audio;
Colour Colour;
/********************************/
/* User Variables */
float rotationAngle;
int colchange;
int r;
int g;
int b;
/********************************/
};