Skip to content

Socket - #4

Open
mantinone wants to merge 8 commits into
masterfrom
socket
Open

Socket#4
mantinone wants to merge 8 commits into
masterfrom
socket

Conversation

@mantinone

Copy link
Copy Markdown
Collaborator

Made a few gameplay changes.

Implemented socket.io so multiple browsers and computers can access the server and send messages between each other.

Comment thread npm-debug.log
@@ -0,0 +1,19 @@
0 info it worked if it ends with ok

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be omitted from your repository (add *.log into your .gitignore file).

Comment thread empty/routes/users.js Outdated
res.redirect('/game')
}
else {
res.send('wrong password you, but')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want to encourage hackers to keep guessing - a simple failure (perhaps with a 401 response) is considered best practice.

Comment thread empty/app.js Outdated
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/game', express.static(path.join(__dirname, 'phaser')))
// app.use("/socket.io", express.static(path.join(__dirname, './node_modules/socket.io-client/dist')));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments.

Comment thread empty/app.js Outdated
module.exports = app;
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
// socket.on('ping', function (data) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments.

Comment thread empty/bin/www Outdated

const port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
// app.set('port', port);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments.

Comment thread empty/bin/www Outdated

const server = http.createServer(app);

// const server = http.createServer(app);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments.


//load jump sound
game.load.audio('jump', 'assets/jump.wav')
game.load.image('nyan', 'phaser/assets/NyanCat.png')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot going on in this file. Consider separating individual chunks of logic out - preload could be a function imported from another module, for example, so that the responsibility of this model is just to create the initial main state by importing and aggregating all the smaller pieces.

This particular function could also be cleaned up a little (and made a little easier to update):

const ASSETS = [ 
  { type: 'image', name: 'nyan', extension: 'png' }, 
  { type: 'image', name: 'bird', extension: 'png' }, 
  /* etc. */
  { type: 'audio', name: 'jump', extension: 'wav' } 
]

const preload = () => ASSETS.forEach( { type, name, extension } => 
  game.load( type, `phaser/assets/${name}.${extension}` )
)


// Call the 'jump' function when the spacekey is hit
const spaceKey = game.input.keyboard.addKey(
var spaceKey = game.input.keyboard.addKey(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var

// If the bird is out of the screen (too high or too low)
// Call the 'restartGame' function
if (sprite.y < 0 || sprite.y > 490)
if (sprite.y < 0 || sprite.y > 735)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider declaring all of these magic numbers as constants, with intention revealing names.

if (i != hole && i != hole + 1 && i != hole + 2)
this.addOnePipe(400, i * 60 + 10);
for (var i = 0; i < 12; i++)
if ((i != holeOne && i != holeOne + 1) && (i != holeTwo && i != holeTwo + 1))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!== is best practice, to avoid possible type coercion bugs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants