Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Creating minesweeper  (Read 2731 times)

0 Members and 1 Guest are viewing this topic.

TeaBag

  • Newbie
  • *
  • Posts: 5
    • View Profile
Creating minesweeper
« on: September 27, 2013, 09:37:00 pm »
I want to create a simple Minesweeper game with SFML. The main problem is I can't decide how to make mine grid.
I have a few ideas how to make a grid, but none of them seem efficient to me. Can somebody tell me how should I deal with this problem the right way?

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Creating minesweeper
« Reply #1 on: September 27, 2013, 10:42:43 pm »
the grid? just draw some lines across the screen  :o
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Creating minesweeper
« Reply #2 on: September 27, 2013, 11:05:14 pm »
Due to the vagueness of the question I can only give a very vague answer: Use basic OOP design and make each square an instance of a class.  Have another class represent the grid which contains some number of those squares.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Creating minesweeper
« Reply #3 on: September 27, 2013, 11:48:38 pm »
Well you could for instance use a class, which derives from sf::Drawable and a has a sprite as a member. Then you get a std::vector of your class and fill it with instance of your class, which get initialized to a certain position. Now you add a function to your class that will change the cell's state (covered, empty, number, mine) which moves the texture rect to the correct position. Tada you got a nice grid which you can easily change the state. You now only have to determine where the user clicks and react to it accordingly. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything