Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Is This Good Programming Practice?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DrummaBoyFB




PostPosted: Mon Dec 13, 2010 1:50 am   Post subject: Is This Good Programming Practice?

I've got a class called Design
and in that class you can see that I have all my functions and
stuff declared inside my class.

Look Below


c++:

#include "Design.h"

/* Design::GetClothes (BITMAP *Clothes [][])
return Clothes [][];
*/


Design::Design () {
  num = 0;
  ChooseOption = false;
  SelectNumX = 0;
  SelectNumY = 0;
  DropY = 0;
  dropbox = false;
  SetColour = 0;
  for (int i = 0; i < 5; i ++)
    Colour[i] = i + 1;
  MainFont = load_font ("Fonts.pcx", NULL, NULL);
  ChangeCol = false;
  for (int i = 0; i < 4; i ++) {
    setImage [i] = 0;
    setColour [i] = 5;
    }
  }

/* 1 - black
2 - Silver
3 - Red
4 - Blue
5 - Yellow/Blonde
*/


void Design::LoadImages (int numHair , int numAddon , int numClothes, int numExtra) {
  for (int i = 0; i < numHair; i ++) {
    for (int a = 0 ; a < 6; a++) {
      stringstream str, str2;
      str << "Design\\Hair\\HairModel" << i + 1 << "(" << a + 1 << ").bmp";
      str2 << "Design\\Hair\\Hair" << i + 1 << "(" << a + 1 << ").bmp";
      bHairModel [i][a] = load_bitmap (str.str().c_str(), NULL);
      bHair [i][a] = load_bitmap (str2.str().c_str(),NULL);
      if (!bHairModel [i][a])
        allegro_message ("Error could not load %s", str.str().c_str() );
      else if (!bHair [i][a])
        allegro_message ("Error could not load %s" , str2.str().c_str() );
      } // End of Second For Loop
    } // End of First For Loop

  for (int i = 0; i < numClothes; i ++) {
    for (int a = 0 ; a < 6; a++) {
      stringstream str, str2;
      str << "Design\\Clothes\\ClothesModel" << i + 1 << "(" << a + 1 << ").bmp";
      str2 << "Design\\Clothes\\Clothes" << i + 1 << "(" << a + 1 << ").bmp";
      bClothesModel [i][a] = load_bitmap (str.str().c_str(), NULL);
      bClothes [i][a] = load_bitmap (str2.str().c_str(),NULL);
      if (!bClothesModel [i][a])
        allegro_message ("Error could not load %s", str.str().c_str() );
      else if (!bClothes [i][a])
        allegro_message ("Error could not load %s" , str2.str().c_str() );
      } // End of Second For Loop
    } // End of First For Loop


  for (int i = 0; i < numAddon; i ++) {
    for (int a = 0 ; a < 6; a++) {
      stringstream str, str2;
      str << "Design\\Addons\\AddonsModel" << i + 1 << "(" << a + 1 << ").bmp";
      str2 << "Design\\Addons\\Addons" << i + 1 << "(" << a + 1 << ").bmp";
      bAddonsModel [i][a] = load_bitmap (str.str().c_str(), NULL);
      bAddons [i][a] = load_bitmap (str2.str().c_str(),NULL);
      if (!bAddonsModel [i][a])
        allegro_message ("Error could not load %s", str.str().c_str() );
      else if (!bAddons [i][a])
        allegro_message ("Error could not load %s" , str2.str().c_str() );
      } // End of Second For Loop
    } // End of First For Loop


  for (int i = 0 ; i < 6; i++) {
    stringstream str, str2;
    str << "Design\\Extra\\ExtraModel" << i + 1 << ".bmp";
    str2 << "Design\\Extra\\Extra" << i + 1 << ".bmp";
    bExtraModel [i] = load_bitmap (str.str().c_str(), NULL);
    bExtra [i] = load_bitmap (str2.str().c_str(),NULL);
    if (!bExtraModel [i] )
      allegro_message ("Error could not load %s", str.str().c_str() );
    else if (!bExtra [i])
      allegro_message ("Error could not load %s" , str2.str().c_str() );
    }


  // for the selections

  for (int i = 0 ; i < 4; i++) {
    stringstream str;
    str << "Design\\Selection" << i + 1 << ".bmp";
    bSelection [i] = load_bitmap (str.str().c_str (), NULL);
    if (!bSelection [i])
      allegro_message ("Error could not load %s" , str.str().c_str() );
    }

  bBackgrounds [0] = load_bitmap ("Design\\SelectionBackground.bmp",NULL);
  bNone = load_bitmap ("Design\\None.bmp",NULL);

  } // Design::LoadImages

