Showing posts with label Technical. Show all posts
Showing posts with label Technical. Show all posts

Friday, February 6, 2015

Step by step to launch my installation

Step 1
Get a router.
Define the local server.
Go to DHCP-address Reservation
Add new.
Insert your computer MAC address
In the reserved IP Address : 192.168.0.103, then save.


Step 2
Go into folder “Software and Source” -> “installer” folder.
Installed node.js and xampp ( in the folder had provided software for mac and window).

Step 3
Go to folder “Artefact” and copy “websock-mastering” folder to your desktop.
Go to folder “Artefact” and copy “game” folder to Xampp/htdocs.


Step 4
Launch “Terminal” for Mac and “Command Prompt” for window.
Launch “ node index.js”


Step 5
Launch “XAMPP”, then press start all.


Step 6
Off all the internet connection of your mobile devices and computer and connect to the router when you setup your personal server. For mobile device also need to off the mobile data.


Step 7
After connecting to the specific connection/router, Main screen (computer) launch the internet browser (“Chrome”) then key in ”http://192.168.0.103/game/main.htm


Step 8
For mobile devices connected to “http://192.168.0.103/game/p1.htm” for player one;
For mobile devices connected to “http://192.168.0.103/game/p2.htm” for player two.
or
Scan the QR code.


Step 9

Enjoy the game.

Wednesday, February 4, 2015

Main Page Background Music

Image1

Image2


After refine and restore the error and code, i realized my main dont have anything sound effect so i did a sound function to call the background music and make it loop until player login and start the games.

Image1 show i call the music and how i make it loop.

Images 2 show i will pause the music when it load to the game page.

References
Stackoverflow.com,. 'Playing Audio With Javascript?'[online] Available at: http://stackoverflow.com/questions/9419263/playing-audio-with-javascript [Accessed 5 Feb. 2015.]
Stackoverflow.com,. 'Sound Effects In Javascript / HTML5'. [online] Available at: http://stackoverflow.com/questions/1933969/sound-effects-in-javascript-html5  [Accessed 5 Feb. 2015.]

Stackoverflow.com, (2014). How do I implement press and hold button javascript?. [online] Available at: http://stackoverflow.com/questions/702165/how-do-i-implement-press-and-hold-button-javascript [Accessed 24 Dec. 2014].

Friday, January 30, 2015

Count Down Timer to go back to Main page

After thinking for awhile i think is better to remove the restart status in the end of the games. because my objective of this installation is showcase how can we use web-socket, browser and the mobile device to create something new in technology and interaction.

So i decided to make the game if user lose or win then game will automatically bring the players back to the main screen. if you they will like to play just press start then they are able to play again.

So i create a function to link to another page after 5 seconds when the function is called. For now i linked the page the first pages which is main.htm now.


So every time when the game over or when the game timer finish the the function will call and after 5 seconds the page will automatically link back to main page.



References
W3schools.com,. 'Javascript Timing Events' [online] Available at: http://www.w3schools.com/js/js_timing.asp [Accessed 30 Jan. 2015.]

Friday, January 23, 2015

Consultation with Yee Siang (23/1/2015)

The accelerometer work and able to move two different speed when the player tilt more. So this week is just to check what are some other update i am able to put in to let user had a better user experiences and also debugging.

The accelerometer had a minor error which is one of the plane cannot move left, while discussing with Yee Siang i find out is because i put it the wrong keycode. So after switching the keycode every was able to work perfectly.

I discuss Yee Siang whether i should create the restart function so when they lose they are able to restart. Yee Siang did say yes and we are trying to make the function work . and if they didnt press restart it will automatic go back to main interface.

So that will my final week consultation objective which able to let the to work and have perfect interaction cycle.

When i reach i done some thinking and though i think i just make the game restart without letting restart if the player want to continue the can just press start in the main then start the game again. this is use to prevent people staying over the installation for too long.

Friday, January 16, 2015

Consultation with Yee Siang (16/112015)

I was very sorry that, my laptop break down at the very important day before my consultation. My laptop pass away a day before my consultation make need to go borrow Melissa's laptop and update my old files back to the newest files. I am glad that i had back the previous files but i am sad that i back up not seldom enough because the code i back up is before i successfully code accelerometer. Which make need to code again in class but this time even faster.

