• 沒有找到結果。

用程式設計製作遊戲

N/A
N/A
Protected

Academic year: 2022

Share "用程式設計製作遊戲"

Copied!
22
0
0

加載中.... (立即查看全文)

全文

(1)

中華醫事科技大學 資訊管理系 102 學年度 畢業專題成果發表 THEME:用程式設計製作遊戲

組員:四資管四 A 陳柏翰 組員:四資管四 A 邱麗郁 組員:四資管四 A 鄭元彰 組員:四資管四 A 林宗翰 指導教授:羅逸文 ( KEVIN ) 日期: 2013 年 11 月 30 日

Directory

(2)

Section 01 _ Summary A 研究動機 ( Motivation ) B 研究目的 ( Purposes ) C 研究方法 ( Approach )

Section 02 _ 遊戲畫面 and 玩法介紹

( Include Source code )

Section 03 _ 參考文獻 ( Consultation )

(3)

研究動機 (Motivation)

玩遊戲時對這些遊戲背後的程式感到好奇,

想更加了解齒輪的運作。

研究目的 ( Purposes )

A. 藉由製作遊戲過程學習更多程式設計相 關能力。

B. 邊學、邊做、邊玩,透過玩遊戲的過程 學習程式碼的應用。

C. 思考程式碼運作的邏輯。

研究方法 ( Approach ) A. 尋找各種簡易小遊戲。

B. 研讀專業書籍,一邊了解程式內容,一 邊試著修改。

C. 藉由邊做邊學,以達到學習目的。

D. 試著自行製作,以挑戰自己的實力。

遊戲畫面 and 玩法介紹

(4)

Tic Tac Toe

遊戲說明:Tic-tac-toe (or Noughts and crosses, Xs and Os) is a paper- and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three

respective marks in a horizontal, vertical, or diagonal row wins the game.

↑ 以此為範本,嘗試做修改。

參考來源:http://211.75.223.181/game/game2/game2.htm

(5)

<head>

<meta http-equiv="Content-Type" content="text/html; charset=big5">

<title>You</title>

<SCRIPT LANGUAGE="JavaScript">

var x = "x.jpg";

var o = "o.jpg";

var blank = "blank.jpg";

var z = "z.jpg";

var p = "p.jpg";

var j = "j.jpg";

var pause = 0;

var all = 0;

var a = 0;

var b = 0;

var c = 0;

var d = 0;

var e = 0;

var f = 0;

var g = 0;

var h = 0;

var i = 0;

var temp="";

var ok = 0;

var cf = 0;

var choice=9;

var aRandomNumber = 0;

var comp = 0;

var t = 0;

var wn = 0;

var ls = 0;

var ts = 0;

(6)

function quitGame() {

alert("這是一場不能結束的遊戲,因為這是現實 嘿嘿嘿");

window.close();

}

function help() {

alert("你是人類,你將與巨人大戰,只要一方先連成一線就贏了,加油吧 人類")

}

function logicOne() {

if ((a==1)&&(b==1)&&(c==1)) all=1;

if ((a==1)&&(d==1)&&(g==1)) all=1;

if ((a==1)&&(e==1)&&(i==1)) all=1;

if ((b==1)&&(e==1)&&(h==1)) all=1;

if ((d==1)&&(e==1)&&(f==1)) all=1;

if ((g==1)&&(h==1)&&(i==1)) all=1;

if ((c==1)&&(f==1)&&(i==1)) all=1;

if ((g==1)&&(e==1)&&(c==1)) all=1;

if ((a==2)&&(b==2)&&(c==2)) all=2;

if ((a==2)&&(d==2)&&(g==2)) all=2;

if ((a==2)&&(e==2)&&(i==2)) all=2;

if ((b==2)&&(e==2)&&(h==2)) all=2;

if ((d==2)&&(e==2)&&(f==2)) all=2;

if ((g==2)&&(h==2)&&(i==2)) all=2;

if ((c==2)&&(f==2)&&(i==2)) all=2;

if ((g==2)&&(e==2)&&(c==2)) all=2;

if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g !=

0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3;

}

function logicTwo() {

if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C";

if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B";

if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A";

(7)

if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G";

if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D";

if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A";

if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I";

if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E";

if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A";

if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H";

if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E";

if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B";

if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F";

if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E";

if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D";

if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I";

if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H";

if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G";

if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I";

if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F";

if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C";

if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C";

if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E";

if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G";

}

