My BCGame w/ level difficulty and hints

I did section 2 a while back but felt that I had to come back to it since I started the Blender Complete course that Ben and Micheal teach. I finally learned how to use the lecture discussion boards and it made a world difference in my learning.

Anyways, following along with Ben I was able to rebuild my previous work and create a game that allowed the user to select the difficulty and get a hint to help them play the game.

I come from a web development background so I see areas where the code could be shorter but I couldn’t get it to work that way. So section 2 forced me to think differently. I hope you guys like my game. I created a gist where you can download a copy of my game. It originally wasn’t that different from our Instructor’s code but I decided that in order to showcase the improvement that I made easily. I need most of the code to look like his so that you all could find my code within the code.

At the bottom of FBullCowGame.cpp you will find 3 new functions that I made. They correspond to what is in the FBullCowGame.h file. In main.cpp there is a function called GetPlayerChoice() that handle allowing the player to choose the level of difficulty.

Please run the code and tell me what you think. You can comment here or at the gist.
Below is the link to the code.

2 Likes

Nice work!

I have no suggestions in terms of coding, it looks quite solid to me :+1:
Ah, ok, a small one:
You could use a switch statement instead of the “if() {} else if() {}” thing in FBullCowGame::ChooseIsogram
Oh and you should have some kind of error handling in FBullCowGame::ChooseIsogram too, since the player could write anything.

On to game design stuff:
I like the idea with the hints, but I think you are basically sabotaging the basic game mechanic a lot with that. It’s much easier to guess the word with a hint, so I feel like there should be a trade off, like getting only one try after asking for a hint.
And the player shouldn’t just get the hint at the beginning of the game, he should have to ask for it.
Maybe you could make it so that if the player has only 20 % of tries remaining but none of his previous guesses were close to finding the right word (maybe less 60 % of letters were Bulls/Cows?) then the game asks the player if he wants a hint.

Also, the game says “You want to play again with the same word?” and that’s not true, you can choose a new one in PrintIntro(). But that’s an easy fix.

Ok, honestly that’s quite a lot of work for a simple game like this and I personally wouldn’t do it.
Anyway, that’s what I came up with in terms of suggestions :slight_smile:

2 Likes

Pretty neat suggestions indeed, maybe i use these make the game little bit more “player friendly”.

Thanks mate :sunglasses:

1 Like

Big thanks to you mate, i was dashing the web to find what was missing with my function :

FString FBullCowGame::SelectIsogram(int32 number) const
{
	
	TMap<int32, FString> OurHiddenWord{ {3,"jam" },{4,"base" },{5,"space" },{6,"planet" },{7,"whoring"} };
	return OurHiddenWord[number];

}`Preformatted text`

And you showed me:

FString FBullCowGame::ChooseIsogram(FString Choice)
{
	TMap<FString, FString> BuzzWord
	{
		{ "3", "cat" },
		{ "4", "time" },
		{ "5", "plane" },
		{ "6", "planet" },
		{ "7", "stumped" }
	};

	if (Choice == "3")
	{
		MyHiddenWord = BuzzWord[Choice];
	}
	else if (Choice == "4")
	{
		MyHiddenWord = BuzzWord[Choice];
	}
	else if (Choice == "5")
	{
		MyHiddenWord = BuzzWord[Choice];
	}
	else if (Choice == "6")
	{
		MyHiddenWord = BuzzWord[Choice];
	}
	else if (Choice == "7")
	{
		MyHiddenWord = BuzzWord[Choice];
	}

	MyHiddenWord = BuzzWord[Choice];

	return MyHiddenWord;
}

FString FBullCowGame::GetPlayerChoice(FString Choice)
{
	FString PlayerChoice = ChooseIsogram(Choice);

	return PlayerChoice;
}
indent preformatted text by 4 spaces

altough what @DerTee is suggesting about Switch statements can be really usefull rather than using if{} else{}.

@Doctorhawkeye
I don’t know what’s wrong with your solution. In fact it’s better than @Rafael_Cortes’s solution, because he’s basically doing the same thing twice:
First, he builds a data structure containing the values for various word lengths, then he does a big if-statement and handles every single data point of the data structure. He could instead just go directly without using a TMap:

