Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the code for painting a simple Christmas tree in 8 bit retro style:

C++
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;

int main()
{
    int treeheight = 15;
    int i, j;
    string str;
    string tabs = "\t";
    
    cout << endl;
    
    for (i = 0; i < treeheight; i++)
    {
        str = tabs;
        for (j = 0; j < treeheight-i; j++)
            str += " ";
            
        if (i > 0) str += "#";
        else str += "*";

        srand((int)time(NULL));
        for (j = 1; j < 2*i; j++)
            if (rand() % 4) str += " ";
            else str += "o";
                
        if (i > 0) str += "#";
        
        str += "\n";
            
        cout << str;    
    }
    
    str = tabs + "  ";
    for (i = 0; i < 2*treeheight-3; i++)
        str += "#";
    str += "\n";
    
    cout << str;    
    
    str = tabs;
    for (i = 0; i < treeheight; i++)
        str += " ";
    str += "|\n";
    
    cout << str;
        
    cout << endl;
    
    system("pause");
    
    return 0;
}


So far so not bad.

Here my question:

How is it generally possible to bring colour and sound into a console app
to make the printing more comfortable, more professional.

I guess "cout <<" is not the right candidate because of its weakness.

Some C++ code snippet or perhaps a link to a former code project will help.

Thanks in advance.
Posted

 
Share this answer
 
v2
Comments
sja63 10-Dec-12 5:59am    
Thank you for your very fast answer.

Perhaps you can send me another link regarding sound?
Sound played by a file or sound created directly by the generator, if possible?

Thanks in advance
You may set colors using SetConsoleTextAttribute [^] function.
a very simple function for generating tones is Beep[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900