Click here to Skip to main content
11,717,960 members (77,655 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Here is the code for painting a simple Christmas tree in 8 bit retro style:

#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 9-Dec-12 23:31pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v2
Comments
Member 9586495 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You may set colors using SetConsoleTextAttribute [^] function.
a very simple function for generating tones is Beep[^].
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 849
1 OriginalGriff 215
2 F-ES Sitecore 210
3 Maciej Los 140
4 Jochen Arndt 120
0 Sergey Alexandrovich Kryukov 1,494
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100