mjc 发表于 2007-4-27 11:09:12

***游戏类***简单的走迷宫游戏

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
要完成此效果需要两个步骤

第一步:把如下代码加入到<body>区域中


<center>
<br>
</center>

<center>



<br>

<br>

<center>

    <table border=5 bordercolor=#000000 borderlight=green>
      <tr>
      <td align=center><font size=5 color=red face="arial, helvetica, sans-serif"><strong><font face="楷体_gb2312">走迷宫</font></strong></font></td>
      </tr><tr><td align=center>

<script>

var line = "";

var x = 0;

var y = 0;

var full="*";

var blank = ".";

var wall = "#";

var goal = "$";



var fill = "";



// functions to create the board



function makeboard() {

         for (var i=1; i<= 10; i++)

               this = new makerow();

         return this;

}



function makerow() {

         for (var i=1; i<= 10; i++)

               this=blank;



         return this;

}



// functions to fill & clear the board.



function clearboard (form) {

// clears & resets the board

         x = 0;



         y = 0;



         form.xval.value = 1;



         form.yval.value = 1;



         for (var i=1; i<= 10; i++)

               for (var j=1; j<= 10; j++)

                         theboard=blank;



         drawmaze();

         fillboard(form);

         return;

}



function fillboard (form) {

         // clear board buffer

         line = "";

         form.grid.value = "";

         // fill board buffer

         for (var i=1; i<= 10; i++)

               for (var j=1; j<= 10; j++)

                         line += theboard;



         // move buffer contents to board

         form.grid.value=line;



}



function plot (v, h) {

         theboard = fill;



}



function drawmaze() {

// plots the walls of the maze

//

// ideally, a function should do this automatically,

// or maybe i should write a maze generating function in js!

// note: this program operates in y,x co-ordinates (not standard x,y).



         theboard = goal;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



theboard = wall;



theboard = wall;



theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



         theboard = wall;



}



function update(form) {

         var horiz = eval(form.xval.value);



         var vert = eval(form.yval.value);



         plot(vert,horiz);

         fillboard(form);

         return;

}



function initboard() {

         theboard = new makeboard();

         fill = full;



         clearboard(document.board);

         update(document.board);

}



// functions to handle the player piece

//

// i suppose i could have written one function to handle this,

// but it was getting too complex.feel free to try. :)

//



function decx(form) {

         fill = blank;



         update(form);

         checkx = eval(form.xval.value - 1);

         checky = form.yval.value;



         if (form.xval.value > 1) {

               if (theboard != wall) {

                         form.xval.value=eval(form.xval.value - 1);

               }

               else {

                         alert("thud!\nyou hit a wall.");

               }

               if (theboard == goal) {


                         alert("you win!");

               }

         }

         fill = full;

         update(form);

}



function incx(form) {

         fill = blank;

         update(form);

         checkx = eval(1 * form.xval.value + 1);

         checky = form.yval.value;

         if (form.xval.value < 10) {

               if (theboard != wall) {

                         form.xval.value=eval(1 * form.xval.value + 1);

               }

               else {

                         alert("thud!\nyou hit a wall.");

               }

               if (theboard == goal) {

                         alert("you win!");

               }

         }

         fill = full;



         update(form);

}



function decy(form) {

         fill = blank;



         update(form);

         checkx = form.xval.value;



         checky = eval(form.yval.value - 1);

         if (form.yval.value > 1) {

               if (theboard != wall) {

                         form.yval.value=eval(form.yval.value - 1);

               }

               else {

                         alert("thud!\nyou hit a wall.");

               }

               if (theboard == goal) {

                         alert("you win!");

               }

         }

         fill = full;

         update(form);

}



function incy(form) {

         fill = blank;

         update(form);

         checkx = form.xval.value;

         checky = eval(1 * form.yval.value + 1);

         if (form.yval.value < 10) {

               if (theboard != wall) {

                         form.yval.value=eval(1 * form.yval.value + 1);

               }

               else {

                         alert("thud!\nyou hit a wall.");

               }

               if (theboard == goal) {

                         alert("you win!");

               }

         }

         fill = full;



         update(form);

}



// various functions



function cheater (form) {

// refuse to change values manually, and start over. cheater!

         alert("you can't change this value manually.\nplease use the buttons.");

         clearboard(form);

         update(form);

}





</script>



<form method="post" name="board">

<input type='button' value='reset' onclick='clearboard(this.form);update(document.board);'>

<br>

<textarea name="grid" rows="12" cols="10" wrap=virtual>






第二步:把“onload="timerone=window.settimeout('scrollit_r2l(100)',500);initboard();" ”加在标记里
      










--------------------------------------

http://www.huoyue.com.cn 活跃网,活跃人群的论坛,访问活跃网,将给您带来意想不到的收获,还可以免费为您开论坛,让您免费拥有与朋友、网友交流的论坛。你是年轻人吗?你活跃你就上!
页: [1]
查看完整版本: ***游戏类***简单的走迷宫游戏