void Design::Action (BITMAP *Buffer, int numHair, int numAddon, int numClothes, int numExtra) {
  Design::Controls ();
  Design::Restrictions (numHair,numAddon, numClothes, numExtra);
  Design::Selector (Buffer);
  Design::HairModel (numHair , Buffer);
  Design::AddonsModel (numAddon, Buffer);
  Design::ClothesModel (numClothes, Buffer);
  Design::ExtraModel (numExtra, Buffer);
  Design::DrawSpriteModel (Buffer, 0);
  Design::PreviewModel (Buffer);
  Design::DrawSprite (Buffer);
  //Design::Hair (numHair , Buffer);
  }

void Design::Controls () {
  if (ChooseOption == false) {

    if (key [KEY_DOWN])
      num ++;
    else if (key [KEY_UP])
      num --;

    if (key [KEY_Z])
      ChooseOption = true;

    } // If ChooseOption = false

  else if (ChooseOption == true) {

    if (key [KEY_Z]){
      setImage [num] = SelectNumX;
      setColour [num] = DropY;
      }

    if (key [KEY_X])
      ChooseOption = false;

    if (key [KEY_RIGHT])
      SelectNumX ++;
    else if (key [KEY_LEFT])
      SelectNumX --;
    if (key [KEY_DOWN]){
      if (dropbox == true) {
        SelectNumY += 40;
        DropY ++;
        }
      dropbox = true;
      }

    else if (key [KEY_UP]) {
      SelectNumY -= 40;
      DropY --;
      }
    } // If ChooseOption = false
  } // Design::Controls ()


void Design::Restrictions (int numHair, int numAddons, int numClothes, int numExtra) {
  // For Selector 
  if (num > 3)
    num = 3;
  else if (num < 0)
    num = 0;

  // For HairModel
  if (num == 0) {
    if (SelectNumX > numHair)
      SelectNumX = 0;
    else if (SelectNumX <0)
      SelectNumX = numHair;
    }

  if (num == 1) {
    if (SelectNumX > numAddons)
      SelectNumX = 0;
    else if (SelectNumX <0)
      SelectNumX = numAddons;
    }

  if (num == 2) {
    if (SelectNumX > numClothes)
      SelectNumX = 0;
    else if (SelectNumX <0)
      SelectNumX = numClothes;
    }

  if (num == 3) {
    if (SelectNumX > numExtra)
      SelectNumX = 0;
    else if (SelectNumX <0)
      SelectNumX = numExtra;
    }


  if (num < 3) {
    if (SelectNumY > 200) {
      SelectNumY = 200;
      DropY = 5;
      }
    else if (SelectNumY < 0) {
      dropbox = false;
      SelectNumY = 0;
      DropY = 0;
      }
    } // if Num < 3

  else {
    if (SelectNumY > 40) {
      SelectNumY = 40;
      DropY = 1;
      }
    else if (SelectNumY < 0) {
      dropbox = false;
      SelectNumY = 0;
      DropY = 0;
      }
    }

  }

