Click here to Skip to main content
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 10-Dec-12 0:31am
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 450
1 OriginalGriff 180
2 DamithSL 130
3 Dave Kreskowiak 120
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,645
1 DamithSL 5,614
2 Sergey Alexandrovich Kryukov 5,344
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
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