Wednesday, March 29

Hacking Game: Part 1 - Electron Setup & Initial Code


Introduction

Today I started programming the beginnings of a yet unnamed hacking game. I know there have been, and will be, many fantastic games already developed in this genre. I am not expecting this game to live up to the likes of Uplink, Hacker Evolution, or Hackmud.

The one thing that might set this one apart a little is the fact that I am streaming the development on twitch.tv/failedsleep. The other small thing is that I will be posting the source code, so it is available for download and experimenting with in days of the stream.


Accomplishments

  • Created the Main Menu
  • Started the Game Intro
  • Started the main Terminal console


Electron.atom.io

Build cross platform desktop apps with JavaScript, HTML, and CSS. You can download pre compiled versions for most systems at: github.com/electron/electron/releases.


Screen shots






The Links


Tuesday, March 28

NodeJS, Socket.io: Simple Client / Server


Introduction

The minimum amount of code to have NodeJS serve a simple socket.io client and server.



Requirements

This code uses NodeJS module "socket.io" which you install with the following command:
npm install socket.io


Server.js Source Code

var http = require('http')
 , fs = require('fs')

 , webpage = fs.readFileSync(__dirname + '/client.html')
 , port = 2017
 ;

// Send client.html to all requests
var server = http.createServer(
 function(req, res) {
   res.writeHead(200, {'Content-Type': 'text/html'});
   res.end( webpage );
 }
);

// Socket.io server listens to our app
var io = require('socket.io').listen( server );

// Send current time to all connected clients
function sendEveryone( msg ) {
 io.emit('msg', msg );
}


// Listen for connections
io.on('connection', function( socket ) {
    // Single Client's socket
    socket.emit('confirm', 'Server here');
    socket.on('from Client', function( msg ){
     console.log( msg );
   });
});

server.listen( port );




client.html Source Code

<!doctype html>
<html>
<head>
   <script src='/socket.io/socket.io.js'></script>
</head>
<body>

 <script>
   var socket = io();

   socket.on( 'welcome' , function( msg ) {
       console.log( msg );

       // Contact Server
       socket.emit('from Client', 'Client Here');
   });

   socket.on( 'msg' , function( msg ) {
       console.log( 'incoming:' , msg );
   });

 </script>
</body>
</html>