Created
December 5, 2013 17:17
-
-
Save ghostbar/7809491 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var socketio = require('socket.io-client'); | |
| var client = socketio.connect('ws://yahoobingo.herokuapp.com'); | |
| client.on('connect', function(){ | |
| console.log("Connected..."); | |
| var card = {}; | |
| var results = { | |
| "B": [ | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0 | |
| ], | |
| "I": [ | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0 | |
| ], | |
| "N": [ | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0 | |
| ], | |
| "G": [ | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0 | |
| ], | |
| "O": [ | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0 | |
| ] | |
| }; | |
| client.emit('register', { | |
| name: 'Jose Luis Rivas', | |
| email: '[email protected]', | |
| url: 'https://gits.github.com' | |
| }); | |
| client.on('card', function(payload){ | |
| console.log(payload); | |
| card = payload.slots; | |
| }); | |
| function sayBingo(){ | |
| console.log(card, results); | |
| console.log("bingo!"); | |
| client.emit("bingo"); | |
| }; | |
| client.on('number', function(number){ | |
| var slot = number[0], | |
| nr = parseInt(number.substring(1)), | |
| position = card[slot].indexOf(nr); | |
| if (position>=0){ | |
| results[slot][position] = nr; | |
| console.log(slot, nr, "+"); | |
| console.log(results); | |
| } else { | |
| console.log(slot, nr, "-"); | |
| console.log(results); | |
| } | |
| Object.keys(results).forEach(function(key){ | |
| if(results[key][0] && results[key][1] && results[key][2] && results[key][3] && results[key][4]) | |
| sayBingo(); | |
| }); | |
| for(var i = 0; i < 5; i++){ | |
| if(results.B[i] && results.I[i] && results.N[i] && results.G[i] && results.O[i]) | |
| sayBingo(); | |
| } | |
| if(results.B[0] && results.I[1] && results.N[2] && results.G[3] && results.O[4]) | |
| sayBingo(); | |
| if(results.B[4] && results.I[3] && results.N[2] && results.G[1] && results.O[0]) | |
| sayBingo(); | |
| }); | |
| client.on('win', function (){ | |
| console.log("Won!"); | |
| console.log(card); | |
| console.log(results); | |
| }); | |
| client.on('lose', function () { | |
| console.log("Lose!"); | |
| console.log(card); | |
| console.log(results); | |
| }); | |
| client.on('disconnect', function () { | |
| console.log("Disconected"); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment