C++控制台模拟 "骇客帝国数字飞屏"
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main(int argc,char* argv[]){ srand((unsigned)time(NULL));//设置种子 int colNo=10+rand()%50; //生成随机数 int rowNo=10+rand()%50; int flag=0; system("color 0C");//设置字体颜色 for(int z=0;z<=rowNo;z++){ for(int i=0;i<=colNo;i++){ cout<<" "; if(i==colNo){ if(0==flag){ cout<<"1"<<endl; flag=1; }else{ cout<<"0"<<endl; flag=0; } } } if(z==rowNo){ colNo=10+rand()%50; rowNo=10+rand()%50; z=0; } } cout<<">GameOver<"<<endl; //暂停屏幕 cin.get(); }
简单的代码实现,要点:随机数 的生成方法。。