2012-09-14 47 views
1

我裝盤模擬Matrix電影的背景,我寫了下面的代碼:模擬矩陣背景

#include <iostream> 
#include<windows.h> 
#include <conio.h> 
using namespace std; 


void CursorPosition(short x, short y) { 
    COORD coordScreen = {x, y}; 
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordScreen); 
} 


void color(int nb) { 
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), nb); 
} 
int main(int argc, char *argv[]) { 
    unsigned int y[79]; 
    unsigned int ymin[79]; 
    unsigned int a, b; 

    char i[36] = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 
    70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 
    88, 89, 90}; 

    system("title The Matrix !"); 
    color(10); 

    for (a = 0; a < 79; a++) { 
     y[a] = 0; 
     ymin[a] = 1; 
    } 

    do { 
     for (unsigned int x = 0; x < 79; x++) { 
      for (unsigned int j = 0; j < 5; j++) { 
       a = rand() % 79; 
       if (y[a] != 0) { 
        b = rand() % y[a] + ymin[a]; 
        if (b < 26) { 
         if (b < ymin[a] + 2 & b > 2) color(2); 
         CursorPosition(a + 1, b); 
         cout << i[rand() % 36]; 
         color(10); 
        } 
       } 
      } 
      if (y[x] != 0 || (rand() % 50) == 0) { 
       if ((rand() % (y[x] + 1)) < 20 & ymin[x] == 1) { 
        y[x]++; 
       } else { 
        CursorPosition(x + 1, ymin[x]); 
        cout << " "; 
        ymin[x]++; 
        if (ymin[x] < 25) { 
         color(2); 
         CursorPosition(x + 1, ymin[x] + 1); 
         cout << i[rand() % 36]; 
         color(10); 
        } 
       } 
       if ((y[x] + ymin[x]) < 26) { 
        CursorPosition(x + 1, y[x] + ymin[x]); 
        color(15); 
        cout << i[rand() % 36]; 
        color(10); 
       } 
       if ((y[x] + ymin[x]) < 27) { 
        CursorPosition(x + 1, y[x] + ymin[x] - 1); 
        cout << i[rand() % 36]; 
       } 
      } 
      if (ymin[x] > 25) { 
       ymin[x] = 1; 
       y[x] = 0; 
      }j 
     } 
     Sleep(35); 
    } while (!kbhit()); 

    return 0; 
} 

你有任何建議,以改善代碼? 我的目的是這樣的: enter image description here

+2

什麼是與您當前密碼的問題?我在您的文本中看不到真正的問題 – codeling

+0

如果您想要查看代碼,請將其發佈在Codereview上! –

回答

3

你的代碼不寫這些字符。這是寫簡單的字母字符數字0-9。

你需要的是半角假名字符

。 「 」 、 ・ ヲ ァ ィ ゥ ェ ォ ャ ュ ョ ッ 
    ー ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ 
    タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ 
    ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ン ゙ ゚ 

你需要提高圖書館的boundary部分得到這些,我認爲。

一些例子,我發現:

boost::locale::generator gen; 
using namespace boost::locale::boundary; 
std::string text="生きるか死ぬか、それが問題だ。"; 
ssegment_index map(word,text.begin(),text.end(),gen("ja_JP.UTF-8")); 
for(ssegment_index::iterator it=map.begin(),e=map.end();it!=e;++it) { 
    std::cout << "Segment " << *it << " contains: "; 
    if(it->rule() & word_none) 
     std::cout << "white space or punctuation marks "; 
    if(it->rule() & word_kana) 
     std::cout << "kana characters "; 
    if(it->rule() & word_ideo) 
     std::cout << "ideographic characters"; 
    std::cout<< std::endl; 
} 

輸出:

Segment 生 contains: ideographic characters 
Segment きるか contains: kana characters 
Segment 死 contains: ideographic characters 
Segment ぬか contains: kana characters 
Segment 、 contains: white space or punctuation marks 
Segment それが contains: kana characters 
Segment 問題 contains: ideographic characters 
Segment だ contains: kana characters 
Segment 。 contains: white space or punctuation marks 

Source