我对编码非常陌生,我使用 C++。我正在努力使代码行结束。它就这样继续下去。
这是我的代码:
#include <iostream>
int main(){
std::cout << "................................................................";
std::cout << "................................................................";
std::cout << "................................................................";
std::cout << "................................................................";
std::cout << "................................................................";
std::cout << "................................................................";
std::cout << "................................................................";
std::cout << "................................#...............................";
std::cout << "................................#...............................";
std::cout << "@...............................#...............................";
std::cout << "#######################......#######.....#######################";
std::cout << "......................#................##.......................";
std::cout << "......................##################........................";
std::cout << "................................................................";
std::cout << "................................................................";
std::cout << "................................................................";
return 0;
}
我还想知道如何将 @ 注册为可以随输入移动的章程。如果此代码格式错误,请告诉我,因为这太令人困惑了。
我试图用字符串、数组制作关卡格式,我什至不知道它是什么。
要使每个
cout
语句打印在自己的行上,您可以使用 \n
字符,它会开始一个新行。
例如:
#include <iostream>
int main(){
std::cout << "................................................................\n";
std::cout << "................................................................\n";
std::cout << "................................................................\n";
std::cout << "................................................................\n";
std::cout << "................................................................\n";
std::cout << "................................................................\n";
std::cout << "................................................................\n";
std::cout << "................................#...............................\n";
std::cout << "................................#...............................\n";
std::cout << "@...............................#...............................\n";
std::cout << "#######################......#######.....#######################\n";
std::cout << "......................#................##.......................\n";
std::cout << "......................##################........................\n";
std::cout << "................................................................\n";
std::cout << "................................................................\n";
std::cout << "................................................................\n";
return 0;
}
尽管如果您想制作游戏,这可能不是您想要做的。在尝试实现复杂的事情(例如 2d 游戏中的移动)之前,您应该首先学习 C++ 的其他基础知识。