Help with getting started on a small C++ program

This is a discussion on Help with getting started on a small C++ program within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to design a small minesweeper game with 5 rows and 5 columns, user has 20 guesses ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Help with getting started on a small C++ program

    Hi, I am trying to design a small minesweeper game with 5 rows and 5 columns, user has 20 guesses and there is 10 mines.

    I have started the code - http://pastebin.com/rvnrNSTnNow I am trying to write the main code part but I am having trouble working out how to add in random mines via arrays.

    This is for my studies so I am just looking for help with getting started, not actual code. Any advice is appreciated.

    Thanks

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    Link is broken. Why don't you use the boards code tags?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    2
    Sorry, here is the basic code I have so far:

    Code:
    #include <iostream> //Includes the iostream#include <conio.h> //Includes conio.h
    using namespace std; //Uses namespace std
    
    
    int main() //start of main function
    
    
    {
        int row1[4]; int row2[4]; int row3[4]; int row4[4]; int row5[4]; //Row arrays (values)
        char ShowRow1[4]; char ShowRow2[4]; char ShowRow3[4]; char ShowRow4[4]; char ShowRow5[4]; // Row arrays (Display chars)
        int mineTotal = 10; // Total number of mines left on grid
        int guessTotal = 20; // Total amount of guesses available
        int guessCorrect = 0; // Total amount of correct guesses
        int guessIncorrect = 0; // Total amount of incorrect guesses
        int turnNumber = 1; // Shows the turn number
        int rowGuess, columnGuess; // Values for user guess (row and column)
        int user_option; // User option number
        
            
            cout << "Welcome to Minesweeper" << endl << "Please enter an option" << endl; // Displays welcome message
            cout << "1 - Play Game" << endl << "Press any other key to exit" << endl; // Displays options
            cin >> user_option; //User inputs choice
    
    
            if (user_option == 1) // Starts code if user enters "Play Game" - 1
            {
            
            // MINESWEEPER CODE GOES HERE
                    
            _getch();
    
    
            
            }
            else {return 0;} //Exits the game if any other key is entered other than 1
    
    
    }

  4. #4
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Code:
    int row1[4]; int row2[4]; int row3[4]; int row4[4]; int row5[4]; //Row arrays (values)
    This would be easier to work with as a 2-dimensional array, int row[ROWS][COLUMNS].

    I am having trouble working out how to add in random mines via arrays.
    Think about how you would randomly place mines on a real-life minesweeper board (if such a thing exists ).
    Consider this post signed

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    That code only has 4 columns. If you wanted 5 then you'd have to change those 4's to fives.
    But yeah, your approach is wrong. You don't declare an array for each row for the same reason that you don't declare a separate variable for each cell in that row. You need 2D arrays.

    After fixing that, start with the easy bits, for example write the function that displays the board, or the function that counts the number of surrounding cells that are mines.

    You really haven't done much at all, and you aren't going to get much help until you're a lot further on into the project. Make no mistake, we will not be writing he code for you. We help more in the design discussion and in the code review stages, but the bit in the middle is largely up to you, unless you have a very specific coding question.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bug in my barely-started text-based game program
    By linkofazeroth in forum C++ Programming
    Replies: 18
    Last Post: 08-30-2005, 02:32 AM
  2. Want to run .dll when a program is started
    By mayhem in forum Windows Programming
    Replies: 3
    Last Post: 06-24-2005, 09:18 AM
  3. Help Me Get Started On A program
    By rainmanddw in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2004, 06:05 PM
  4. Replies: 5
    Last Post: 06-15-2003, 12:20 PM
  5. A small problem with a small program
    By Wetling in forum C Programming
    Replies: 7
    Last Post: 03-25-2002, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21