void Design::Selector (BITMAP *Buffer) {
  blit (bBackgrounds [0] , Buffer, 0, 0, 0, 0, 640, 480);
  masked_blit (bSelection [num], Buffer, 0, 0, 0, 0, 640, 480);
  textout_centre_ex (Buffer, MainFont , "Hair" , 450 , 45 , makecol (205, 205, 205), -1);
  textout_centre_ex (Buffer, MainFont , "Addons", 450, 165, makecol (205, 205, 205), -1);
  textout_centre_ex (Buffer, MainFont, "Clothes" , 450, 285 , makecol (205, 205, 205), -1);
  textout_centre_ex (Buffer , MainFont , "Extra" , 450, 405 , makecol (205, 205, 205), -1);
  }

void Design::DrawSpriteModel ( BITMAP *Buffer, int Col ) {
  textout_centre_ex (Buffer , MainFont , "Preview" , 90, 370, makecol (205, 205, 205), -1);
  textout_centre_ex (Buffer, MainFont, "Player", 217, 370, makecol (205, 205, 205), -1);
  masked_blit (bNone , Buffer ,32, 0, 30, 400, 32, 32);
  masked_blit (bNone , Buffer ,32, 32, 60, 400, 32, 32);
  masked_blit (bNone , Buffer ,32, 64, 90, 400, 32, 32);
  masked_blit (bNone , Buffer ,32, 96, 120, 400, 32, 32);


  if (num == 0 && ChooseOption == true){
    if (DropY <= 4) {
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 0, 30, 400, 32, 32);
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 32, 60, 400, 32, 32);
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 64, 90, 400, 32, 32);
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 96, 120, 400, 32, 32);
      }
    }

  else if (num == 1 && ChooseOption == true){
    if (DropY <= 4) {
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 0, 30, 400, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 32, 60, 400, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 64, 90, 400, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 96, 120, 400, 32, 32);
      }
    }

  else if (num == 2 && ChooseOption == true) {
    if (DropY <= 4) {
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 0, 30, 400, 32, 32);
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 32, 60, 400, 32, 32);
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 64, 90, 400, 32, 32);
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 96, 120, 400, 32, 32);
      } // if no clothes are selected then draw a blank sprite
    }

  else if (num == 3 && ChooseOption == true) {
    if (DropY <= 0) {
      masked_blit (bExtra [SelectNumX], Buffer, 32, 0, 30, 400, 32, 32);
      masked_blit (bExtra [SelectNumX], Buffer, 32, 32, 60, 400, 32, 32);
      masked_blit (bExtra [SelectNumX], Buffer, 32, 64, 90, 400, 32, 32);
      masked_blit (bExtra [SelectNumX], Buffer, 32, 96, 120, 400, 32, 32);
      }
    }

  }

void Design::PreviewModel (BITMAP *Buffer) {
  masked_blit (bNone , Buffer ,32, 0, 30, 440, 32, 32);
  masked_blit (bNone , Buffer ,32, 32, 60, 440, 32, 32);
  masked_blit (bNone , Buffer ,32, 64, 90, 440, 32, 32);
  masked_blit (bNone , Buffer ,32, 96, 120, 440, 32, 32);

  if (setColour [2] <= 4) {
    masked_blit (bClothes[setImage[2]][setColour[2]], Buffer, 32, 0, 30, 440, 32, 32);
    masked_blit (bClothes[setImage[2]][setColour[2]], Buffer, 32, 32, 60, 440, 32, 32);
    masked_blit (bClothes[setImage[2]][setColour[2]], Buffer, 32, 64, 90, 440, 32, 32);
    masked_blit (bClothes[setImage[2]][setColour[2]], Buffer, 32, 96, 120, 440, 32, 32);
    }

  // Preview
    if (num == 2 && ChooseOption == true) {
    if (DropY <= 4) {
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 0, 30, 440, 32, 32);
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 32, 60, 440, 32, 32);
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 64, 90, 440, 32, 32);
      masked_blit (bClothes [SelectNumX][DropY], Buffer, 32, 96, 120, 440, 32, 32);
      } // if no clothes are selected then draw a blank sprite
    }

  if (setImage [1] > 1 && setColour [1] < 5) {
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 0, 30, 440, 32, 32);
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 32, 60, 440, 32, 32);
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 64, 90, 440, 32, 32);
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 96, 120, 440, 32, 32);
    }

  // Preview
   if (num == 1 && ChooseOption == true){
    if (DropY <= 4 && SelectNumX > 1) {
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 0, 30, 440, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 32, 60, 440, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 64, 90, 440, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 96, 120, 440, 32, 32);
      }
    }

  if (setColour [0] <= 4) {
    masked_blit (bHair[setImage[0]][setColour[0]], Buffer, 32, 0, 30, 440, 32, 32);
    masked_blit (bHair[setImage[0]][setColour[0]], Buffer, 32, 32, 60, 440, 32, 32);
    masked_blit (bHair[setImage[0]][setColour[0]], Buffer, 32, 64, 90, 440, 32, 32);
    masked_blit (bHair[setImage[0]][setColour[0]], Buffer, 32, 96, 120, 440, 32, 32);
    }

  //Preview
   if (num == 0 && ChooseOption == true){
    if (DropY <= 4) {
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 0, 30, 440, 32, 32);
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 32, 60, 440, 32, 32);
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 64, 90, 440, 32, 32);
      masked_blit (bHair[SelectNumX][DropY], Buffer, 32, 96, 120, 440, 32, 32);
      }
    }

  if (setImage [1] <= 1 && setColour [1] <= 4) {
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 0, 30, 440, 32, 32);
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 32, 60, 440, 32, 32);
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 64, 90, 440, 32, 32);
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 96, 120, 440, 32, 32);
    }

  // Preview
   if (num == 1 && ChooseOption == true){
    if (DropY <= 4 && SelectNumX <= 1) {
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 0, 30, 440, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 32, 60, 440, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 64, 90, 440, 32, 32);
      masked_blit (bAddons [SelectNumX][DropY], Buffer, 32, 96, 120, 440, 32, 32);
      }
    }


  if (setColour [3] <= 0) {
    masked_blit (bExtra [setImage [3]], Buffer, 32, 0, 30 , 440 , 32, 32);
    masked_blit (bExtra [setImage [3]], Buffer, 32, 32, 60 , 440 , 32, 32);
    masked_blit (bExtra [setImage [3]], Buffer, 32, 64, 90 , 440 , 32, 32);
    masked_blit (bExtra [setImage [3]], Buffer, 32, 96, 120 , 440 , 32, 32);
    }



  // Preview



 


 

 

  if (num == 3 && ChooseOption == true) {
    if (DropY <= 0) {
      masked_blit (bExtra [SelectNumX], Buffer, 32, 0, 30, 440, 32, 32);
      masked_blit (bExtra [SelectNumX], Buffer, 32, 32, 60, 440, 32, 32);
      masked_blit (bExtra [SelectNumX], Buffer, 32, 64, 90, 440, 32, 32);
      masked_blit (bExtra [SelectNumX], Buffer, 32, 96, 120, 440, 32, 32);
      }
    }

  // End of Preview

 

  }

void Design::DrawSprite ( BITMAP *Buffer ) {
  masked_blit (bNone , Buffer, 32, 0, 200, 400, 32, 32);

  masked_blit (bClothes [setImage[2]][setColour[2]], Buffer, 32, 0, 200, 400, 32, 32);
  if (setImage [1] > 1 && setColour [1] < 5)
    masked_blit (bAddons [setImage[1]][setColour[1]], Buffer, 32, 0, 200, 400, 32, 32);


  masked_blit (bHair [setImage[0]][setColour[0]], Buffer, 32, 0, 200, 400, 32, 32);
  if (setImage [1] <= 1 && setColour [1] < 5)
    masked_blit (bAddons[setImage[1]][setColour[1]], Buffer, 32, 0, 200, 400, 32, 32);
  if (setColour [3] <= 0)
    masked_blit (bExtra [setImage [3]] , Buffer, 32, 0, 200, 400, 32, 32);


  }