/* I just formatted the code this way to minimize scrolling, would't recommend it in real code */
	if (Choice == "3") { MyHiddenWord = "cat"; }
	else if (Choice == "4") { MyHiddenWord = "time"; }
	else if (Choice == "5") { MyHiddenWord = "plane"; }
	else if (Choice == "6") { MyHiddenWord = "planet"; }
	else if (Choice == "7") { MyHiddenWord = "stumped"; }

My guess is that there was a different issue here which lead him to this solution, since @Rafael_Cortes is a professional dev and surely knows about stuff like this.

My solution is very much along the lines of yours:

/* Snippet from my FBullCowGame.cpp*/

// initalises to an incomplete state because the word length is unknown at this point
// GenerateHiddenWord() MUST be called before any guessing!
void FBullCowGame::Reset()
{
	const FString HIDDEN_WORD = ""; // broken state, that is set because hidden word length is still unknown
	MyHiddenWord = HIDDEN_WORD;

	MyCurrentTry = 1;

	bIsGameWon = false;

	WordLengthToIsogram = {
		{ 3, "sun" },
		{ 4, "glue" },
		{ 5, "plane" },
		{ 6, "beauty" },
		{ 7, "hexagon" }
	};

	return;
}

// Uses given wordlength to generate a hidden word. Has to be called before any guessing.
void FBullCowGame::GenerateHiddenWord(int32 PlayerWordLength)
{
	FString HiddenWord = WordLengthToIsogram[PlayerWordLength];
	MyHiddenWord = HiddenWord;
	return;
}

UPDATE ( after trying @Rafael_Cortes’s solution) : I tried to use his/her code in a (1) modificated way and (2) directly writing down everything ofcourse adding the functions etc. Unfortunately both of them did not work for me even after the sometime my code come to the point that it kind of looked like corrupted : I saw the 2 Bulls or Cows drawn by @Rafael_Cortes even though i did not add those things in my code after the first attempt when i was trying ( I added them first time because they were COOL, i have deleted them afterwards).

Probably i will try to use your way when i have time, maybe it works this time. :thinking:

Do tell what was wrong with your initial solution if you find out, I’d be interested in that.

Like I have said been in the Blender course too long and missed this message. But yea, I agree with you that I could have used a switch statement here. In fact, it was the first thing that came to mind. But I was forced to step away from my PC and when I came back I went with the latter solution, don’t really know why. I do like the idea that the player should ask for the hint but when I think about it but that would require more work then I want for a console project when I, and I think I’m not alone here, want to get to the Meat-and-Potatoes and get into UDK C++ development. It sucks that I didn’t see that game error where it ask if the user want to play with the same word. With the way I went about things. I should have removed that altogether. So good job in point that out. I really missed that one there. I also like that for all the fixes and suggestion you pointed out. You also mention that it would be overall too much for a simple game like this.

This is my issue with the lecture discussion forums. It gets lonely posting work here and very rarely getting a response. So @DerTee I want to thank you very much for the comment that you left here. You stirred the pot and got others involved. I really wish that I would have paid more attention to it and really got involved myself. I’m going to greet everybody who posted a comment and see where that goes.

1 Like

If you look directly at that “if statement” you can see how a “switch statement” would work better. I would go so far as to say the “switch” is cleaner then the “if”. But that is an example of that fact that there is more then one way to get the same results. I’ll see about diving back in this project and see a “switch” in action.

I want to point that I am by no means a professional developer of procedural programming languages like C++ and its kind. While Java is the exception. I mostly know JavaScript, PHP. I was a web developer for 14 years before I had enough of it and decided that I had to develop what I always want to know and that was game programming, and not simplistic game programming for web based games. I leave my ActionScript days WAY behind me. HTML5 game programming was fun for a bit but I was never satisfied with it. There is no real thinking there. You literally can recycle code over and over again, and that get boring real quick. But with C++,C#, and yes even Java. That is not even case. There is always new and exciting ways to solve problems and new ideas that create new challenges.

I want to thank you guys for reminding not to give up. I was in a dark place and I have not been pushing forward in the course. So I feel that I have to start over and re-hash some of the lessons so that I can get back up to speed with the instructors. See you in the course and thanks again.

Great! I look forward to seeing you around! :slight_smile:
Have fun coding or blendering or whatever it is that you are doing right now!

Privacy & Terms