Re: [問題] C++寫貪食蛇的幾項問題
※ 引述《kira1101 (肉包)》之銘言:
: ( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
: ( 未必需要依照此格式,文章條理清楚即可 )
: 遇到的問題: (題意請描述清楚) 1.螢幕會閃動 2.檔案 1M多正常嗎?
: 希望得到的正確結果: 螢幕不閃以及縮小執行檔大小
螢幕不閃的話,不要用cls
write a function to programmatically clear the screen using the FillConsoleOutputCharacter and FillConsoleOutputAttribute functions
MSDN官方文件
http://msdn.microsoft.com/en-us/library/ms682022%28VS.85%29.aspx
BOOL WINAPI FillConsoleOutputCharacter(
__in HANDLE hConsoleOutput, //目標Console不用說了吧
__in TCHAR cCharacter, //要印出的char
__in DWORD nLength, //印出的長度
__in COORD dwWriteCoord, //印出的起點
__out LPDWORD lpNumberOfCharsWritten //回傳多少被印出了
);
這樣很清楚了吧,可以參考官方源始碼,取代cout <<
http://msdn.microsoft.com/en-us/library/ms684206(v=VS.85).aspx
Low-Level Console Output Functions
試看看這些Functions,對你應該有幫助
縮小執行檔大小 不要用debug編譯模式,然後最佳化
: 程式跑出來的錯誤結果:
: 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
: DEV C++
: 有問題的code: (請善用置底文標色功能)
: void printSnake(int snake[],int length){
: for(int i=0 ; i<37 ; i++) //上框架
: if(i == 0)
: cout << "╔";
: else if(i==36)
: cout << "╗" << endl;
: else
: cout << "═";
: for(int i=0;i<792;i++){
: if(i % 36 == 0)
: cout << "║ ";
: else if( (i+1) % 36 == 0 && i - 1)
: cout << " ║ " << endl;
: else if( snakeOrSpace (snake,i,length))
: cout << "▉";
: else
: cout << " ";
: }
: for(int i = 0 ; i < 37 ; i++) //下框架
: if(i == 0 )
: cout << "╚";
: else if(i==36)
: cout << "╝" << endl;
: else
: cout << "═";
: int snakeOrSpace(int snake[],int i,int length){
: for( int count = 0 ; count < length ; count++ ){
: if( snake [ count ] == i)
: return 1;
: }
: return 0;
: }
: 補充說明:
: 我是用一個矩陣記下蛇的位置,不知道有沒有更好的方法,
: 還有我想問的是除了 system"cls" 以外有其他更方便的方法嗎 ?
: 能像是只把蛇清除,而本身的框架卻還存在嗎?
: 拜託大家指教了!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.78.26
推
10/02 17:59, , 1F
10/02 17:59, 1F
※ 編輯: stupid0319 來自: 122.117.78.26 (10/02 18:33)
→
10/02 22:04, , 2F
10/02 22:04, 2F
→
10/02 22:05, , 3F
10/02 22:05, 3F
→
10/02 22:05, , 4F
10/02 22:05, 4F
推
10/03 01:11, , 5F
10/03 01:11, 5F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章