void Design::Clothes (int NumClothes) {

  if (SelectNumX > NumClothes) // the number of clothes
    SelectNumX = 0;
  else if (SelectNumX < 0)
    SelectNumX = NumClothes;
  }

//void Design::DrawSprite (BITMAP *Buffer, int Color , int HairNumber) {
//  masked_blit (bNone , Buffer, 32, 0, 50, 400, 32, 32);
//  }

void Design::HairModel (int numHair, BITMAP *Buffer) {
  if (num == 0 && ChooseOption == true) {
    if (ChangeCol) {}

    masked_stretch_blit (bHairModel [SelectNumX][0] , Buffer, 0, 0, 32, 32, 40, 96, 40, 40);

    if (SelectNumX > 0)
      blit (bHairModel [SelectNumX -1][SetColour], Buffer, 0, 0, 10, 100, 32, 32);
    else
      blit (bHairModel [numHair][SetColour], Buffer, 0, 0, 10, 100, 32, 32);

    if (SelectNumX < numHair)
      blit (bHairModel [SelectNumX + 1][SetColour], Buffer, 0, 0, 80, 100, 32, 32);
    else
      blit (bHairModel [0][SetColour], Buffer, 0, 0, 80, 100, 32, 32);

    if (dropbox == true) {
      masked_stretch_blit (bHairModel [SelectNumX][Colour[0]] , Buffer, 0, 0, 32, 32, 40, 136, 40, 40);
      masked_stretch_blit (bHairModel [SelectNumX][Colour[1]] , Buffer, 0, 0, 32, 32, 40, 176, 40, 40);
      masked_stretch_blit (bHairModel [SelectNumX][Colour[2]] , Buffer, 0, 0, 32, 32, 40, 216, 40, 40);
      masked_stretch_blit (bHairModel [SelectNumX][Colour[3]] , Buffer, 0, 0, 32, 32, 40, 256, 40, 40);
      masked_stretch_blit (bHairModel [SelectNumX][Colour[4]] , Buffer, 0, 0, 32, 32, 40, 296, 40, 40)
      }

    rect (Buffer, 40, 96 + SelectNumY, 80, 136 + SelectNumY, makecol (255, 255, 0));

    } // ChooseOption == true
  } // Design::Hair


void Design::AddonsModel (int numAddons , BITMAP *Buffer) {
  if (num == 1 && ChooseOption == true) {
    if (ChangeCol) {}

    masked_stretch_blit (bAddonsModel [SelectNumX][0] , Buffer, 0, 0, 32, 32, 40, 96, 40, 40);

    if (SelectNumX > 0)
      blit (bAddonsModel [SelectNumX -1][SetColour], Buffer, 0, 0, 10, 100, 32, 32);
    else
      blit (bAddonsModel [numAddons][SetColour], Buffer, 0, 0, 10, 100, 32, 32);

    if (SelectNumX < numAddons)
      blit (bAddonsModel [SelectNumX + 1][SetColour], Buffer, 0, 0, 80, 100, 32, 32);
    else
      blit (bAddonsModel [0][SetColour], Buffer, 0, 0, 80, 100, 32, 32);

    if (dropbox == true) {
      masked_stretch_blit (bAddonsModel [SelectNumX][Colour[0]] , Buffer, 0, 0, 32, 32, 40, 136, 40, 40);
      masked_stretch_blit (bAddonsModel [SelectNumX][Colour[1]] , Buffer, 0, 0, 32, 32, 40, 176, 40, 40);
      masked_stretch_blit (bAddonsModel [SelectNumX][Colour[2]] , Buffer, 0, 0, 32, 32, 40, 216, 40, 40);
      masked_stretch_blit (bAddonsModel [SelectNumX][Colour[3]] , Buffer, 0, 0, 32, 32, 40, 256, 40, 40);
      masked_stretch_blit (bAddonsModel [SelectNumX][Colour[4]], Buffer, 0, 0, 32, 32, 40, 296, 40, 40)
      }

    rect (Buffer, 40, 96 + SelectNumY, 80, 136 + SelectNumY, makecol (255, 255, 0));

    } // ChooseOption == true
  }

