Просмотр файла game/komp/star_wars/index.html

Размер файла: 3.21Kb
  1. <html>
  2. <head>
  3. <title>Звёздные войны - Scripts - JavaScript - Звёздные войны</title>
  4. <META http-equiv="Content-Type" content="text/html; charset=windows-1251">
  5. <Style>
  6. A:Link{ Color: #000000; Text-decoration: underline}
  7. A:Visited{ Color: #000000; Text-decoration: underline}
  8. A:Hover{ Color: #000000; Text-decoration: none}
  9. td, body {font-family: verdana, arial, helvetica; font-size:11px;}
  10. </Style>
  11.  
  12. <!-- HEAD START HERE -->
  13.  
  14.  
  15.  
  16. <!-- HEAD END HERE -->
  17.  
  18.  
  19.  
  20.  
  21. </head>
  22. <body bgcolor="#EDEDED" text="#000000" link="#000000" topmargin="0" leftmargin="0">
  23. <center>
  24.  
  25. <!-- BODY START HERE -->
  26.  
  27. <P align=center><!-- Эта программа была сделана Hiroshi Okada.-->
  28. <SCRIPT language=JavaScript>
  29.  
  30. // ---- Make array
  31. function MakeArray( n){
  32. this.length = n;
  33. for (var i = 1; i <= n; i++) {
  34. this[i] = 0
  35. }
  36. return this
  37. }
  38.  
  39. // ----- poor man's random number
  40. var d0 = new Date();
  41. var r0 = d0.getSeconds();
  42. function poor_rand(){
  43. d1 = new Date();
  44. r0 = (r0 * r0 + r0 + d1.getSeconds()) % 3721 ;
  45. return r0 % width_n;
  46. }
  47.  
  48. // ---- Parameters of game
  49. var height_n = 8;
  50. var width_n =5;
  51.  
  52. // ---- state of game
  53. var enemy = new MakeArray( width_n); // enemy positions
  54. var wtime; // wait time
  55. var score; // points
  56. var gameover; // in case of gameover set to true
  57.  
  58. // ----- Make the battlefield.
  59. document.write( "<FORM NAME='fm1'>");
  60. document.write( "<INPUT TYPE='text' NAME='message' SIZE=20>");
  61. document.write( "</FORM>");
  62. document.write( "<FORM NAME='fm2'><TABLE>");
  63. for( var i=0; i<height_n; i++){
  64. document.write( "<TR>");
  65. for( var j=0;j<width_n; j++){
  66. document.write( "<TD><CENTER><INPUT TYPE='radio'></CENTER></TD>");
  67. }
  68. document.write( "</TR>");
  69. }
  70. document.write( "<TR>");
  71. for( var j=0;j<width_n; j++){
  72. document.write( "<TD><INPUT TYPE='button' VALUE='-x-' onClick='fire("
  73. + j + ")'></TD>");
  74. }
  75. document.write( "</TR>");
  76. document.write( "</TABLE>");
  77. document.write( "<INPUT TYPE='button' VALUE='СТАРТ' onClick='game_start()'>");
  78. document.write( "</FORM>");
  79.  
  80. // ----- game main timer event
  81. // ----- enemy come one step
  82. function come(){
  83. var n = poor_rand();
  84. document.fm2.elements[ width_n * enemy[n+1] + n].checked = true;
  85. enemy[n+1]++;
  86. if( enemy[n+1] < height_n){
  87. setTimeout("come()", wtime);
  88. }else{
  89. gameover = true;
  90. document.fm1.message.value = "ИГРА ОКОНЧЕНА: " + score ;
  91. }
  92. }
  93.  
  94. // ----- Fire the n th beam
  95. function fire( n){
  96. if( gameover ) return;
  97. for( var i=0; i<enemy[n+1]; i++){ // clear enemy
  98. document.fm2.elements[ width_n * i + n].checked = false;
  99. }
  100. score += enemy[ n+1];
  101. document.fm1.message.value = "ОЧКИ: " + score;
  102. enemy[ n+1] = 0;
  103. if( wtime > 100){ wtime -= 10};
  104. }
  105.  
  106. // ---- initialize & start game
  107. function game_start(){
  108. for( var n=0; n<width_n; n++){
  109. for( var i=0; i<enemy[n+1]; i++){
  110. document.fm2.elements[ width_n * i + n].checked = false;
  111. }
  112. enemy[n+1] = 0;
  113. }
  114. wtime = 400;
  115. score = 0;
  116. gameover = false;
  117. document.fm1.message.value = "ОЧКИ: " + score;
  118. setTimeout("come()", wtime);
  119. }
  120.  
  121. // -->
  122. </SCRIPT>
  123.  
  124. <!-- BODY END HERE -->
  125.  
  126.  
  127.  
  128. </body>
  129. </html>
  130.