Be the first to post for 'Instantiating Your Class'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

I shared my .hdd file on a different thread. In filling in FBullCowGame.cpp I tweaked the .hdd as part of looking at the logical structure more.

There are two differences in the approach I am taking.

First, I made the class one that has to be instantiated each time for a new game. This is with a constructor that accepts SecretWord as a parameter. I have completely separated the determination of SecretWord values from the FBullCowGame class. In this approach, there is no Reset() method or anything like that An instance must be created for each play of the game. This is entirely to my own taste and is merely one of many ways to design an FBullCowGame class.

Secondly, I put guards in all of the methods, as far as I could without having complete implementations for many methods. By guards I mean the in-class use of IsOnlyLetters(), IsCorrectLength(), and IsGoodIsogram() to guard responses and also to ensure that SecretWord itself qualifies as a good Isogram.

It is intended that instances will not fail. (If SecretWord is itself bad, it is set to an empty string, std::string(""), and no guess will succeed in any way. Likewise if CheckGuess() has not been used yet.

I am not certain how much this explanation is helpful for beginners. The code demonstrates one way of defending the methods against working with bad or missing data without failing. As I said already, this is to my taste and not something anyone else might do and certainly not if this is unclear. I offer it as just one other way to come at the problem of guaranteeing an interface contract. (For more experienced developers, I caution that efficiency is unimportant in this specific problem.)

I started putting my Section02 on GitHub also and you can see the files there.

Here’s the current FBullCowGame.cpp skeleton with dummy implementations (and TODOs) for key methods:

/* FBullCowGame.cpp 0.0.3            UTF-8                        2016-12-23 */
/* ------1---------2---------3---------4---------5---------6---------7------ */

#include "FBullCowGame.hpp"

FBullCowGame::FBullCowGame(std::string SecretWord)
{
    MySecret = SecretWord;
    MyCurrentGuess = SecretWord;
    if (!IsGoodIsogram())
        MySecret = std::string("");
    MyCurrentGuess = std::string("");
    MyBulls = 0;
    MyCows = 0;
    MyWellFormedTries = 0;
    MySuggestedMaxTries = 7;
}

unsigned FBullCowGame::WordSize()
{
    return MySecret.length();
}

void FBullCowGame::CheckGuess(std::string Guess)
{
    MyCurrentGuess = Guess;
    if (IsGoodIsogram()) MyWellFormedTries++;
}

bool FBullCowGame::IsOnlyLetters()
{
    if (MyCurrentGuess.length() == 0) return false;

    return false; 
        // TODO: Add Logic
}

bool FBullCowGame::IsCorrectLength()
{
    if (!IsOnlyLetters()) return false;

    return MyCurrentGuess.length() == MySecret.length();
}

bool FBullCowGame::IsGoodIsogram()
{
    if (!IsCorrectLength()) return false;

    return false; 
        // TODO: Add Logic
}

bool FBullCowGame::IsSecretGuessed()
{
    if (!IsGoodIsogram()) return false;

    return Bulls() == MySecret.length();
}

unsigned FBullCowGame::Bulls()
{
    if (!IsGoodIsogram()) return 0;

    return MyBulls;
        // Needs to actually figure it out, based on good isogram

}

unsigned FBullCowGame::Cows()
{
    if (!IsGoodIsogram()) return 0;
    return MyCows;
        // Likewise, nice to get Bulls and Cows in one pass but no biggie.
}

unsigned FBullCowGame::WellFormedTries()
{
    return MyWellFormedTries;
}

unsigned FBullCowGame::SuggestedMaxTries()
{
    return MySuggestedMaxTries;
}

Hello Ben, and all the people taking up this course. This is my first post (reply) just to say HI. Hope you all are learning and enjoying this new video series. I am very much eager to get a good understanding of C++ from this course and want to start using Unreal for sure. This is my first time that I will be using Unreal and C++ entirely, as I learned C++ in my college a long time ago (2005) and haven’t used it much since then. I am a game developer from INDIA using Unity 3D. I am very much new to Unreal. I enrolled for this course to enhance and expand my skills even more. Have fun.
Regards,
Iceheros :slight_smile:

Privacy & Terms