發表文章

電腦遊戲設計入門

本部落格的幾篇文章: Console-based or GUI-based game programming 遊戲程式開發工具與網站 ( Tools and their website for game programming ) 開源跨平台遊戲開發工具介紹:GDevelop MIT App Inventor 2 乒乓球遊戲 Python 猜數字遊戲 用 Corona SDK 寫遊戲 Python 遊戲設計:軟體安裝 ( Python Game Development: Software Installation ) Pygame 遊戲設計:鍵盤控制角色移動 Scratch 程式設計教學 Java 遊戲程式設計:基礎篇 (Java Game Programming: The Basic) Java 遊戲程式設計:動畫 ( Java Game Programming: Animation ) Java 遊戲程式設計:鍵盤控制 (Java Game Programming: Control a Sprite with the Keyboard ) Java 遊戲程式設計:用鍵盤控制控制兩個長方形 ( Java Game Programming: Controlling two Sprites with the Keyboard ) Java 遊戲程式設計:乒乓球遊戲 ( Java Game Programming: Ping Pong ) etc. 說明了一些開發環境的建立,也介紹了一些小遊戲的做法。但, 設計電腦遊戲一定要學程式設計嗎 ?例如 開源跨平台遊戲開發工具介紹:GDevelop 文中提到的 GDevelop  以及  遊戲程式開發工具與網站 ( Tools and their website for game programming )  所提到的  Clickteam Fusion 、 RPG Maker ,這三款軟體皆可不需撰寫程式碼,就可以設計遊戲囉。 除了這三款軟體之外,還有沒有其他的工具呢?當然有(不然要這篇文章做什麼呢!?)。此類軟體有免費與付費的,底下就分為這兩類來介紹。 須付費電腦遊戲設計軟體: Game Maker https://www.yo...

高中生程式解題系統:a134: 00948 - Fibonaccimal Base

題目連結 https://zerojudge.tw/ShowProblem?problemid=a134 。 此題和  c121: 00495 - Fibonacci Freeze  、 LintCode: Fibonacci 費布那西數列 很接近,都是與 費波那契數列有關 。 程式碼是先建立好Fibonacci數列,也知道N最大值為500,所以就建立前40項的Fibonacci數列。 從小於N的最大Fibonacci數開始找起 ,就可以唯一的表示法。 程式碼: import sys fibs = list(range( 40 )) fibs[ 0 ] = 0 fibs[ 1 ] = 1 for i in range( 2 , 40 ): fibs[i] = fibs[i -1 ] + fibs[i -2 ] #print(fibs) n = int(input()) for x in range(n): d = int(input()) print(str(d) + " = " , end= "" ) isPut = False for i in range( 39 , 1 , -1 ): if d >= fibs[i]: d = d - fibs[i] isPut = True print( "1" , end= "" ) elif isPut == True : print( "0" , end= "" ) print( " (fib)" ) 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or buy me a coffee . Thank you very much.

三角函數觀念與常見公式

