Coding Challenge #71: Minesweeper

46
25



In this challenge, I attempt to code the classic game Minesweeper in JavaScript with the p5.js library. This video builds on some previous tutorials related to the Prototypes and multi-dimensional arrays in JavaScript.

💻Challenge:
💻Editor:

Links discussed in this video:
🔗Minesweeper:
🔗Minesweeper suggestion:
🔗Flood fill:

🎥 2D Arrays in JavaScript:
🎥 Prototypes in JavaScript:

🚂Website:
💡Github:
💖Membership:
🛒Store:
📚Books:
🖋️Twitter:
Video editing by Mathieu Blanchette.

🎥Coding Challenges:
🎥Intro to Programming:

🔗 p5.js:
🔗 Processing:

📄 Code of Conduct:
🌐Help us caption and translate:
🚩Suggest Topics:
👾Share your contribution:

Nguồn: https://baovnexpress.com

Xem thêm bài viết khác: https://baovnexpress.com/cong-nghe

46 COMMENTS

  1. easy to make it so you dont spawn a bee within a distance from the first click, just generate the whole map on the first click

  2. One Thing That I Think Is Amazing About Daniel Is, Even Though His Fanbase Praises Him, His Ego Remains And His Head Is'nt The Size Of Earth

  3. I'm half-way through the video, and if I got this right, I'm realizing that you're going to check for the number of neighbouring bees for a cell each and every time you click on a cell. Wouldn't it be easier or more optimized to have simply stored the number in each cell at bee-creation time? So, like you said, if we use -1 to symbolize a bee and 0 for an empty cell, then when we create a bee, we simply increment +1 each neighbour cell that isn't a bee (cell.content>-1). All that's missing is an exception check for the boundaries of the grid as to not increment non-existing elements of the array (our of bounds). By the end of the bee creation process at setup stage, each remainder cell that isn't a bee should have the exact number stored in itself, which is then child's play to fetch at will, is it not? Or, since in theory we only click on each cell only once, does this get to be totally equivalent in terms of code volume and processing steps?

  4. The floodfill algorithm should terminate in purely x or y directions (not diagonals), simple refactor – exclude corners from neighbour check.

  5. I used minesweeper to teach myself JavaScript over 20 years ago. The other day I updated to get it to work on the latest browsers again.

    You can check it out here:
    https://cdn.rawgit.com/henkkruger/minesweeper/139b8dac/index.html

  6. I tried to fix my problem while making the check neighbors things for like an hour and was unsuccessful, and you just figured it out on the fly, it's just amazing, I'm only watching to the part I haven't done or tried but failed at doing

  7. I like the idea that you make mistake on purpose so students will learn, but in my opinion you should also educate to read the docs like in the scenario of the "splice" function.
    Keep up we love your content.

  8. right at the start i notice that you can die in one click
    i thought minesweeper generates the field once you click somewhere, so whereever you click first will never have a mine below it

  9. instead of the contains function you could have wrote in mousePressed
    grid[ floor ( mouseX / w ) ] [ floor( mouseY / w ) ].revealed = true;

  10. I coded this myself and added a concept of shield to the game.. looked online to see how others coded the game. Was not disappointed

LEAVE A REPLY

Please enter your comment!
Please enter your name here