Hi,
While waiting for the rest of the remaster I’m currently trying to make an anagram finding game as a kind of follow up to Triple X, it’s started out fairly well but I’ve run into 1 little snag that I am struggling to find an answer to by googling as it seems to be a very specific question I need to ask…
Basically I’ve created a 2 dimensional array to hold the anagrams, I’m then using rand() with time.h (time) in order to randomly choose 1 of the arrays depending on the level selected. That all works fine the issue comes when I want to come the response given with the list of anagrams, as I can’t just specify which elements to compare it with as it’s chosen randomly, so I need a way to get the address of the randomly chosen element. My first thought was to use pointers and get the address that way but currently that is also proving problematic.
Is there an easier way to do this that I’m missing? am I just using pointers entirely wrong? or should I just not be using .compare for this? I’ve included what I have so far for reference, currently it always compares the word with art, but even putting that in has no effect on the outcome.
/* HeadPounder
Author Ben Barnes 06/01/2020
Version 0.1
*/
#include <iostream>
#include <string>
#include <cstdlib>
#include <time.h>
#include <stdio.h>
void Log(const char*);
int main()
{
srand (time(NULL));
std::string Anagram;
std::string* ThreePointer;
std::string ThreeLetterAnagrams[8][3]{
{ "art", "rat", "tar" },
{ "apt", "pat", "tap" },
{ "arm", "mar", "ram" },
{ "are", "ear", "era" },
{ "asp", "sap", "spa" },
{ "ate", "eat", "tea" },
{ "now", "own", "won" },
{ "opt", "pot", "top" }
};
ThreePointer = ThreeLetterAnagrams[0];
void PrintIntroduction();
{
Log("Welcome to HeadPounder a quick game of anagrams!");
Log("You will be given a word from a selection and your goal is to find all the anagrams of that word.");
Log("You will need to use every letter and don't worry I'll let you know when you've got them all.");
Log("Good luck and don't feel too bad if you don't get them all, you can always try again.");
Log("");
}
void SelectDifficulty();
{
int LevelDifficulty;
Log("Ok first choose your difficulty level, this will determine the number of letters in your word.");
Log("Just enter a digit between 3 and 10, trust me anagrams of 2 letter words aren't fun...");
label1:
std::cin >> LevelDifficulty;
switch (LevelDifficulty)
{
default: Log("I said between 3 and 10... lets try this again, enter a digit between 3 and 10 to choose your difficulty.");
std::cin.clear();
std::cin.ignore(1000, '\n');
goto label1;
case 3: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level: "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
case 4: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level: "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
case 5: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level: "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
case 6: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level: "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
case 7: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level: "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
case 8: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level; "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
case 9: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level: "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
case 10: Anagram = ThreeLetterAnagrams[rand() % 7 + 0][0];
Log("");
printf("Great! you've selected difficulty level: "), std::cout << LevelDifficulty, Log("");
Log("Lets get on with the game!");
Log("");
break;
}
}
void PlayGame();
{
std::string Response;
std::cin.ignore(1000, '\n');
std::cout << "Ok your first word to find anagrams for is: " << Anagram << std::endl;
Log("Enter your guesses below.");
getline(std::cin, Response);
Response.compare(&ThreePointer[rand() % 7 + 0][0]);
if (!Response.compare(&ThreePointer[rand() % 7 + 0][1, 2]))
{
Log("You got one right!!");
}
else
{
Log("That's not right dumbass!");
}
}
}
void Log(const char* message)
{
std::cout << message << std::endl;
}