又一个圣诞树应用程序

编程入门 行业动态 更新时间:2024-10-07 22:24:12
本文介绍了又一个圣诞树应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是用8位复古风格绘制简单圣诞树的代码:

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; }

到目前为止还不错。 在这里我的问题: 通常如何将颜色和声音带入控制台应用程序 以使打印更舒适,更多专业。 我想cout<<由于它的弱点,它不是正确的候选者。 某些C ++代码片段或者前代码项目的链接也会有所帮助。 提前致谢。

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.

推荐答案

是的。 www.dotnetperls/console-color [ ^ ] 如果你使用cout,请看这里: www.cplusplus/forum/beginner/5830/ [ ^ ] Yes. www.dotnetperls/console-color[^] If you use cout, then see here: www.cplusplus/forum/beginner/5830/[^]

您可以使用颜色设置 SetConsoleTextAttribute [ ^ ]功能。 a生成音调的非常简单的函数是哔哔声 [ ^ ]。 You may set colors using SetConsoleTextAttribute [^] function. a very simple function for generating tones is Beep[^].

更多推荐

又一个圣诞树应用程序

本文发布于:2023-11-30 06:37:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649043.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:圣诞树   应用程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!