Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    2
  • comments
    3
  • views
    2261

Entries in this blog

 

TicTacToe... Sorta.

Ok, if you read my previous entry you will note that I am working on a totally stellar adaptation of TicTacToe for the console. After running across a heap of issues I have decided to flex my class making skills. First I need to figure out what classes I need and how they will relate to each other.

What exactly am I going to be doing in its simplest form?
o Displaying a Main Menu.
o Displaying a Game Menu.

What does Main Menu have?
o Some options to choose from.
o Accept some input.
o Do stuff with that input.

Does all of that need to be in one class? Is a class even needed? Good question. Let's lay out some pseudo code.

class MainMenu
{
void dispMnu();
void getInput();
string parseInput();
}
Ok, semi sexy I suppose. We are defiantly missing something. Aha! Private variables to store junk in.

class MainMenu
{
public:
void dispMnu();
void getInput();
string parseInput();
private:
string menu;
string input;
}
Sexy! I think we can make 'string menu' a little better though. Let's make that sucker a constant. Which I have been told is way better. Some even say its better than being rich. I like to collectively call those people idiots.

class MainMenu
{
public:
void dispMnu();
void getInput();
string parseInput();
private:
const string menu = "->TicTacToe string input;
}
Now that's what I call one sexy menu. Throw in some particle effects and were rocking. Let's move onward to the easy stuff. Who am I kidding? Oh by the way, I am told that that what I did with 'string menu' was called inline definition. Whatever, let me cut and paste this crap into Visual Studio and listen to it whine and moan.

And we're back! Ok, after about 500 million errors it keeps moaning at me for trying to give 'string menu' a value at declaration. Also I forgot 'std::' for the strings. Here is our new and improved class! OMG, the suspense is killing me! My spell checker tells me 'OMG' is not a word.

class MainMenu
{
public:
void dispMnu() {};
void getInput() {};
string parseInput() {};
private:
const std::string mnuText;
std::string input;
};
See that semicolon at the last line? Yea, rookie mistake, reminds me to facilitate the sudden death of that darned rookie who keeps wondering around here stealing my socks. Since I obviously am not allowed to both declare and define a variable in a class declaration, let's cook up a constructor that does it.

MainMenu::MainMenu()
{
mnuText = "->TicTacToe\n(1)New Game\n(2)Quit\nChoice:";
}
Titillating as you can see. Probably won't compile because CPP hates me, but it's worth a try at least. Now let's make 'void dispMnu()' shoot some fireballs or some such.

MainMenu::dispMnu()
{
std::cout getInput();
}
Not the fireball I was looking for, but I guess it will have to do. Since 'dispMnu' is taking advantage of 'getInput' I guess I should define it.

MainMenu::getInput()
{
std::getline(std::cin, input);
parseInput();
}
Could be a lot better, but for now I'm leaving it as is. I'm seeing a pattern here. I keep calling a function from within a function. That could be bad I guess. Perhaps I need to make some of them private.

class MainMenu
{
public:
MainMenu();
void dispMnu();
private:
void getInput();
string parseInput();
const std::string mnuText;
std::string input;
};
Heck, on second thought, do I even need 'getInput'? Let's rework it and see.

class MainMenu
{
public:
MainMenu();
void dispMnu();
private:
string parseInput();
const std::string mnuText;
std::string input;
};

MainMenu::dispMnu()
{
std::cout std::getline(std::cin, input);
parseInput();
}
Looks pretty sexy so far, let's move on to parsing the players input. I'm beginning to weep openly here.

MainMenu::parseInput()
{
if(input == "1")
{
return "NEWGAME";
}
else if(input == "2")
{
return "EXIT";
}
else
{
return "WTF";
}
}
A strange man once told me that using numbers that magically have some other value is bad. I can dig that. So instead I am going to return a string that says something. Some could argue that using an enumeration would be better, but they greatly underestimate how lazy I truly am. I guess that concludes the work on 'MainMenu'. Who am I kidding, my computer is going to vomit urine when I try and compile that. Tune in tomorrow for the exciting conclusion of 'MainMenu'!

-JetSirus-

-JetSirus-

 

Hmm... OOP?

Well, after a few weeks of working with CPP I am starting to get the hang of things, to an extent at least. A problem I am often confronting is my complete disregard for an old and true saying, KISS, or Keep It Simple Stupid. I tend to so over complexify even the most simple of programming task that I loose track of my original goal. To this extent I have decided to completely scrap my ever so awesome rendition of Classic Tetris. By awesome I mean merely OK, and by merely OK I mean total crap. It does however look awful sexy in full, awe inspiring system text. But I digress.

In it's current state it uses many functions, separate .h and .cpp files and whatnot. Sadly though, not a single Class is used. I'm gonna have to look into inheritance some more before I am fully comfortable with Classes. As it stands, I get this almost school-girl giddiness while thinking of making a monster Class that does everything I could ever imagine. Including foot massages. On the other hand I hate getting slapped around by the CPP god's for such travesties, so I will have to KISS it. Bleh... Bad pun.

For the moment I need to come up with a more user friendly form of input. Currently I use a Row/Column system. Rows being 0,1,3 and columns being A,B,C. It gets hairy when the player chooses a square. Enter 'a0x' for example and viola a shiny new 'X' appears in the top left square. While that's completely understandable for your standard Harvard graduate, I get a feeling that little Timmy will either wet himself or start crying when trying to piece it all together. Perhaps both when the game crashes.

I will post another update soon. For the moment though I leave you with the following:
if(KISS == FALSE) {
myHead->Explode.Wait(3);
}

-JetSirus-

-JetSirus-

Sign in to follow this  
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!