Random Minefield generating c++
Page 1 of 1
Steve-O 2004




Posts: 2851

PostPosted: Sun, 29th Apr 2012 18:46    Post subject: Random Minefield generating c++
Trying to finish off my Minesweeper game and so far all I need to do is make the array random which Im finding hard. So far I have -

Code:
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <string> 
#include <cmath>
#include <stdio.h>
#include <crtdbg.h>
#include <limits>
#include <iomanip>
using namespace std;   

int main()
{
   int mines=0;
 int boardm[16][16];
 srand((unsigned)time(0));
 
 
   for(int X=0; X<16; X++){
   for(int Y=0; Y<16; Y++){
        boardm[X][Y] = (rand ()%6);
      if (boardm[X][Y] == 0)
         boardm[X][Y] = -1;
      if (boardm[X][Y] == -1)
         mines++;
      if (boardm[X][Y] != -1)
         boardm[X][Y] =0;
   
          cout << boardm[X][Y] << endl;
      
 } 
 }
   
cout << "There is "  << mines << " Mines\n\n";
{
   for(int X=0; X<16; X++){
   for(int Y=0; Y<16; Y++){
      if (boardm[X][Y] == -1)
      {boardm[X+1][Y] ++;
      boardm[X+1][Y+1] ++;
      boardm[X+1][Y-1] ++;
      boardm[X-1][Y] ++;
      boardm[X-1][Y+1] ++;
      boardm[X-1][Y-1] ++;}

   cout << boardm[X][Y];
   }}
}

}


But I get a runtime error, Im guessing i have done it completely wrong... Any ideas ?

Thanks


George W Bush -

'...more and more of our imports are coming from overseas.'
Back to top
garus
VIP Member



Posts: 34197

PostPosted: Sun, 29th Apr 2012 18:49    Post subject:
snip


Last edited by garus on Tue, 27th Aug 2024 21:29; edited 1 time in total
Back to top
Steve-O 2004




Posts: 2851

PostPosted: Sun, 29th Apr 2012 22:38    Post subject:
lol, I think learning HTML, XML / XSL, CSS, some PHP and C++ at once is quite abit to take in but getting there


George W Bush -

'...more and more of our imports are coming from overseas.'
Back to top
Steve-O 2004




Posts: 2851

PostPosted: Mon, 30th Apr 2012 16:42    Post subject:
its all done and working now Very Happy Very Happy Very Happy Very Happy Very Happy Happy days but messy code lol


George W Bush -

'...more and more of our imports are coming from overseas.'
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group