dimanche 2 décembre 2018

How can I get names of players and the chips from a database?

I'm creating a Poker Web App
Currently this is my player function

var Player = function( socket, name, chips )

I am using Node.js and Socket.io

In my App.js this is the code for player registration and distributing chips

socket.on('register', function( newScreenName, callback ) {
    // If a new screen name is posted
    if( typeof newScreenName !== 'undefined' ) {
        var newScreenName = newScreenName.trim();
        // If the new screen name is not an empty string
        if( newScreenName && typeof players[socket.id] === 'undefined' ) {
            var nameExists = false;
            for( var i in players ) {
                if( players[i].public.name && players[i].public.name == newScreenName ) {
                    nameExists = true;
                    break;
                }
            }
            if( !nameExists ) {
                // Creating the player object
                players[socket.id] = new Player( socket, newScreenName, 25000 );
                callback( { 'success': true, screenName: newScreenName, totalChips: players[socket.id].chips } );
            } else {
                callback( { 'success': false, 'message': 'This name is taken' } );
            }
        } else {
            callback( { 'success': false, 'message': 'Please enter your name' } );
        }
    } else {
        callback( { 'success': false, 'message': '' } );
    }
});

I give out 25000 Chips at the start and a player can then joins rooms (win some, lose some chips). But refreshing the webpage resets it back to 25000.

In my Index.html here is the code to select a player name

<select class="screen-name-input" class="form-control" ng-model="newScreenName" ng-trim="true" required>
    <option>Name1</option>
    <option>Name2</option>
    <option>Name3</option>
    <option>Name4</option>
    <option>Name5</option>
    <option>Name6</option>
    <option>Name7</option>
</select>




Aucun commentaire:

Enregistrer un commentaire