Monday, March 1, 2010

Dictionary Shortener

Recently, I had to write a program that shortened the dictionary. What I mean by this is that using a full dictionary (over 237,000 words), I needed to weed out the words that were longer than eight letters and shorter than three letters. I needed a list of letters between three and eight letters for an upcoming game that happens to need a dictionary to check against.

Why do I bring this up? Well, my program takes advantage of fstream, a coder's good friend or enemy, depending on your understanding of it.

In my next posting, I will show you the finer points of using fstream, but for now, here is the code for the dictionary shortening program:



#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
 
int main()
{
    string word;
    ifstream infile;
    ofstream outfile;
    int count=0;
    infile.open("fulldictionary.txt");
    if(infile.fail())
    {
        cout<<"File could not be opened\n";
        system("PAUSE");
        return 0;
    }
    outfile.open("dictionary_short.txt");
    if(outfile.fail())
    {
        cout<<"File could not be opened\n";
        system("PAUSE");
        return 0;
    }
    for(int i=0;!infile.fail();i++)
    {
        getline(infile,word);
        if(word.length()>=3&&word.length()<=8)
        {
            count+=1;
            cout<<count<<": "<<word<<endl;
            outfile<<word<<endl;
        }
    }
    infile.close();
    outfile.close();
    cout<<"There were "<<count<<" words saved in dictionary_short.txt\n";
    system("PAUSE");
    return 0;
}



The above code assumes that you have a file called "fulldictionary.txt" in the project folder and will automatically create the output file. There's no need to make that one.

Friday, February 26, 2010

Creating Road In Unity Game Engine

Unity game engine is a great engine for developing game on PC, MAC, iPhone, and other platforms. However, I noticed that Unity does not have a road editor compared to Torque (game engine). One can use primitives to resolve this issue, but I prefer to use a 3d modeling tool. Thus, in this tutorial I will show you how to create roads using 3ds Max.

THINGS YOU MIGHT NEED:
a) A 3D modeling tool
b) Road Design/Map
c) Road Textures

1) Open 3ds Max, click CREATE and select SHAPES.
(click the picture to view in X-Large)

1b) Enter/Select all the necessary values and settings as desired. (Use the same values and setting to achieve similar results as this tutorial)


2) Create the desired road using the top view.


3) Select the Map Editor. (Shortcut: hit M on the keyboard to pop up the Map Editor)

 

3b) Click on the none button next to Diffuse. Double Click on Bitmap and select your road texture.

 

 4)  Make sure the desired material is selected.
4a) Select the "Assign Material to Selection" button in the Material editor to assign material
4b) Select the "Show Standard map in Viewport" to show material layout in your Viewport.
4c) Play Around with the Tiling Values to get the desired tiling.


5) Export as .FBX to Unity Game Engine.



~* By: Verse316 *~

Tuesday, January 5, 2010

Simple Console Program & Code Snippet Embeding.

Happy New Year! There will lots of code altering and editing on this blog this year. Thus, displaying code in code snippets will be very effective. How do you display or embed code snippets on your blog? There are several ways you can embed scripts or code on your blog. One of the easiest ways is to use Microsoft Live Writer. Once you have that installed you may need a plug-in that helps with formatting and highlighting.

Here is an example with a simple Console Program I made:
   1: #include <iostream>

   2: #include <iomanip>

   3: #include <string>

   4:  

   5: using namespace std;

   6:  

   7: int main()

   8: {

   9:     //** Declarations **    

  10:     double hourpay, twoweeks, month, year;

  11:     int ans, weeksWorked;

  12:     string name;

  13:     bool flag = false; 

  14:  

  15:     cout << "Welcome to the Budget Console" << endl;

  16:     cout << endl;

  17:     cout << "Please enter your name: ";

  18:     getline(cin, name);

  19:     system("cls");

  20:  

  21:     cout << name << ", How much do you earn per hour: ";

  22:     cin >> hourpay;

  23:     cout << endl;

  24:     cout << "How much do you work in a week: ";

  25:     cin >> weeksWorked;

  26:     cout << endl;

  27:     system("cls");

  28:  

  29:     //** Menu **

  30:     while (!flag)

  31:     {

  32:     cout << "\t Menu" << endl;

  33:     cout << "1) Calculate how much I earn in 2 weeks."<< endl;

  34:     cout << "2) Calculate how much I earn in a month."<< endl;

  35:     cout << "3) Calculate how much I earn in a year: ";

  36:     cin >> ans;

  37:     cout << endl;

  38:  

  39:     //** Calculation **

  40:      twoweeks = hourpay * weeksWorked;

  41:      month = twoweeks * 2;

  42:      year = (twoweeks * 2) * 12;

  43:  

  44:     //** Outputs **

  45:     if (ans == 1) {         

  46:           cout << "Your Two Weeks Pay: $" << twoweeks << ".00 " << endl;

  47:           flag = true;

  48:     }

  49:     else if (ans == 2) {        

  50:         cout << "Your a month Pay: $" << month << ".00 " << endl;

  51:         flag = true;

  52:     }

  53:     else if (ans == 3) {        

  54:         cout << "Your a month Pay: $" << year << ".00 " << endl;

  55:         flag = true;

  56:     }

  57:     else {

  58:       cout << "Invalid Selection" << endl;

  59:     }

  60:       }

  61:     system("pause");

  62:     return 0;

  63: }