- Joined
- Oct 20, 2007
- Messages
- 353
Like i just writed? ;D
Oh, You writed the same, but with other words!

(9 ratings)
Like i just writed? ;D
// The source code used to be here, but I removed it for ... senseless reasons
This didn't take me 20 lines :c (I feel n00bish now)
Code:// The source code used to be here, but I removed it for ... senseless reasons
Don't.
You exe, for example, doesn't require a database, a web server or an internet connection.
If you'd make what he said, you'd need to fill a database with name, which would be a lot of boring work.
one thing I've noticed, there are so many names that has the phrase 'Mage', perhaps Magtheridon96? XD...
Magtheridon96 said:I guess I could make an item name generator.
I have no idea what those DLLs are for![]()
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <locale>
// Yes, this application will only work
// on Windows.
#include <Windows.h>
const std::vector<std::string> vowels
{
"a", "e", "i", "o", "u"
};
const std::vector<std::string> consonants
{
"b", "c", "d", "f", "g",
"h", "j", "k", "l", "m",
"n", "p", "q", "r", "s",
"t", "v", "w", "x", "y",
"z", "ch", "sh", "th"
};
const std::vector<std::string> female_suffix
{
"ona", "ena", "ana", "una", "ina",
"ora", "era", "ara", "ura", "ira"
};
const std::vector<std::string> male_suffix
{
"thor", "don", "din", "gon", "thar",
"kon", "kin", "mag", "gin", "mace",
"dex", "tex", "mech", "lag", "bei",
"ven", "den", "dan", "nero"
};
const std::vector<std::string> clan_prefix
{
"War", "Black", "Mage", "Dark", "Eagle",
"Thunder", "Silver", "Demon", "Blood", "Iron",
"Frost"
};
const std::vector<std::string> clan_suffix
{
"song", "rock", "fire", "wing", "horn",
"hand", "hoof", "claw", "eye", "wood",
"fist", "bane"
};
void print_welcome_message() {
std::cout << "\n Warcraft III Name Generator v2.4.0.0"
<< "\n By Magtheridon96"
<< "\n Special Thanks to D.O.G."
<< '\n'
<< "\n This program will generate Warcraft III character names."
<< "\n There are nearly a hundred million possible names."
<< '\n';
}
void print_instructions() {
std::cout << "\n Commands:"
<< "\n 'm' - Generate a male name."
<< "\n 'f' - Generate a female name."
<< "\n 'c' - Clear the screen."
<< "\n 'd' - Dump all the generated names to a file."
<< "\n 'q' - Quit the application."
<< "\n The last generated name will be copied."
<< "\n\n";
}
//
// The expected range has the same properties as
// C++ standard iterator ranges. [begin, end)
//
// get_random_int(0, 4) -> [0 ... 3]
//
int get_random_int(int begin, int end) {
return begin + std::rand() % (end - begin);
}
const std::string& get_random_vowel() {
return vowels[get_random_int(0, vowels.size())];
}
const std::string& get_random_consonant() {
return consonants[get_random_int(0, consonants.size())];
}
const std::string& get_random_male_suffix() {
return male_suffix[get_random_int(0, male_suffix.size())];
}
const std::string& get_random_female_suffix() {
return female_suffix[get_random_int(0, female_suffix.size())];
}
const std::string& get_random_clan_prefix() {
return clan_prefix[get_random_int(0, clan_prefix.size())];
}
const std::string& get_random_clan_suffix() {
return clan_suffix[get_random_int(0, clan_suffix.size())];
}
void seed_random_number_generator() {
std::srand(std::time(0));
}
std::string get_male_name() {
std::string name = "";
int i = get_random_int(0, 2);
switch (i) {
case 0:
name += get_random_consonant();
name += get_random_vowel();
break;
case 1:
name += get_random_vowel();
name += get_random_consonant();
name += get_random_vowel();
break;
case 2:
name += get_random_consonant();
name += get_random_vowel();
name += get_random_consonant();
name += get_random_vowel();
break;
default:
// This is never supposed to happen.
break;
}
name += get_random_male_suffix();
if (std::islower(name[0]))
name[0] = std::toupper(name[0]);
name += " ";
name += get_random_clan_prefix();
name += get_random_clan_suffix();
return name;
}
std::string get_female_name() {
std::string name = "";
int i = get_random_int(0, 2);
switch (i) {
case 0:
name += get_random_vowel();
name += get_random_consonant();
break;
case 1:
name += get_random_consonant();
name += get_random_vowel();
name += get_random_consonant();
break;
case 2:
name += get_random_vowel();
name += get_random_consonant();
name += get_random_vowel();
name += get_random_consonant();
break;
default:
// This is never supposed to happen.
break;
}
name += get_random_female_suffix();
if (std::islower(name[0]))
name[0] = std::toupper(name[0]);
name += " ";
name += get_random_clan_prefix();
name += get_random_clan_suffix();
return name;
}
void clear_screen() {
// This function is not standard, but it will work here.
// Don't use this in portable software, seriously.
// Everything in conio.h is not standard compliant.
// ISO C++ does not mention this shit.
clrscr();
}
void dump_file(const std::string& all) {
std::ofstream file("Generated Names.txt");
file << all;
}
// This function is Windows specific.
// C++ does not know what a 'clipboard' is.
void copy_to_clipboard(const std::string& name) {
const char* output = name.c_str();
const std::size_t size = name.length() + 1;
HGLOBAL memory = GlobalAlloc(GMEM_MOVEABLE, size);
memcpy(GlobalLock(memory), output, size);
GlobalUnlock(memory);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, memory);
CloseClipboard();
}
int main() {
std::string all_names;
print_welcome_message();
print_instructions();
seed_random_number_generator();
bool quit = false;
while (!quit) {
// The standard input stream is buffered, which is why it's not
// possible to get a single key stroke without making it unbuffered.
// The simplest work around is to use a platform specific function.
// This application is only meant to work on Windows anyway.
char i = std::tolower(_getch());
std::string text;
std::string name;
switch (i) {
case 'm':
name = get_male_name();
text = "(M) " + name + "\r\n";
std::cout << text;
all_names += text;
copy_to_clipboard(name);
break;
case 'f':
name = get_female_name();
text = "(F) " + name + "\r\n";
std::cout << text;
all_names += text;
copy_to_clipboard(name);
break;
case 'c':
clear_screen();
print_instructions();
break;
case 'd':
dump_file(all_names);
std::cout << "[System] Dumped to file." << std::endl;
break;
case 'q':
quit = true;
break;
default:
break;
}
}
return 0;
}
I was wondering, why are you not 'using namespace std', when you can omit all 'std::' by it?...
and #include <string>, isnt it that string is a keyword already?...
isnt it that instead of *output, why cant it be &name?...