Giter VIP home page Giter VIP logo

minesweeper's Introduction

MineSweeper

MineSweeper is a game where you are faced with the challenge to clear a mine field. A number of mines are hidden in the field.

Each turn the player can choose to mark a location - to indicate that he thinks there is a mine in that location - or he can boldly clear the location. Marking is always safe but if you clearing a location will result in a big explosion and a GAME OVER. Luckily its just a game so you can try again 😊

Our finished game will look like this:

1 2 3 4 5 6 7 8 9 A
1 1️⃣ 1️⃣ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
2 1️⃣ 1️⃣ 1️⃣ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
3 ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
4 ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
5 ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
6 ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
7 ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
8 ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
9 ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
A ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️ ⏹️
row col [mark]: 1 2 m

Skeleton

The code skeleton given contains the game loop already and displays a mock mine field with all *s.

It will repeatedly ask the player for input, and display the minefield again.

1 2 3 4 5 6 7 8 9 A
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
row col [mark]: 1 2 m

A lot of work still needs to be done! Let's get to it!

To run our game type following in the terminal:

python mines.py

Steps

  • step1 - interpret user input
  • step2 - add a minefield
  • step3 - clear fields
  • step4 - add initial mines
  • step5 - add game over
  • step6 - show mine counts
  • step7 - proper display
  • step8 - remaining + keep clearing

Step 1

In the first step we are going to implement interpreting the user input.

return input("row col [mark]: ")

When this code is executed is displays row col [mark]: wait for user input (finished with a return). This string is then returned from the function.

We expect the user to supply us with 2 or 3 components: the row, the column and some indication wether the user wants to dig or mark the spot.

For the row and column a coords constant is already supplied.

To do this we need to:

  • split the input on whitespace
  • convert the first 2 to an integer number (0 based index in the coords string)
  • if the player enters a 3rd part, we will interpret this mark instead of dig. This part should be converted to True or False

Hints

Click here You can either use `variablename.split(' ')` or import the `re` module to do a more fancy `re.split(r'\s+', variablename)`.

You can use coords.find('A') will return the 0 based index of the first occurence of A in the string, which is 10.

You can use destructuring to separate the results from the split over different variables row, col, *mark = splitresultarray.

Using stringpart.upper() will make interpeting the player input a bit more tolerant for when the player forgets to use capitals for the alphanumeric coordinates.

You can use bool(variable) to convert anything to

minesweeper's People

Contributors

jacco avatar

Watchers

 avatar

Forkers

jacco-tst

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.