Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


#ActualKhatharr

Posted 23 December 2012 - 12:53 AM

I just want to point out: Plugging in graphics after isn't as easy as you think. You can't take something in the command line and add graphics without almost completely rewriting it. When I got started, that's what I thought, and it's not true.

 

This is true. However, once you've worked with graphics based programs for a while it's easy to write a graphics-ish program that uses the console as a place-holder for the graphics routines. What you're doing here (OP) is actually close to the correct way of going about this because of things like "Difficulty Game::GetDifficulty()". Once you switch to a graphics based program you can replace that function with one that gets the desired input from a GUI widget. However, I'd suggest putting the string-grab and int conversion on the outside of the function here and then passing them in as arguments. This way once you want to get the selection from a GUI widget you can just pass that as an index into the function you already have, yes?

 

All that being said, the two functions you showed here are using an awful lot of space and not doing much. Maybe something like this:

 

enum GameMode : unsigned { //enums will automatically define each successive value as the previous value + 1
  COMPUTER_PLAYER = 0,
  PLAYER_COMPUTER,
  GAMEMODE_ENTRY_COUNT //if new entries are added place them prior to this one
};

GameMode Game::GetGameMode() {
  while(1) {
    //get user input
    GameMode gameMode = (GameMode)(ToInt(StringInput()));
    
    //Check for validity
    if(gameMode < GAMEMODE_ENTRY_COUNT) {
      return gameMode;
    }
    
    //validity failed, so show message and reloop
    cout << "Please enter a valid choice using the number next to your desired game mode." << endl;
    cout << "Press ENTER to try again..." << endl;
    cin.get();
    DisplayGameMode();
  }

  return SOME_INVALID_VALUE; //to shut the compiler up
}

#7Khatharr

Posted 23 December 2012 - 12:40 AM

I just want to point out: Plugging in graphics after isn't as easy as you think. You can't take something in the command line and add graphics without almost completely rewriting it. When I got started, that's what I thought, and it's not true.

 

This is true. However, once you've worked with graphics based programs for a while it's easy to write a graphics-ish program that uses the console as a place-holder for the graphics routines. What you're doing here (OP) is actually close to the correct way of going about this because of things like "Difficulty Game::GetDifficulty()". Once you switch to a graphics based program you can replace that function with one that gets the desired input from a GUI widget. However, I'd suggest putting the string-grab and int conversion on the outside of the function here and then passing them in as arguments. This way once you want to get the selection from a GUI widget you can just pass that as an index into the function you already have, yes?

 

All that being said, the two functions you showed here are using an awful lot of space and not doing much. Maybe something like this:

 

enum GameMode : unsigned {
  COMPUTER_PLAYER = 0,
  PLAYER_COMPUTER,
  GAMEMODE_ENTRY_COUNT //if new entries are added place them prior to this one
};

GameMode Game::GetGameMode() {
  while(1) {
    //get user input
    GameMode gameMode = (GameMode)(ToInt(StringInput()));
    
    //Check for validity
    if(gameMode < GAMEMODE_ENTRY_COUNT) {
      return gameMode;
    }
    
    //validity failed, so show message and reloop
    cout << "Please enter a valid choice using the number next to your desired game mode." << endl;
    cout << "Press ENTER to try again..." << endl;
    cin.get();
    DisplayGameMode();
  }

  return SOME_INVALID_VALUE; //to shut the compiler up
}

#6Khatharr

Posted 23 December 2012 - 12:39 AM

I just want to point out: Plugging in graphics after isn't as easy as you think. You can't take something in the command line and add graphics without almost completely rewriting it. When I got started, that's what I thought, and it's not true.

 

This is true. However, once you've worked with graphics based programs for a while it's easy to write a graphics-ish program that uses the console as a place-holder for the graphics routines. What you're doing here (OP) is actually close to the correct way of going about this because of things like "Difficulty Game::GetDifficulty()". Once you switch to a graphics based program you can replace that function with one that gets the desired input from a GUI widget. However, I'd suggest putting the string-grab and int conversion on the outside of the function here and then passing them in as arguments. This way once you want to get the selection from a GUI widget you can just pass that as an index into the function you already have, yes?

 

All that being said, the two functions you showed here are using an awful lot of space and not doing much. Maybe something like this:

 

enum GameMode {
  COMPUTER_PLAYER,
  PLAYER_COMPUTER,
  GAMEMODE_ENTRY_COUNT
};

GameMode Game::GetGameMode() {
  while(1) {
    //get user input
    GameMode gameMode = (GameMode)(ToInt(StringInput()));
    
    //Check for validity
    if(gameMode < GAMEMODE_ENTRY_COUNT) {
      return gameMode;
    }
    
    //validity failed, so show message and reloop
    cout << "Please enter a valid choice using the number next to your desired game mode." << endl;
    cout << "Press ENTER to try again..." << endl;
    cin.get();
    DisplayGameMode();
  }

  return SOME_INVALID_VALUE; //to shut the compiler up
}

#5Khatharr

Posted 23 December 2012 - 12:36 AM

I just want to point out: Plugging in graphics after isn't as easy as you think. You can't take something in the command line and add graphics without almost completely rewriting it. When I got started, that's what I thought, and it's not true.

 

This is true. However, once you've worked with graphics based programs for a while it's easy to write a graphics-ish program that uses the console as a place-holder for the graphics routines. What you're doing here (OP) is actually close to the correct way of going about this because of things like "Difficulty Game::GetDifficulty()". Once you switch to a graphics based program you can replace that function with one that gets the desired input from a GUI widget. However, I'd suggest putting the string-grab and int conversion on the outside of the function here and then passing them in as arguments. This way once you want to get the selection from a GUI widget you can just pass that as an index into the function you already have, yes?

 

All that being said, the two functions you showed here are using an awful lot of space and not doing much. Maybe something like this:

 

GameMode Game::GetGameMode() {
  /*
  If you start the GameMode enum at zero and let it increment values automatically then you can just check if the user
  choice is less than or equal to the max value and greater than zero rather than the array and for-loop method here.
  Just remember that if you do that then you'll have to be absolutely sure to update the max value in the test in this 
  function if you add an enum value. (One way of doing this is making the last enum value be GAMEMODE_ENTRY_COUNT and then 
  just test for less than that value. New entries would come before that value, so it would update automatically.)
  */
  const size_t NUM_VALID_MODES = 2;
  GameMode validModes[NUM_VALID_MODES] = {COMPUTER_PLAYER, PLAYER_COMPUTER};
  
  GameMode gameMode = (GameMode)(ToInt(StringInput()));
  
  bool valid = false;
  while(valid == false) {
    //Check for validity
    for(int i = 0; i < NUM_VALID_MODES; ++i) {
      if(gameMode == validModes[i]) {
        return gameMode;
      }
    } //ends for(i < NUM_VALID_MODES)
    
    //validity failed, so show message and reloop
    cout << "Please enter a valid choice using the number next to your desired game mode." << endl;
    cout << "Press ENTER to try again..." << endl;
    cin.get();
    DisplayGameMode();
  } //ends while(valid == false)

  return SOME_INVALID_VALUE;
}

#4Khatharr

Posted 23 December 2012 - 12:33 AM

I just want to point out: Plugging in graphics after isn't as easy as you think. You can't take something in the command line and add graphics without almost completely rewriting it. When I got started, that's what I thought, and it's not true.

 

This is true. However, once you've worked with graphics based programs for a while it's easy to write a graphics-ish program that uses the console as a place-holder for the graphics routines. What you're doing here (OP) is actually close to the correct way of going about this because of things like "Difficulty Game::GetDifficulty()". Once you switch to a graphics based program you can replace that function with one that gets the desired input from a GUI widget. However, I'd suggest putting the string-grab and int conversion on the outside of the function here and then passing them in as arguments. This way once you want to get the selection from a GUI widget you can just pass that as an index into the function you already have, yes?

 

All that being said, the two functions you showed here are using an awful lot of space and not doing much. Maybe something like this:

 

GameMode Game::GetGameMode() {
  /*
  If you start the GameMode enum at zero and let it increment values automatically then you can just check if the user
  choice is less than or equal to the max value and greater than zero rather than the array and for-loop method here.
  */
  const size_t NUM_VALID_MODES = 2;
  GameMode validModes[NUM_VALID_MODES] = {COMPUTER_PLAYER, PLAYER_COMPUTER};
  
  GameMode gameMode = (GameMode)(ToInt(StringInput()));
  
  bool valid = false;
  while(valid == false) {
    //Check for validity
    for(int i = 0; i < NUM_VALID_MODES; ++i) {
      if(gameMode == validModes[i]) {
        return gameMode;
      }
    } //ends for(i < NUM_VALID_MODES)
    
    //validity failed, so show message and reloop
    cout << "Please enter a valid choice using the number next to your desired game mode." << endl;
    cout << "Press ENTER to try again..." << endl;
    cin.get();
    DisplayGameMode();
  } //ends while(valid == false)

  return SOME_INVALID_VALUE;
}

#3Khatharr

Posted 23 December 2012 - 12:29 AM

I just want to point out: Plugging in graphics after isn't as easy as you think. You can't take something in the command line and add graphics without almost completely rewriting it. When I got started, that's what I thought, and it's not true.

 

This is true. However, once you've worked with graphics based programs for a while it's easy to write a graphics-ish program that uses the console as a place-holder for the graphics routines. What you're doing here (OP) is actually close to the correct way of going about this because of things like "Difficulty Game::GetDifficulty()". Once you switch to a graphics based program you can replace that function with one that gets the desired input from a GUI widget. However, I'd suggest putting the string-grab and int conversion on the outside of the function here and then passing them in as arguments. This way once you want to get the selection from a GUI widget you can just pass that as an index into the function you already have, yes?

 

All that being said, the two functions you showed here are using an awful lot of space and not doing much. Maybe something like this:

 

GameMode Game::GetGameMode() {
  /*
  If you start the GameMode enum at zero and let it increment values automatically then you can just check if the user
  choice is less than or equal to the max value and greater than zero rather than the array and for-loop method here.
  */
  const size_t NUM_VALID_MODES = 2;
  GameMode validModes[NUM_VALID_MODES] = {COMPUTER_PLAYER, PLAYER_COMPUTER};
  
  GameMode gameMode = (GameMode)(ToInt(StringInput()));
  
  bool valid = false;
  while(valid == false) {
    //Check for validity
    for(int i = 0; i < NUM_VALID_MODES; ++i) {
      if(gameMode == validModes[i]) {
        return gameMode;
      }
    } //ends for(++i < NUM_VALID_MODES)
    
    //validity failed, so show message and reloop
    cout << "Please enter a valid choice using the number next to your desired game mode." << endl;
    cout << "Press ENTER to try again..." << endl;
    cin.get();
    DisplayGameMode();
  } //ends while(valid == false)

  return SOME_INVALID_VALUE;
}

PARTNERS