In this week tutorial i am unable to reach my target to make two speed. So I code it inside class. we was trying to think a better to code the two different speed java script but the first few method doesnt work. Suddenly i got idea of creating a separate function to for different speed, so when check the condition if more the digit then will trigger the second function which will make the ship move faster. The Yee Siang ask me try and was able to work. Then is almost 5 pm i finish the all while i reach home.

Friday, January 9, 2015

Consultation with Yee Siang (9/1/2015)


During the two weeks breaks, i went to cyber jaya to find Yee Siang for extra consultation so i am able to finish the code to show in the second guest review.And during the consultation, i am able to finish the game structure with some help of Yee Siang. Then Yee Siang say that id only using button to control will lose the main purpose of using mobile devices. So i decided to add in accelerometer to control the ship. Although i am not able to show it during the guest review but i actually already start working on the code. But there some error i cant manage to debug.

In this week tutorial Yee Siang show me Firebug for chrome, which is a plugin for chrome to help me trace and debug my code. I am able to access and control the accelerometer in the end of the class. But Yee Siang say that it will be good that when tilt their phone more then the ship will move faster and ask to go back and try myself and show him next week.

So that will be my next week object to create more speed trigger function to let the ship move faster.

Monday, December 29, 2014

Countdown Timer

For my game i need to create a timer to just let the user play for a limited time. since this project is just to let user know about the technology and experience how fantastic it will be that we are able to control and interact with our personal mobile devices.

While searching online to find how to create a timer with java script, I was guide to this specific website from Google.

From this website i am able to copy and modified my personal timer from here. As always i am will start in new working files to test is it the code i want then only bring in to my actual working files.

I am going make my game duration around 1 minute to 1 minute 30 seconds, so for var i use 90 then the var minutes = Math.round(second-30)/60 with round out to the time i want then when it is being trigger it will minus when it reach 0:00 the will stop the timer and show the player they had win the game.


This is the code in html inside body. 

And i code style the CSS to make it appear like the image below.




So that is how i get my game timer.


References
Phpjabbers.com,. 'Javascript Countdown Timer | Javascript Tutorial'.  [online] Available at:http://www.phpjabbers.com/javascript-countdown-timer-php46.html [Accessed 29 Dec. 2014].

Friday, August 22, 2014

WebSocket Server & Mobile Client

Although i successfully using socket io to create a chatroom that able to let few computer to communicate but only computer that have node js are able to use the chatroom but that is not the connection i will like to have for my project. So me and tutor yee siang and jam who both are the professional in this industry sit down in the lab and try to figure out the possibility of fixing. Yee siang and jam did mention this is some like computer science level already so even them also need some research only can fix it. At that point i almost gave up and think i will fail my final year project but luckily Yee Siang are able to solve the problem. That night after the 2 hours meeting, Yee Siang tag in a facebook post, which is a tutorial he created to base on the problem i had . He said that when research on this area not body had share the solution. Just part and part, then he straight away combine the code and create a free source tutorial to share his tutorial.

So basically there are are few step need to beware of compare to our last time tutorial.

here is the link that send to me by my lecturer : http://tech.yeesiang.com/websocket-server-mobile-client/. if you are interested to this code can try to subscribe the blog.(yee siang i help you promote your blog. LOL )

You require to download Xampp, Node.js

To create the server you need to follow this few steps.

First, you need to have nodejs installed.
Save the code below into websock-server\index.js
Then, in your terminal/cmd, type npm install websocket@1.0.3 to install the nodejs websocket library.




Make sure your port 8080 is not occupied by other program as I am using port 8080 in this example.


Next, in your terminal/cmd, cd into the folder and type node index.js

var
http = require('http');
var server = http.createServer(function(request, response) {
    console.log((new Date()) + ' Received request for ' + request.url);
    response.writeHead(404);
    response.end();
});
server.listen(8080, function() {
    console.log((new Date()) + ' Server is listening on port 8080');
});
wsServer = new WebSocketServer({
    httpServer: server,
    // You should not use autoAcceptConnections for production
    // applications, as it defeats all standard cross-origin protection
    // facilities built into the protocol and the browser.  You should
    // *always* verify the connection's origin and decide whether or not
    // to accept it.
    autoAcceptConnections: false
});
function originIsAllowed(origin) {
  // put logic here to detect whether the specified origin is allowed.
  return true;
}
var connections = {};
var connectionIDCounter = 0;
    
