2012-09-23 22 views
0

我正在製作基於文本的冒險遊戲。我想讓遊戲名稱(大型)或大量行。我怎樣才能做到這一點?如何製作C++菜單文本

的我想要的一個例子是這樣的:

╔═╗╔═╗───╔╗────────╔╗────╔╗─╔ ╗──╔╗╔╗────╔═══╦╗ ║║╚╝║║───║║──────────────────── ║║║║────╚╗╔╗║║ ║╔╗╔╗╠══╦╣║╔╦══╦╗─╔╣║╔══╗║╚╗║╚═╝╠══╣║║ ║╔══╗╗─║║║║╚═╦══╦══╦══╗* ║║║║║║╔╗╠╣╚╝╣╔╗║║─║║║║╔╗║║ ╔═╗║║═╣║ ║║║╔╗║─║║║║╔╗║╔╗║╔╗║║═╣ ║║║║║║╔╗║║╔╗╣╔╗║╚═╝║╚╣╔╗║║ ║─║║║═╣╚╣╚╣╔╗║╔╝╚╝║║║║╚╝║╚╝║║═╣ ╚╝╚╝╚╩╝╚╝╚╝╚╝╚╝╚╝╚╝╚╝╚╗╗╗╗ ╔═╝╚╝╚╝╝╚╝╚╝╝╚╝╚╝╚╚═══╩╩╩╩╝╚╝╚╝╚╝╚╝╚╝╚╝╚╝╚═╝╚╝╚╝╚══╣╔╩╩╝╝╝ ────────── ─────╔═╝║───────────────────────────────║║ ─────── ──────────────────────────────────────╚╝

但更明顯。而且當這個編譯出來的時候,它出現在?的。所以我需要文本編譯器友好。

+0

伊夫使用各種線,如_,並試圖|但我這樣做的方式看起來令人難以置信的愚蠢。 – Pendo826

+0

您可以創建填充每個字符的ascii代碼的char數組並打印char數組。這樣他們將被正確轉換。這裏是一個ASCII代碼表:http://www.asciitable.com/index/extend.gif – 2012-09-23 19:55:15

+0

你在什麼操作系統上運行? –

回答

3

在Windows上,具有廣泛的字符串文字:

wchar_t * titleStr= L"╔═╗╔═╗───╔╗────────╔╗────╔╗─╔╗──╔╗╔╗────╔═══╦╗\n" 
        L"║║╚╝║║───║║────────║║────║║─║║──║║║║────╚╗╔╗║║\n" 
        L"║╔╗╔╗╠══╦╣║╔╦══╦╗─╔╣║╔══╗║╚═╝╠══╣║║║╔══╗─║║║║╚═╦══╦══╦══╗*\n" 
        L"║║║║║║╔╗╠╣╚╝╣╔╗║║─║║║║╔╗║║╔═╗║║═╣║║║║╔╗║─║║║║╔╗║╔╗║╔╗║║═╣ \n" 
        L"║║║║║║╔╗║║╔╗╣╔╗║╚═╝║╚╣╔╗║║║─║║║═╣╚╣╚╣╔╗║╔╝╚╝║║║║╚╝║╚╝║║═╣ \n" 
        L"╚╝╚╝╚╩╝╚╩╩╝╚╩╝╚╩═╗╔╩═╩╝╚╝╚╝─╚╩══╩═╩═╩╝╚╝╚═══╩╝╚╩══╣╔═╩══╝ \n" 
        L"───────────────╔═╝║───────────────────────────────║║ \n" 
        L"───────────────╚══╝───────────────────────────────╚╝\n" 
std::wcout<<titleStr; 
0

有多種方法可以做到這一點。

最簡單的方法是在這裏輸出字符代碼> cout(char)< 這將允許您打印這些邊框字符而不是下劃線和破折號。

ASCII人物和他們的代碼列表是http://www.cplusplus.com/doc/ascii/

您也可以嘗試在單獨的文本文件傾倒所有文字,讀取並解析該文件,然後將它打印到控制檯。

事情是這樣的:

#include <iostream> 
#include <fstream> 
#include <string> 

int main() { 
    std::ifstream reader("art.txt"); //Load the text 
    std::string art = parseart(reader); //Parse the file 
    std::cout << art << std::endl; //Print 

    reader.close(); 
    return 0; 
} 

std::string parseart(std::ifstream& File) { 
    std::string parsedfile; 

    if(File) { 
     while(File.good()) { 
      std::string tmpline; 
      std::getline(File, tmpline); 
      tmpline += "\n"; 

      parsedfile += tmpline; 
     } 
     return parsedfile; 
    } else { 
     //Error 
    }