- 設計與發想: 由於本身對於射擊遊戲富有天賦且代表學校出去比賽過,希望可以更加提升自己能力。又加上想把自己的程式語言訓練得更加精熟,因此選擇了這個項目。 - 遊戲內容: 在此遊戲中,玩家需要操縱一個射擊器,在螢幕上射擊目標。玩家每擊中一個目標,得分就會增加。遊戲結束後,顯示玩家的最終得分。 - 程式碼: ```c= #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> #define TARGET_ROW 10 #define TARGET_SPEED 1 #define GUN_POSITION 20 int score = 0; void displayTarget(int row) { int i; for (i = 0; i < row; i++) { printf("\n"); } printf(" |\n"); } void displayGun() { printf("===\n"); } void displayScore() { printf("\nScore: %d\n", score); } void updateGame() { int targetRow = TARGET_ROW; while (1) { system("cls"); displayGun(); displayTarget(targetRow); displayScore(); if (kbhit()) { char key = getch(); if (key == ' ') { if (targetRow >= GUN_POSITION && targetRow <= GUN_POSITION + 2) { score++; } } } targetRow -= TARGET_SPEED; if (targetRow < 0) { system("cls"); printf("Game Over!\n"); printf("Final Score: %d\n", score); break; } // 控制遊戲延遲速度 int i; for (i = 0; i < 10000000; i++) {} } } int main() { srand(time(NULL)); // 遊戲初始化 printf("=== Simple Shooting Game ===\n"); printf("Instructions:\n"); printf("Press the Spacebar to shoot.\n"); printf("Try to hit the target!\n"); printf("Press any key to start the game.\n"); getch(); updateGame(); return 0; } ``` ### 1.困難與挑戰 - 遊戲類型 : 什麼樣的遊戲可以對於槍法達到快速提升的目的就是我首先需要解決的問題。 - 語言精熟度 : 做出一款遊戲是很困難的,需要大量時間去Debug、修改整理,一切都來自對語言的不熟悉。 ### 2.心得 - 本人算是程式語言的初學者,起跑點和大多數學生不一樣,但為此我也花了很多時間在學習C語言上,到了下學期甚至可以靠自己所學解出期中考老師自己出的題目,真的很有成就感。非常喜歡老師的上課方式。而且由於就讀的是電機系,將來碰到程式這塊是不變的事實,所以現在能把基礎打好,對未來是非常有幫助的。 - 其實網路上面有很多類似的練槍遊戲,甚至都做得更完美、更精緻,但這是我自己第一個為了練習所嘗試出來的遊戲,對我來說有很大的意義,為此也花了很多時間去網路上尋找資源,學期更多語法。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up