圖片
本篇文章整理與三角函數有關的資訊。 三角函數的基本觀念 影片版 文字版: 三角函數基本概念 定義整理(取自 三角函數- 維基百科 ): {\displaystyle \theta } 的 正弦 是對邊與斜邊的比值: {\displaystyle \sin {\theta }={\frac {a}{h}}} {\displaystyle \theta } 的 餘弦 是鄰邊與斜邊的比值: {\displaystyle \cos {\theta }={\frac {b}{h}}} {\displaystyle \theta } 的 正切 是對邊與鄰邊的比值: {\displaystyle \tan {\theta }={\frac {a}{b}}} {\displaystyle \theta } 的 餘切 是鄰邊與對邊的比值: {\displaystyle \cot {\theta }={\frac {b}{a}}} {\displaystyle \theta } 的 正割 是斜邊與鄰邊的比值: {\displaystyle \sec {\theta }={\frac {h}{b}}} {\displaystyle \theta } 的 餘割 是斜邊與對邊的比值: {\displaystyle \csc {\theta }={\frac {h}{a}}} 平方關係 定義整理(取自 三角函數- 維基百科 ): 由   可導出底下式子 {\displaystyle 1+\cot ^{2}\!x=\csc ^{2}\!x.} 和角與差角公式 定義整理 和角公式(取自 三角函數- 維基百科 ): 差角公式(取自 三角函數- 維基百科 ): 二倍角公式(取自 三角函數- 維基百科 ): 積化和差(取自 三角函數- 維基百科 ): {\displaystyle 2\cos \theta \cos \varphi ={\cos(\theta -\varphi )+\cos(\theta +\varphi )}} {\displaystyle 2\sin \theta \sin \varphi ={\cos(\theta -\varphi )-\cos(\theta +\varphi...

Python 函數(Functions)

程式語言所用的函數(Functions)和數學上的函數有著很相似的觀念,但程式語言的函數比較複雜一點,需要了解底下知識:函數宣告、函數定義、函數呼叫。然而不是所有的程式語言都會有這三種觀念,因此本文會分別以C語言和Python語言來說明這三種觀念( 註:C語言也是有版本之分的,請參考 https://en.wikipedia.org/wiki/C_(programming_language)#History )。 函數宣告(Function declaration) C語言語法如下: 1 回傳型態 函數名稱 ( 參數列 ); C語言範例: 1 2 3 4 int sum( int a, int b); int add( int , int ); int min( int x, int y); int max( int , int ); 因為 Python 目前沒有 Function declaration 的語法,請直接使用 Function definition。 函數定義(Function definition) C語言語法如下: 1 2 3 回傳型態 函數名稱 ( 參數列 ) { 函數主體 } C語言範例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int sum( int a, int b) { return a + b; } int add( int a, int b) { return a + b; } int min( int x, int y) { return x <= y ? x: y; } int max( int x, int y) { return x >= y ? x: y; } Python語言語法如下: 1 2 3 4 def 函數名稱( 參數列 ): "函數說明" 程式碼 return [運算式(Expression)] Python語言範例: 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Python 排序(Sorting)

筆者有用C++來解高中生解題系統上的 高中生程式解題系統:排序 Sorting (題目連結: https://zerojudge.tw/ShowProblem?problemid=a104 ) 一題。 本篇換用 Python 程式語言來解。雖然本部落有介紹過一些常見的排序演算法:「 Python 排序演算法範例 ( Sorting Algorithms in Python ) 」。但因為 Python 有內建的排序函數  list.sort與sorted  可用,排序部分就用內建函數了。於是針對此題的演算法會變成如下: 讀取正整數 n 讀取一行正整數數列 line 設定 numbers 為空串列 將數列 line 每一個正整數加到 numbers 中 對 numbers 排序並輸出結果 Python程式碼: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import sys while True : line = sys.stdin.readline() if not line: break n = int(line) line = sys.stdin.readline() numbers = [] for x in line.split(): numbers.append(int(x)) for x in sorted(numbers): print(x, end= " " ) print() 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or buy me a coffee . Thank you very much.

Python 完全平方和

筆者有用C++來解高中生解題系統上的  高中生程式解題系統:完全平方和 (題目連結: https://zerojudge.tw/ShowProblem?problemid=a059 ) 一題。 本篇換用 Python 程式語言來解,演算法如下: 找出在範圍 [a, b]內大於或等於 a 的完全平方數(curSquare),與 a 的平方根(minRoot)。 當 curSquare 小於或等於 b 時 {   將 curSquare 加到 squareSum 裡   minRoot += 1   curSquare = minRoot * minRoot } Python程式碼: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 from math import sqrt n = int(input()) for i in range(n): a = int(input()) b = int(input()) # Current Square Number curSquare = 0 # Minimal square root minRoot = int(sqrt(a)) if minRoot * minRoot == a: curSquare = a else : minRoot = minRoot + 1 curSquare = minRoot * minRoot squareSum = 0 while curSquare <= b: squareSum += curSquare minRoot += 1 curSquare = minRoot * minRoot print( "Case " + str(i + 1) + ":" , squareSum) 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, p...

Python 阿姆斯壯數

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 筆者有用C++來解高中生解題系統上的 高中生程式解題系統:阿姆斯壯數 Armstrong number (題目連結: https://zerojudge.tw/ShowProblem?problemid=a040 ) 一題。 本篇換用 Python 程式語言來解,而當時所寫的 C++ 為先建立好阿姆斯壯數的對應表,算有點偷吃步,這次用演算法來解囉。首先要知道數字是幾位數,可將數字轉成字串後,在呼叫計算字串長度函數 order = len(str(x)) ,接著就是將每位數的 order 次方加總(s),並檢查是否與原來數字相等。 Python程式碼: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import sys def isArm (x): order = len(str(x)) temp = x s = 0 while (temp != 0): r = temp % 10 s = s + (r ** order) temp = temp // 10 return (s == x) for s in sys.stdin: n, m = map(int, s.split()) flag = False for i in range(n, m): if isArm(i): flag = True print(str(i), end = " " ) if flag == False : print( "none" ) else : print() 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or buy me...