wsServer.on('request', function(request) {
    if (!originIsAllowed(request.origin)) {
      // Make sure we only accept requests from an allowed origin
      request.reject();
      console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
      return;
    }
    //var connection = request.accept('kraken-protocol', request.origin);
    var connection = request.accept(null, request.origin);
    connection.id = connectionIDCounter ++;
    connections[connection.id] = connection;
    
   console.log((new Date()) + ' Connection ID ' + connection.id + ' accepted.');
    
    connection.on('message', function(message) {
        if (message.type === 'utf8') {
            console.log('Received Message: ' + message.utf8Data);
            //connection.sendUTF(message.utf8Data);
            broadcast(message.utf8Data)
        }
        else if (message.type === 'binary') {
            console.log('Received Binary Message of ' + message.binaryData.length + ' bytes');
            connection.sendBytes(message.binaryData);
        }
        
    });
    
    connection.on('close', function(reasonCode, description) {
        console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected. '+"Connection ID: " + connection.id);
        // Make sure to remove closed connections from the global pool
        delete connections[connection.id];
    });
});
// Broadcast to all open connections
function broadcast(data) {
    Object.keys(connections).forEach(function(key) {
        var connection = connections[key];
        if (connection.connected) {
            connection.send(data);
        }
    });
}
// Send a message to a connection by its connectionID
function sendToConnectionId(connectionID, data) {
    var connection = connections[connectionID];
    if (connection && connection.connected) {
        connection.send(data);
    }
}

Save then you will see this in your folder

This is able to use as server. Is user a output screen . Every time when people log in or out will have update. Then everything when people key in message it automatically update on the page.

After create the server we need to create the client files.

For the client part, the tutorial ask to going to create 2 interface, one for sending and receiving chat msg (index.htm), another for receiving chat msg only (logger.htm) which is the display.

You will need to change the Server IP in it into yours (ws://192.168.0.200:8080)

So now i can open the index.htm and type a msg, and it will appear on the space below the input box, as well as in logger.htm

I can even put index.htm into phonegap (need to provide option for user to enter the Server IP) and it can serve as a ‘controll’ while logger.htm can be modified to be a ‘receiver’ which also know as a "output".

Put the two files in the websock-client folder


index.htm source code
<head>
    <title>Node Based Echo</title>
    <script src="js/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="js/jquery.websocket-0.0.1.js" type="text/javascript"></script>
    <script src="js/jquery.json.min.js" type="text/javascript"></script>
</head>
<body>
    <script type="text/javascript">
        // sends a message to the websocket server
        function sendToServer() {
            ws.send('say', '{ messageTextA: ' + $('#echoText').val() + ' }');
            //ws.send('krakenmsgB', '{ messageTextB: ' + $('#echoText').val() + ' }');
        }
        // set-up web socket
        var ws = $.websocket("ws://192.168.0.200:8080/", {
            open: function () { },
            close: function () { alert('websocket has been closed'); },
            events: {
                say: function (e) { $('#returnText').append(e.data + "<br/>"); },
            }
        });
    </script>
    <div>
        <div style="float: left; clear: left; padding-top: 2px;">
            Your text:
        </div>
        <div style="float: left; padding-left: 20px;">
            <input type="text" id="echoText" style="width: 150px;" required />
        </div>
        <div style="clear: left;">
            <input type="button" onclick="javascript:sendToServer();" value="Send" />
        </div>
        <div id="returnText" style="clear: left; height: 200px; padding-top: 30px;">
        </div>
    </div>
</body>
</html>

Then logger.htm source code

<html lang="en"> <head> <title>Logger</title> <script src="js/jquery-1.6.2.min.js" type="text/javascript"></script> <script src="js/jquery.websocket-0.0.1.js" type="text/javascript"></script> <script src="js/jquery.json.min.js" type="text/javascript"></script> </head> <body> <script type="text/javascript"> // set-up web socket var ws = $.websocket("ws://localhost:8080/", { open: function () { }, close: function () { alert('websocket has been closed'); }, events: { say: function (e) { $('#returnText').append(e.data + "<br/>"); }, } }); </script> <div> <div id="returnText" style="clear: left; height: 200px; padding-top: 30px;"> </div> </div> </body> </html>

To try it  copy the websock-client files into xampp htdocs first so that phone are able to connect to the folder to internet database.


Start xampp first before launch in browser. and also terminal as well .

So this will be how it will look like