function logicThree() {

if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C";

if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B";

if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A";

if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G";

if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D";

if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A";

if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I";

if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E";

if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A";

if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H";

if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E";

if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B";

(8)

if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F";

if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E";

if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D";

if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I";

if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H";

if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G";

if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I";

if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F";

if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C";

if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C";

if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E";

if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G";

}

註解:程式以上面的判斷玩家選擇的位子以及判斷自己要選取哪個位子 function clearOut() {

document.game.you.value="0";

document.game.computer.value="0";

document.game.ties.value="0";

}

function checkSpace() { if ((temp=="A")&&(a==0)) { ok=1;

if (cf==0) a=1;

if (cf==1) a=2;

}

if ((temp=="B")&&(b==0)) { ok=1;

if (cf==0) b=1;

if (cf==1) b=2;

}

if ((temp=="C")&&(c==0)) { ok=1;

if (cf==0) c=1;

if (cf==1) c=2;

}

(9)

if ((temp=="D")&&(d==0)) { ok=1;

if (cf==0) d=1;

if (cf==1) d=2;

}

if ((temp=="E")&&(e==0)) { ok=1;

if (cf==0) e=1;

if (cf==1) e=2;

}

if ((temp=="F")&&(f==0)) { ok=1

if (cf==0) f=1;

if (cf==1) f=2;

}

if ((temp=="G")&&(g==0)) { ok=1

if (cf==0) g=1;

if (cf==1) g=2;

}

if ((temp=="H")&&(h==0)) { ok=1;

if (cf==0) h=1;

if (cf==1) h=2;

}

if ((temp=="I")&&(i==0)) { ok=1;

if (cf==0) i=1;

if (cf==1) i=2;

} }

function yourChoice(chName) { pause = 0;

if (all!=0) ended();

if (all==0) {

(10)

cf = 0;

ok = 0;

temp=chName;

checkSpace();

if (ok==1) {

document.images[chName].src = x;

}

if (ok==0)taken();

process();

if ((all==0)&&(pause==0)) myChoice();

} }

function taken() {

alert("巨人已攻陷這裡請轉換據點") pause=1;

}

function myChoice() { temp="";

ok = 0;

cf=1;

logicTwo();

logicThree();

checkSpace();

while(ok==0) {

aRandomNumber=Math.random()

comp=Math.round((choice-1)*aRandomNumber)+1;

if (comp==1) temp="A";

if (comp==2) temp="B";

if (comp==3) temp="C";

if (comp==4) temp="D";

if (comp==5) temp="E";

if (comp==6) temp="F";

if (comp==7) temp="G";

if (comp==8) temp="H";

if (comp==9) temp="I";

(11)

checkSpace();

}

document.images[temp].src= o;

process();

}

function ended() {

alert("戰爭已結束。如果還想與巨人戰鬥,請再點選一次戰鬥") }

function process() { logicOne();

if (all==1){ wn++; new4 = window.open("","empty2",

"location,status,resizable=yes,width=600,height=700,top=200,left=450"

);

new4.document.write("<html><head><title>新視窗</title></head>人類 獲得勝利<br><img border=0 src=z.jpg width=480 height=683>");}

if (all==2){ ls++;new4 = window.open("","empty2",

"location,status,resizable=yes,width=600,height=700,top=200,left=450"

);

new4.document.write("<html><head><title>新視窗</title></head>巨人 吃光人類<br><img border=0 src=p.jpg width=480 height=360>");}

if (all==3){ ts++;new4 = window.open("","empty2",

"location,status,resizable=yes,width=600,height=700,top=200,left=450"

);

new4.document.write("<html><head><title>新視窗</title></head>這回 合人類與巨人平手<br><img border=0 src=j.jpg width=600

height=400>");}

註解:勝負出來後跳出新視窗 if (all!=0) {

document.game.you.value = wn;

document.game.computer.value = ls;

document.game.ties.value = ts;

}

(12)

}

function playAgain() { if (all==0) {

if(confirm("要重新與巨人在戰嗎?")) reset();

}

if (all>0) reset();

}

function reset() { all = 0;

a = 0;

b = 0;

c = 0;

d = 0;

e = 0;

f = 0;

g = 0;

h = 0;

i = 0;

temp="";

ok = 0;

cf = 0;

choice=9;

aRandomNumber = 0;

comp = 0;

document.images.A.src= blank;

document.images.B.src= blank;

document.images.C.src= blank;

document.images.D.src= blank;

document.images.E.src= blank;

document.images.F.src= blank;

document.images.G.src= blank;

document.images.H.src= blank;

document.images.I.src= blank;

if (t==0) { t=2; myChoice(); } t--;

(13)

}

註解:選擇重新遊戲 將已有的資料刷新為零 // End -->

</script>

</head>

<body>

<center>

<form name=game>

<table border=0>

<td>

<table border=1>

<tr>

<td><a href="javascript:yourChoice('A')"><img src="blank.jpg" border=0 height=100 width=100 name=A alt="Top-Left"></a></td>

<td><a href="javascript:yourChoice('B')"><img src="blank.jpg" border=0 height=100 width=100 name=B alt="Top-Center"></a></td>

<td><a href="javascript:yourChoice('C')"><img src="blank.jpg"

border=0 height=100 width=100 name=C alt="Top-Right"></a></td>

<td><a href="javascript:yourChoice('D')"><img src="blank.jpg"

border=0 height=100 width=100 name=D alt="Middle-Left"></a></td>

<td><a href="javascript:yourChoice('E')"><img src="blank.jpg" border=0 height=100 width=100 name=E alt="Middle-Center"></a></td>

<td><a href="javascript:yourChoice('F')"><img src="blank.jpg" border=0 height=100 width=100 name=F alt="Middle-Right"></a></td>

</tr>

<tr>

<td><a href="javascript:yourChoice('G')"><img src="blank.jpg"

border=0 height=100 width=100 name=G alt="Bottom-Left"></a></td>

<td><a href="javascript:yourChoice('H')"><img src="blank.jpg"

border=0 height=100 width=100 name=H alt="Bottom- Center"></a></td>

<td><a href="javascript:yourChoice('I')"><img src="blank.jpg" border=0 height=100 width=100 name=I alt="Bottom-Right"></a></td>

</tr>

(14)

</table>

<table>

<tr><td><input type=text size=5 name=you></td><td>人類勝</td></tr>

<tr><td><input type=text size=5 name=computer></td><td>巨人

</td></tr>

<tr><td><input type=text size=5 name=ties></td><td>平手</td></tr>

註解:右側記錄勝敗場數

</table>

</td>

</table>

<input type=button value="戰鬥吧人類" onClick="playAgain();">

&nbsp;&nbsp;

<input type=button value="遊戲解說" onClick="help();">

&nbsp;&nbsp;

<input type=button value="結束遊戲" onClick="quitGame();">

</form>

</center>

<p></p>

</body>

Tic Tac Toe

(15)

↑ 以上是修改過後的井字遊戲畫面。把圈圈叉叉改成人類與巨人戰鬥。

這是試玩的遊戲介面,此介面顯示 人類獲勝!

數獨遊戲

遊戲說明:數獨(日本語:数独/すうどく sūdoku)是一種邏輯性的數字填充

遊戲,玩家須以數字填進每一格,而每行、每列和每個宮(即 3x3 的大格)

(16)

有齊 1 至 9 所有數字。遊戲設計者會提供一部份的數字,使謎題只有一個答 案。

一個已解答的數獨其實是一種多了宮的限制的拉丁方陣,因為同一個數字不

可能在同一行、列或宮中出現多於一次。

這種遊戲只需要邏輯思維能力,與數字運算無關。雖然玩法簡單,但數字排 列方式卻千變萬化,所以不少教育者認為數獨是鍛煉腦筋的好方法。因為數 獨上的數字沒有運算價值,僅僅代表相互區分的不同個體,因此可以使用其 他的符號比如拉丁字母、羅馬字母甚至是不同形狀的圖案代替。

數獨是由日本的遊戲公司Nikoli 在1986 年發揚光大的,名稱「數獨」的意

思是「一個數字」。在2005 年,數獨變得世界知名。

<html>

<head>

<meta http-equiv="Content-Language" content="zh-tw">

<meta http-equiv="Content-Type" content="text/html; charset=big5">

<title>7</title>

<SCRIPT LANGUAGE="JavaScript">

(17)

alert("這是一個簡單的數獨遊戲");

</script>

<script Language="JavaScript">

function DD() {

ans=document.f.D1.value+document.f.D2.value+document.f.D3.value+

document.f.D4.value+document.f.D5.value+document.f.D6.value+docu ment.f.D7.value;

ans+=document.f.D8.value+document.f.D9.value+document.f.D10.valu e+document.f.D11.value+document.f.D12.value+document.f.D13.value +document.f.D14.value;

ans+=document.f.D15.value+document.f.D16.value+document.f.D17.v alue+document.f.D18.value+document.f.D19.value+document.f.D20.val ue+document.f.D21.value;

ans+=document.f.D22.value+document.f.D23.value+document.f.D24.v alue+document.f.D25.value+document.f.D26.value+document.f.D27.val ue+document.f.D28.value;

ans+=document.f.D29.value+document.f.D30.value+document.f.D31.v alue+document.f.D32.value+document.f.D33.value+document.f.D34.val ue+document.f.D35.value;

ans+=document.f.D36.value+document.f.D37.value+document.f.D38.v alue+document.f.D39.value+document.f.D40.value+document.f.D41.val ue+document.f.D42.value;

ans+=document.f.D43.value+document.f.D44.value+document.f.D45.v alue+document.f.D46.value+document.f.D47.value;

註解:以上是將玩家選擇的答案跟正確答案比對

co="92154832515684714258969823253947857344792254816";

(18)

註解:這邊是正確答案 if (ans==co) alert("恭喜你答對了");

else

alert("可惜你答錯了");

}

</script>

<SCRIPT LANGUAGE="JavaScript">

function II(){

alert("直排跟橫排以及顏色相同的九宮格內 1~9 的數字不能重複");

}

function CC(){

alert("感謝你的試玩");

window.close();

}

</script>

</head>

<body>

<form name=f method="GET" >

<table border="1" width="83%" height="734" bgcolor="#FFFFCC">

<tr>

<td bordercolor="#000000" align="center">

<select size="1" name="D1" style="font-size: 18pt; color:

#0000FF">

<option>請選擇</option>

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

<option value="6">6</option>

(19)

<option value="7">7</option>

<option value="8">8</option>

<option value="9">9</option>

</select></td>

<td bordercolor="#000000" align="center">

<select size="1" name="D2" style="font-size: 18pt; color:

#0000FF">

<option>請選擇</option>

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

<option value="6">6</option>

<option value="7">7</option>

<option value="8">8</option>

<option value="9">9</option>

後面重複太多以下省略

專題甘特圖

(20)

專題工作分配

(21)
(22)

參考文獻 ( Consultation ) ( 教科書籍 )

JAVA 程式設計項目教程

徹底研究 JAVA 開發實戰經典

最新 JAVA 2 程式設計實例入門增訂第三 版

JAVA SE6 全方位學習 ( 參考網站 )

http://www.javascriptsource.com/games/

(The JavaScript Source)

http://www.javascriptsource.com/repository/

javascripts/2007/08/877901/tictactoe.html http://www.javascriptsource.com/repository/

javascripts/2003/07/228571/numbers.htm

參考文獻

相關文件

• The  ArrayList class is an example of a  collection class. • Starting with version 5.0, Java has added a  new kind of for loop called a for each

建立活動 默契 工作分配 遊戲規則 說明. 發下活動

If x or F is a vector, then the condition number is defined in a similar way using norms and it measures the maximum relative change, which is attained for some, but not all

 When citing a foreword/introduction/preface/afterword, begin the citation with the name of the person who wrote it, then the word “Foreword” (or whatever it is), without

3.16 Career-oriented studies provide courses alongside other school subjects and learning experiences in the senior secondary curriculum. They have been included in the

Wang, Solving pseudomonotone variational inequalities and pseudocon- vex optimization problems using the projection neural network, IEEE Transactions on Neural Networks 17

The Hilbert space of an orbifold field theory [6] is decomposed into twisted sectors H g , that are labelled by the conjugacy classes [g] of the orbifold group, in our case

 A file system (or filesystem) is an abstraction to store, retrieve and update a set of files.  Learn more in