void Design::ClothesModel (int numClothes, BITMAP *Buffer) {
  if (num == 2 && ChooseOption == true) {
    if (ChangeCol) {}

    masked_stretch_blit (bClothesModel [SelectNumX][0] , Buffer, 0, 0, 32, 32, 40, 96, 40, 40);

    if (SelectNumX > 0)
      blit (bClothesModel [SelectNumX -1][SetColour], Buffer, 0, 0, 10, 100, 32, 32);
    else
      blit (bClothesModel [numClothes][SetColour], Buffer, 0, 0, 10, 100, 32, 32);

    if (SelectNumX < numClothes)
      blit (bClothesModel [SelectNumX + 1][SetColour], Buffer, 0, 0, 80, 100, 32, 32);
    else
      blit (bClothesModel [0][SetColour], Buffer, 0, 0, 80, 100, 32, 32);

    if (dropbox == true) {
      masked_stretch_blit (bClothesModel [SelectNumX][Colour[0]] , Buffer, 0, 0, 32, 32, 40, 136, 40, 40);
      masked_stretch_blit (bClothesModel [SelectNumX][Colour[1]] , Buffer, 0, 0, 32, 32, 40, 176, 40, 40);
      masked_stretch_blit (bClothesModel [SelectNumX][Colour[2]] , Buffer, 0, 0, 32, 32, 40, 216, 40, 40);
      masked_stretch_blit (bClothesModel [SelectNumX][Colour[3]] , Buffer, 0, 0, 32, 32, 40, 256, 40, 40);
      masked_stretch_blit (bClothesModel [SelectNumX][Colour[4]], Buffer, 0, 0, 32, 32, 40, 296, 40, 40)
      }

    rect (Buffer, 40, 96 + SelectNumY, 80, 136 + SelectNumY, makecol (255, 255, 0));

    } // ChooseOption == true
  }

void Design::ExtraModel (int numExtra, BITMAP *Buffer) {
  if (num == 3 && ChooseOption == true) {
    if (ChangeCol) {}

    masked_stretch_blit (bExtraModel [SelectNumX], Buffer, 0, 0, 32, 32, 40, 96, 40, 40);

    if (SelectNumX > 0)
      blit (bExtraModel [SelectNumX -1], Buffer, 0, 0, 10, 100, 32, 32);
    else
      blit (bExtraModel [numExtra], Buffer, 0, 0, 10, 100, 32, 32);

    if (SelectNumX < numExtra)
      blit (bExtraModel [SelectNumX + 1], Buffer, 0, 0, 80, 100, 32, 32);
    else
      blit (bExtraModel [0], Buffer, 0, 0, 80, 100, 32, 32);

    if (dropbox == true) {
      masked_stretch_blit (bExtraModel [5], Buffer, 0, 0, 32, 32, 40, 136, 40, 40);
      }

    rect (Buffer, 40, 96 + SelectNumY, 80, 136 + SelectNumY, makecol (255, 255, 0));

    } // ChooseOption == true
  }


void Design::ColorPalette (BITMAP *Buffer) {
  if (DropY == 0)
    rectfill (Buffer, 0, 0, 10, 10, makecol (10, 10, 10));
  else if (DropY == 1)
    rectfill (Buffer, 0, 0, 10, 10, makecol (200, 200, 200));
  else if (DropY == 2)
    rectfill (Buffer, 0, 0, 10, 10, makecol (222, 0, 0));
  else if (DropY == 3)
    rectfill (Buffer, 0, 0, 10, 10, makecol (0, 250, 250));
  else
    rectfill (Buffer, 0, 0, 10, 10, makecol (250, 250, 0));
  }



