topical media & game development

talk show tell print

lib-js-terminal-sample-invaders.htm / htm



  <html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
          <title>Invaders Sample</title>
          <script language="JavaScript" type="text/javascript" src="lib-js-terminal-termlib.js"></script>
          <script language="JavaScript" type="text/javascript" src="lib-js-terminal-termlib-invaders.js"></script>
  
  <script type="text/javascript">
  <!--
  
  // *** text wrap sample ***
  // mass:werk, N.Landsteiner 2007
  
  var help = [
          '%+r **** termlib.js text wrap sample **** %-r',
          ' ',
          ' * type "invaders" to play invaders.',
          ' * type "help" to see this page.',
          ' * type "exit" to quit.',
          ' '
  ]
  
  var term;
  
  function termOpen() {
          if ((!term) || (term.closed)) {
                  term = new Terminal(
                          {
                                  x: 220,
                                  y: 70,
                                  cols: 90,
                                  rows: 30,
                                  termDiv: 'termDiv',
                                  bgColor: '#111111',
                                  greeting: help.join('\%n'),
                                  handler: termHandler,
                                  exitHandler: termExitHandler
                          }
                  );
                  term.open();
                  
                  // dimm UI text
                  var mainPane = (document.getElementById)?
                          document.getElementById('mainPane') : document.all.mainPane;
                  if (mainPane) mainPane.className = 'lh15 dimmed';
          }
  }
  
  function termExitHandler() {
          // reset the UI
          var mainPane = (document.getElementById)?
                  document.getElementById('mainPane') : document.all.mainPane;
          if (mainPane) mainPane.className = 'lh15';
  }
  
  function termHandler() {
          // default handler + exit
          this.newLine();
          if (this.lineBuffer.match(/^\s*exit\s*/i)) {
                  this.close();
                  return;
          }
          else if (this.lineBuffer.match(/^\s*invaders\s*/i)) {
                  TermlibInvaders.start(this);
                  return;
          }
          else if (this.lineBuffer.match(/^\s*help\s*/i)) {
                  this.clear();
                  this.write(help);
          }
          else if (this.lineBuffer != '') {
                  // echo with write for wrapping, but escape any mark-up
                  this.write('You wrote: '+this.lineBuffer.replace(/%/g, '%%'));
                  this.newLine();
          }
          this.prompt();
  }
  
  // demo hooks
  
  function test(command) {
          if ((!term) || (term.closed)) {
                  alert('Please open the terminal first!');
                  return;
          }
          TermGlobals.importEachLine( command );
  }
  
  //-->
  </script>
  
  <style type="text/css">
  body,p,a,td {
          font-family: courier,fixed,swiss,sans-serif;
          font-size: 12px;
          color: #cccccc;
  }
  .lh15 {
          line-height: 15px;
  }
  
  .term {
          font-family: "Courier New",courier,fixed,monospace;
          font-size: 12px;
          color: #94aad6;
          background: none;
          letter-spacing: 1px;
  }
  .term .termReverse {
          color: #232e45;
          background: #95a9d5;
  }
  
  a,a:link,a:visited {
          text-decoration: none;
          color: #77dd11;
  }
  a:hover {
          text-decoration: underline;
          color: #77dd11;
  }
  a:active {
          text-decoration: underline;
          color: #eeeeee;
  }
  
  a.termopen,a.termopen:link,a.termopen:visited {
          text-decoration: none;
          color: #77dd11;
          background: none;
  }
  a.termopen:hover {
          text-decoration: none;
          color: #222222;
          background: #77dd11;
  }
  a.termopen:active {
          text-decoration: none;
          color: #222222;
          background: #eeeeee;
  }
  
  table.inventory td {
          padding-bottom: 20px !important;
  }
  
  tt {
          font-family: courier,fixed,monospace;
          color: #ccffaa;
          font-size: 12px;
          line-height: 15px;
  }
  
  li {
          line-height: 15px;
          margin-bottom: 8px !important;
  }
  
  .dimmed,.dimmed *,.dimmed * * {
          background-color: #222222 !important;
          color: #333333 !important;
  }
  
  @media print {
          body { background-color: #ffffff; }
          body,p,a,td,li,tt {
                  color: #000000;
          }
          pre,.prop {
                  color: #000000;
          }
          h1 {
                  color: #000000;
          }
          a,a:link,a:visited {
                  color: #000000;
          }
          a:hover {
                  color: #000000;
          }
          a:active {
                  color: #000000;
          }
          table.inventory {
                  display: none;
          }
  }
  
  </style>
  </head>
  
  <body bgcolor="#222222" link="#77dd11" text="#cccccc" alink="#eeeeee" vlink="#77dd11"
  topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" marginheight="0" marginwidth="0">
  
  <table border="0" cellspacing="20" cellpadding="0" align="center">
  <tr>
          <td nowrap><a href="lib-js-terminal-index.htm">termlib.js home</a></td>
          <td>|</td>
          <td nowrap><a href="lib-js-terminal-multiterm-test.htm">multiple terminals</a></td>
          <td>|</td>
          <td nowrap><a href="lib-js-terminal-parser-sample.htm">parser</a></td>
          <td>|</td>
          <td nowrap><a href="lib-js-terminal-faq.htm">faq</a></td>
          <td>|</td>
          <td nowrap><a href="lib-js-terminal-readme.txt" title="readme.txt (text/plain)">documentation</a></td>
          <td>|</td>
          <td nowrap><a href="lib-js-terminal-samples.htm" style="color: #cccccc;">samples</a></td>
  </tr>
  </table>
  
  <table border="0" cellspacing="20" cellpadding="0">
          <tr valign="top">
          <td nowrap>
                  <table border="0" cellspacing="0" cellpadding="0" width="190" class="inventory">
                  <tr><td nowrap>
                          Invaders Sample<br>&nbsp;
                  </td></tr>
                  <tr><td nowrap>
                          <a href="javascript:termOpen()" onfocus="if(this.blur)this.blur();" onmouseover="window.status='open terminal'; return true" onmouseout="window.status=''; return true" class="termopen">&gt; open terminal &nbsp;</a>
                  </td></tr>
                  <tr><td nowrap>
                          <p><a href="javascript:test('invaders')" onfocus="if(this.blur)this.blur();" class="termopen">&gt; play invaders&nbsp;</a></p>
                  </td></tr>
                  <tr><td nowrap>
                          &nbsp;
                  </td></tr>
                  <tr><td nowrap class="lh15">
                          &nbsp;<br>
                          (c) mass:werk,<br>N. Landsteiner 2005-2008<br>
                          <a href="http://www.masswerk.at/" target="_blank">http://www.masswerk.at>
                  </td></tr>
                  </table>
          </td>
          <td class="lh15" width="560" id="mainPane">
                  <p><b style="letter-spacing: 1px;">Termlib - Invaders</b><br>&nbsp;</p>
                  <p>A simple text-mode invaders game.</p>
                  <p>Requires version 1.4 of &quot;termlib.js&quot;.</p>
                  <p>Usage:</p>
                  <p><tt>&nbsp;&nbsp;&nbsp;&nbsp;TermlibInvaders.start(<i>TerminalRef</i> [, <i>maxCols</i> [, <i>maxRows</i>]])</tt></p>
                  <p>returns status (boolean, <tt>true</tt>: success).</p>
                  <p>The optional arguments <i><tt>maxCols</tt></i> and <i><tt>maxRows</tt></i> specify the maximum dimensions to use for the game. If the terminal window is bigger, the game will be centered in the window and a frame will be drawn around.</p>
                  
                  <p>The code is contained in a single global object and supports configurable colors using the web-colors API.</p>
                  
                  <p>Usage example:</p>
                  
                  <p><tt>if ( TermlibInvaders.start(this) ) {<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;return;<br>
                  }<br>
                  else {<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;// oops, terminal doesn't meet the requirements<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;this.write('Sorry, invaders failed.');<br>
                  }</tt></p>
                  
                  <p>&nbsp;</p>
          </td>
          </tr>
  </table>
  
  <div id="termDiv" style="position:absolute; visibility: hidden; z-index:1;"></div>
  
  </body>
  </html>
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.