第一步實現乙個簡單下落的小鳥@,小鳥自己有重力,會下落,每次y座標+1,按空格鍵上公升。換句話說,這裡只給小鳥一種操作,上公升。
#include
#include
#include
handle hout;
//定義標準輸出裝置控制代碼
console_screen_buffer_info csbi;
//定義視窗緩衝區資訊結構體
console_cursor_info curinfo;
//定義游標資訊結構體
int bird_x, bird_y;
int width, height;
void
gotoxy
(int x,
int y)
;setconsolecursorposition
(getstdhandle
(std_output_handle)
, pos);}
void
hidecursor()
intinitgame()
void
endgame()
void
updatewithinput()
}void
updatewithoutinput()
void
show()
printf
("\n");
}}intmain()
endgame()
;return0;
}
效果如下:
同時顯示小鳥和靜止的障礙物,並讓障礙物自己從右向左移動。障礙物是從上面向下一截,從下面向上一截,中間有乙個空缺。用bar_ytop,bar_ydown,bar1_x來描述障礙物。修改如下:
...
int bar_ytop, bar_ydown, bar_x;
//障礙物
看小鳥是否從障礙物的縫隙中通過,還是發生碰撞。碰撞後退出遊戲迴圈。越過障礙顯示得分。
#include
#include
#include
#include
handle hout;
//定義標準輸出裝置控制代碼
console_screen_buffer_info csbi;
//定義視窗緩衝區資訊結構體
console_cursor_info curinfo;
//定義游標資訊結構體
int bird_x, bird_y;
int width, height;
int bar_ytop, bar_ydown, bar_x;
//障礙物
int score;
int exitflag =0;
//退出遊戲迴圈標誌
void
setsize
(short len,
short wid)
; small_rect rc =
;//座標從0開始
// -- 設定視窗資訊
// @param handle [in] 視窗控制代碼
// @param bool [in] 意思不明,但在true時才起作用
// @param rect * [in] 分別指定視窗左上角座標和右下角座標
// #return bool 成功返回非0值
setconsolewindowinfo
(hout,
true
,&rc)
;// -- 設定緩衝區大小
// -- 長和寬不得小於控制台大小;不得小於系統最小限制。否則設定無效
// @param handle [in] 視窗控制代碼
// @param coord [in] 座標結構,包含長和寬
// #return bool 成功返回非0值
setconsolescreenbuffersize
(hout, pos);}
void
gotoxy
(int x,
int y)
;setconsolecursorposition
(getstdhandle
(std_output_handle)
, pos);}
void
hidecursor()
intinitgame()
void
endgame()
void
updatewithinput()
}void
updatewithoutinput()
}sleep
(200);
//減緩下落
}void
show()
printf
("\n");
}printf
("得分為:%d\n"
類似飛機遊戲中敵機被擊落或者超出螢幕範圍後重新出現敵機,這裡讓障礙物在左邊消失後在最右邊迴圈出現。用rand()隨機產生障礙物的縫隙的位置和大小,當然,要讓小鳥通過。
思考:模擬重力效果,小鳥加速下落。
1089 狼人殺 簡單版 C C 實現
1089 狼人殺 簡單版 20 point s 以下文字摘自 靈機一動 好玩的數學 狼人殺 遊戲分為狼人 好人兩大陣營。在一局 狼人殺 遊戲中,1 號玩家說 2 號是狼人 2 號玩家說 3 號是好人 3 號玩家說 4 號是狼人 4 號玩家說 5 號是好人 5 號玩家說 4 號是好人 已知這 5 名玩...
C C 版選擇排序
選擇排序實現如下 include include using namespace std constexpr int greater 0 從大到小排序的指示碼 constexpr int less 1 從小到大排序的指示碼 選擇排序 template typename datatype void s...
c c 轉義字元
c語言常用轉義字元 轉義字元 含義ascii碼 16 10進製 a響鈴 bel 07h 7 b退格 bs 08h 8 f換頁 ff 0ch 12 n換行 lf 0ah 10 r回車 cr 0dh 13 t水平製表 ht 09h 9 v垂直製表 vt 0bh 11 反斜槓 5ch 92 問號字元 3f...