Now I wanted to know if it's good programming practice to put all those functions into one class or
would it be better to separate them and put them into different classes?

Thanks in Advance
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Mon Dec 13, 2010 2:29 am   Post subject: RE:Is This Good Programming Practice?

At a quick glance, it seems there's little reason to be using classes here at all. Instead, namespaces might be a better fit.
DrummaBoyFB




PostPosted: Mon Dec 13, 2010 4:02 am   Post subject: Re: Is This Good Programming Practice?

ok thanks. But a quick question. What are the benefits of using namespaces over classes in certain situations and when do you know when to use a namespace over a class?
wtd




PostPosted: Mon Dec 13, 2010 4:19 am   Post subject: RE:Is This Good Programming Practice?

Well, look at the way you use your class. From what I can see, your constructor simply initializes a set of instance variables. There are no inputs to the constructor, so those variables are always the same. None of your member functions seem to modify any of those member variables.

What you seem to have is a set of related variables and functions all grouped into one "thing." This is exactly what namespaces are intended for.
DrummaBoyFB




PostPosted: Mon Dec 13, 2010 4:28 am   Post subject: Re: Is This Good Programming Practice?

ohh ok thank you sooo much Very Happy. I never knew what the purpose of them was until now
DrummaBoyFB




PostPosted: Mon Dec 13, 2010 12:31 pm   Post subject: Re: Is This Good Programming Practice?

One quick question.
Should I put the class inside the namespace? Or do without the class?
[Gandalf]




PostPosted: Mon Dec 13, 2010 1:30 pm   Post subject: RE:Is This Good Programming Practice?

That would make your class redundant, because currently you are using your class like a namespace. Just put it in a namespace. If, in the future, you make more entities like "Design", then you may want to put them in the same namespace, or not.
DrummaBoyFB




PostPosted: Mon Dec 13, 2010 3:42 pm   Post subject: Re: Is This Good Programming Practice?

Ok thanks for the info I really appreciate it Very Happys
Sponsor
Sponsor
Sponsor
sponsor
DrummaBoyFB




PostPosted: Tue Dec 14, 2010 7:31 pm   Post subject: Re: Is This Good Programming Practice?

So should I put the namespace in a header file then declare all the stuff in a .cpp file like I do with classes?
Or should I just do everything with a header file?

Because I'm trying to declare variables in the .cpp file but it won't work.
So I was thinking of just putting everything into a header file but I was wondering if that's good programming practice
crossley7




PostPosted: Wed Dec 15, 2010 10:03 am   Post subject: RE:Is This Good Programming Practice?

if you use global variables in your header file, either declare them before you declare the heared file (not ideal) or declare them at the top of the header file, and then they will work in the .cpp file still.

That is my thoughts from my recent usage of header files
DrummaBoyFB




PostPosted: Wed Dec 15, 2010 11:52 am   Post subject: Re: Is This Good Programming Practice?

No I'm talking about using namespaces in header files
wtd




PostPosted: Wed Dec 15, 2010 2:05 pm   Post subject: RE:Is This Good Programming Practice?

Your namespace should be declared in a header file, but then implemented in an implementation file.
DrummaBoyFB




PostPosted: Wed Dec 15, 2010 3:09 pm   Post subject: Re: Is This Good Programming Practice?

So basically just like a class?
(Sorry for all the questions I'm just trying to understand you better)
DrummaBoyFB




PostPosted: Wed Dec 22, 2010 11:32 am   Post subject: Re: Is This Good Programming Practice?

wtd... I re-looked at what you said but if you check in my code I do modify values of my member variables in my functions.
So should I just stick to classes then?
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: