Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    14
  • comments
    15
  • views
    10613

Release!

Sign in to follow this  
Ceoddyn

262 views



I've completely my first game titled Console Combat 1. Yay! It's currently in the Showcase: Console Combat 1


Source code is included and it's licensed under the do whatever the hell you want with any of my code (not that you would want to use that ugly uncommented clusterfuck) license(TM).

Error handling is rather difficult in the console (mostly input at wrong times) so attempting to screw it up will in fact screw it up. I also couldn't figure out how to allow spaces in input for the name, so that's out too.

Overall though, I'm happy with how it turned out and it makes for a fun little 10 minute time-waster. I learned a lot about OO design and why I need to use more commenting next time around. I also need to abstract things better functionally as well because I had a lot of word-for-word rewritten code.

On to Console Combat 2.
Sign in to follow this  


6 Comments


Recommended Comments

Quote:

Error handling is rather difficult in the console (mostly input at wrong times) so attempting to screw it up will in fact screw it up. I also couldn't figure out how to allow spaces in input for the name, so that's out too.


For spaces in string input, just use getline.


std::string Name = "";
std::getline( std::cin, Name );
std::cout << Name << std::endl;


and you can detect incorrect input like this:


int Number = 0;
std::cin >> Number;
if( !std::cin )
{
std::cout << "Error, bad input." << std::endl;
//clear the input buffer
std::cin.clear();
std::cin.ignore( BUFSIZ, '\n');
}
else
{
std::cout << Number << std::endl;
}


You'll have to implement your own check for strings though since it's possible to enter anything as a string.

Edit: I assuming this is C++.

Share this comment


Link to comment
I used to have a senior programmer right at the beginning of my career that used to drill into me that he wanted to see more 'green' in my code (green was the default colour of comment syntax highlighting). So I did - every line.

I learned through years of commercial programming that in fact comments became a hindrance in code that has evolved because although the code has evolved the comments mostly didn't. Not how it should be though.

So, my working practice these days is to make sure that your code is self-commented through the use of variable names so that the next person even if that is you can pick up that code and work out quickly what your intentions were. I will still stick in a comment block every now and then when the code I am writing somehow got out of control and became complicated.

Not the best code out of my set... but one that uses the 'name things as they are' rule:


if(m_bPathSeeker)
{
PathSeek(fTimeDelta);

// Time to fire?
if(m_pPath->AreWeAllowedToFire(m_dwPathNodeIndex))
{
m_fCurrentFiringTime += fTimeDelta;

if(m_fCurrentFiringTime >= m_fFiringDelay)
{
switch(m_eFiringType)
{
case ACTOR_FIRING_ONE_SHOT:
if(!m_bFired)
{
FireBullet();
}
break;

case ACTOR_FIRING_CONTINUOUS:
FireBullet();
m_fCurrentFiringTime = 0.0f;
break;

case ACTOR_FIRING_RANDOM:
FireBullet();
m_fFiringDelay = CMath::RandomFloat() * m_fFireRandomPeriod;
m_fFiringDelay += m_fRandomBase;
break;
}

}
}
}



However, all of the above is subjective to style and that is my particular style.

Share this comment


Link to comment
I've actually been working on the same thing, but I implemented a Windows-specific console manipulation class that allows you to set the width and height of the window/buffer, and some functions that allow you to output in color, get keypresses, and a cin-like function (if you specify the space character for the 'watch this/these for keypresses' string, you could set two-word names. [wink]). Unfortunately I've been working on that more than I have the actual game. [lol]

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!