Skip to content

Commit

Permalink
Bingo 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
eufelipemateus committed Sep 19, 2019
1 parent e78b4ef commit cd9950c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 70 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ npm start

### How game works

The server draws in a certain time several numbers of a range each user can dial the numbers as the server races, the user is only declared vencendos if they complete with all the numbers drawn if the user presses the bingo button in a different declared situation loser.
The server draws in a certain time several numbers of a range each user can dial the numbers as the server races, the user is only declared winner if they complete with all the numbers drawn if the user presses the bingo button in a different declared situation loser.


### Diagram
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "node-bingo-game",
"version": "2.0.1-dev",
"version": "2.0.1",
"description": "Jogo de Bingo Multiplayer Online",
"main": "build/server.js",
"scripts": {
"compile": "tsc -w",
"compile": "tsc",
"start": "node dist/server.js"
},
"repository": {
Expand All @@ -19,7 +19,6 @@
},
"devDependencies": {
"@types/node": "^7.0.5",
"copyfiles": "^2.1.1",
"typescript": "^3.1.6"
},
"keywords": [
Expand Down
27 changes: 10 additions & 17 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@

var IntervalValue = 1;
var IntervalBPoints;
var TimeInterval = 80;
var TimeInterval = 100;
var NumerosSorteados = [];


Expand All @@ -243,8 +243,7 @@

function GirarRoleta(){
IntervalBPoints = setInterval(function(){



document.querySelector('div[data-value="'+IntervalValue+'"]').classList.remove("apontado");

IntervalValue++;
Expand All @@ -266,7 +265,7 @@
}

function StopRoleta(){
clearInterval(IntervalBPoints);
clearInterval(IntervalBPoints);
}

function SortearNumero(num){
Expand All @@ -279,9 +278,7 @@
var selectedSquares = new Array();

function newCard(card) {//precisa melhorarar pentende de atualização futura!

let colPlace = new Array(1,2,3,4,5);

let colPlace = new Array(1,2,3,4,5);
for(var p=0 ; p<colPlace.length; p++){
for(var i=0 ; i<card.length; i++){
if(card[i]<=(colPlace[p]*(MaxPoints/5))){
Expand All @@ -292,7 +289,6 @@
}
}
}

}

function selectSquare(event){
Expand All @@ -313,7 +309,7 @@
/**** Audio ****/
var Audio;

function initAudio(){
function InitAudio(){
Audio = document.createElement("audio");
document.body.appendChild(Audio);
}
Expand All @@ -324,10 +320,8 @@

</script>
<script>
/*** Iniciar Sistema ***/
function initAll() {


/*** Listen connections ***/
function listen() {
socket.on('connect', () => {
socket.emit('NEW CONNECTION');
});
Expand All @@ -341,7 +335,6 @@
});

socket.on('NEW CARD', function (msg) {
initAudio();
InitRoleta();
newCard(msg);

Expand Down Expand Up @@ -378,13 +371,13 @@

socket.on('disconnect', () => {
StopRoleta();
console.log("Foi Fechado!! ");
console.log("Conexao Fechada!! ");
});

}
</script>
<script>
initAll();
listen();
InitAudio();
</script>

</html>
41 changes: 15 additions & 26 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class App {
public app: express.Application;
public server: Server;
private io: SocketIO.Server;
public PORT: number = 8100;
public PORT: number = 8080;
public debug:boolean=false;


Expand All @@ -21,7 +21,6 @@ class App {
routes() {
this.app = express();
this.app.use(express.static('public'));

}

private sockets(): void {
Expand All @@ -32,14 +31,13 @@ class App {
private listen(): void {

this.io.on('connection', (socket: any) => {
if(this.debug)console.info('a user connected');
if(this.debug)console.info('A user connected!');

socket.on('NEW CONNECTION', function (msg) {

socket.emit("NEW NUMBER POINTS",bingo.Numbers);
socket.emit('NUMBERS DRAW',bingo.Sorteados);


let card = bingo.NewCard();
socket.card = card ;
socket.selectedCards = Array();
Expand All @@ -62,24 +60,17 @@ class App {

if(socket.selectedCards.length>=bingo.CardNums){
let NumerosChekededs=0;
this.bingo.Sorteados.forEach(function(N,index) {
this.bingo.Sorteados.forEach(function(N) {

if(N){
socket.selectedCards.forEach(function(n){
if(n==index){
NumerosChekededs++;
}else{
/*User lost*/
socket.emit('YOU LOST')
if(this.debug)console.info("Trapaça! Numero não sorteado");
}
});
console.log("NuChe:"+NumerosChekededs);
}else{
/*User lost*/
socket.emit('YOU LOST')
if(this.debug)console.info("Trapaça! Numero não sorteado!");
}
socket.selectedCards.forEach(function(n){
if(n==N && (socket.card.indexOf(n)>-1)){
NumerosChekededs++;
}else{
/*User lost*/
socket.emit('YOU LOST')
if(this.debug)console.info("Trapaça! Numero não sorteado");
}
});
});
if(NumerosChekededs>=this.bingo.CardNums){
//*User win Game*/
Expand All @@ -96,7 +87,7 @@ class App {

socket.on('disconnect', () => {
bingo.Gamers.splice(bingo.Gamers.indexOf(socket), 1);
if(this.debug)console.info('user disconnected');
if(this.debug)console.info('User disconnected!');
});
});
}
Expand All @@ -107,10 +98,9 @@ class App {
do{
newNumber = bingo.GetNewNum() + 1
}while(bingo.Sorteados.indexOf(newNumber)!==-1 );


bingo.Sorteados.push(newNumber);
io.emit('DRAW NUMBER',newNumber);

},bingo.IntervaloSorteio,this.io);


Expand All @@ -121,9 +111,8 @@ class App {
"win_possible":bingo.PossibleGamersWinners(),
"draw_numbers_counts":bingo.Sorteados.length
});
},1000,this.io);
},2000,this.io);
}
}


export default new App();
37 changes: 16 additions & 21 deletions src/Bingo.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@

class Bingo {
public Gamers = Array();
public Numbers = 75;
public Sorteados;
public Numbers = 90;
public Sorteados= Array();
public CardNums = 24;
public IntervaloSorteio = 5000;


constructor() {

this.Sorteados = new Array();
}
constructor() {}

public NewCard() {
let usedNumbers=Array();
let useds=Array();
for(var i=0 ; i<this.CardNums; i++){
let newNumber;
do{
newNumber = this.GetNewNum() + 1;
}while(usedNumbers.indexOf(newNumber)!==-1 ) ;
usedNumbers.push(newNumber);
}while(useds.indexOf(newNumber)!==-1 ) ;
useds.push(newNumber);
}
return usedNumbers.sort(function(a,b){ return a - b });
return useds.sort(function(a,b){ return a - b });
}

public GetNewNum() {
return Math.floor(Math.random() * this.Numbers );
}

public PossibleGamersWinners(){//Not working
public PossibleGamersWinners(){
let winners=0;

this.Gamers.forEach((J)=> {
let acertos = 0;
this.Sorteados.forEach(function(Boolean,index) {
J.card.forEach(function(n) {
if(index==n){
acertos++;
for(let a=0 ; a<this.Sorteados.length; a++){
for(let b=0 ; b<J.card.length; b++){
if(this.Sorteados[a]==J.card[b]){
acertos++;
}
});
});
if(acertos>=this.CardNums) winners;
}
}
if(acertos>=this.CardNums) winners++;
});
return winners;
}
}

export default new Bingo();
export default new Bingo();
5 changes: 3 additions & 2 deletions src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Server } from 'http';

const port = process.env.PORT || app.PORT;

app.debug = true;
app.debug = false;

app.server.listen(port, function () {
console.log(`Server running in + ${port}`);
console.info(`Server running in ${port}...`);
});

0 comments on commit cd9950c

Please sign in to comment.