Minesweeper Dev C++
// this game is free for anyone. If you find this helpful, please, in gratitude help me when // i put my posts on go4expert thanks:) enjoy. // for more info read the manual of minesweeper in windows, its quite similar. // the mines placed in this game are randomly generated. // please modify the code anyway you wish and let me know of any bugs.:) // printmatrix is a function borrowed. I'm making a simplified minesweeper game using a 5x5 2D array. Part of my instruction was to make a function like this: This function takes a value between 1 and 25 and converts the value to row column locations. Little snitch disadvantages. You will need to use reference parameters to accomplish this. How can I accomplish this? Here is my code so far. Dec 17, 2011 game development c on December 17, 2011 The other day I was tutoring a freshman programmer program his first minesweeper text game in C. Here is the resulting code. Right now it doesn't do anything as far as I can tell. You have a void function that declares and changes a local variable called numMines, then never does anything with numMines.
I'm doing this minesweeper assignment and I need help. I tried to test the findMineValues() function and it completely scrambles up my board. Can someone help me pinpoint what I am doing wrong?
- 2 Contributors
- forum 5 Replies
- 914 Views
- 14 Hours Discussion Span
- commentLatest Postby DeadJusticeLatest Post
VernonDozier2,218
Please be more specific about what the problem is. What is this function supposed to do and what does 'it completely scrambles up my board' mean?
Right now it doesn't do anything as far as I can tell. You have a void function that declares and changes a local variable called numMines
, then never does anything with numMines
. You have a function call that DOES do something with numMines
, but it is commented out.
As a side note, on lines like this:
you can leave true
off and it'll be the same code.
Minesweeper In C
- {
- int theone;
- int extra2=0;
- char char2;
- char flag='n';
- int x;
- int count=30;
- srand (time(NULL));
- vector<char>cover;
- vector<int>waiter;
- vector<char>chars;
- for(int i=0;i<261;i++)
- waiter.push_back(0);
- mines.push_back(0);
- cover.push_back('+');
- cout<<'n';
- {
- y=x%260+1;
- if(mines[y]0)
- mines[y]=1;
- else
- i--;
- }
- {
- chars[i]='M';
- x=0;
- if(chars[1]!='M') //top left
- if(chars[2]'M')
- nums[1]++;
- if(chars[27]'M')
- nums[1]++;
- if(chars[28]'M')
- nums[1]++;
- }
- if(chars[26]!='M') //top right
- if(chars[25]'M')
- nums[26]++;
- if(chars[51]'M')
- nums[26]++;
- if(chars[52]'M')
- nums[26]++;
- }
- if(chars[235]!='M') //bottom left
- if(chars[209]'M')
- nums[235]++;
- if(chars[210]'M')
- nums[235]++;
- if(chars[236]'M')
- nums[235]++;
- }
- if(chars[260]!='M') //bottom right
- if(chars[233]'M')
- nums[260]++;
- if(chars[234]'M')
- nums[260]++;
- if(chars[259]'M')
- nums[260]++;
- }
- for(int i=2;i<26;i++) //top
- if(chars[i]!='M')
- if(chars[i-1]'M')
- if(chars[i+1]'M')
- if(chars[i+25]'M')
- if(chars[i+26]'M')
- if(chars[i+27]'M')
- }
- {
- {
- nums[i]++;
- nums[i]++;
- nums[i]++;
- nums[i]++;
- nums[i]++;
- }
- for(int i=26;i<210;i++) //left
- if(i%261&&chars[i]!='M')
- if(chars[i-26]'M')
- if(chars[i-25]'M')
- if(chars[i+1]'M')
- if(chars[i+26]'M')
- if(chars[i+27]'M')
- }
- {
- {
- nums[i]++;
- nums[i]++;
- nums[i]++;
- nums[i]++;
- nums[i]++;
- }
- for(int i=28;i<234;i++) //all else
- if(i%26!=0&&i%26!=1&&chars[i]!='M')
- if(chars[i-27]'M')
- if(chars[i-26]'M')
- if(chars[i-25]'M')
- if(chars[i-1]'M')
- if(chars[i+1]'M')
- if(chars[i+25]'M')
- if(chars[i+26]'M')
- if(chars[i+27]'M')
- }
- {
- chars[i]='1';
- chars[i]='2';
- chars[i]='3';
- chars[i]='4';
- chars[i]='5';
- chars[i]='6';
- chars[i]='7';
- chars[i]='8';
- while(1)
- cout<<'nnMines left: '<<count<<'nn a b c d e f g h i j k l m n o p q r s t u v w x y zn ---------------------------------------------------n 0 ';
- for(int i=0;i<260;i++)
- if(cover[i+1]'+')
- else
- if(i%2625&&num!=10)
- cout<<' '<<num-1<<'n '<<num<<' ';
- }
- }
- cout<<' 9n ---------------------------------------------------n a b c d e f g h i j k l m n o p q r s t u v w x y z';
- cout<<'nnChoose a space: ';
- if(char1'F')
- cin>>char3;
- char2=char3;
- count--;
- wait=1;
- extra1=1;
- extra1=2;
- extra1=3;
- extra1=4;
- extra1=5;
- extra1=6;
- extra1=7;
- extra1=8;
- extra1=9;
- extra1=10;
- extra1=11;
- extra1=12;
- extra1=13;
- extra1=14;
- extra1=15;
- extra1=16;
- extra1=17;
- extra1=18;
- extra1=19;
- extra1=20;
- extra1=21;
- extra1=22;
- extra1=23;
- extra1=24;
- extra1=25;
- extra1=26;
- if(char2'0')
- else if(char2'1')
- else if(char2'2')
- else if(char2'3')
- else if(char2'4')
- else if(char2'5')
- else if(char2'6')
- else if(char2'7')
- else if(char2'8')
- else if(char2'9')
- if(flag'y')
- chars[theone]='F';
- cover[theone]='-';
- waiter[wait]=theone;
- while(wait!=0&&flag'n')
- if(chars[theone]'0')
- if(theone1) //top left
- {
- waiter[wait]=2;
- cover[2]='-';
- {
- waiter[wait]=27;
- cover[27]='-';
- {
- waiter[wait]=28;
- cover[28]='-';
- if(theone26&&cover[26]'+') //top right
- if(nums[25]0&&cover[25]'+')
- wait++;
- }
- if(nums[51]0&&cover[51]'+')
- wait++;
- }
- if(nums[52]0&&cover[52]'+')
- wait++;
- }
- }
- {
- {
- waiter[wait]=209;
- cover[209]='-';
- if(nums[210]0&&cover[210]'+')
- wait++;
- }
- {
- waiter[wait]=236;
- cover[236]='-';
- }
- {
- {
- waiter[wait]=233;
- cover[233]='-';
- if(nums[234]0&&cover[234]'+')
- wait++;
- }
- {
- waiter[wait]=259;
- cover[259]='-';
- }
- {
- {
- {
- waiter[wait]=i-1;
- cover[i-1]='-';
- {
- waiter[wait]=i+1;
- cover[i+1]='-';
- {
- waiter[wait]=i+25;
- cover[i+25]='-';
- {
- waiter[wait]=i+26;
- cover[i+26]='-';
- {
- waiter[wait]=i+27;
- cover[i+27]='-';
- }
- for(int i=236;i<260;i++) //bottom
- if(theonei)
- if(nums[i-1]0&&cover[i-1]'+')
- wait++;
- }
- {
- waiter[wait]=i+1;
- cover[i+1]='-';
- if(nums[i-25]0&&cover[i-25]'+')
- wait++;
- }
- if(nums[i-26]0&&cover[i-26]'+')
- wait++;
- }
- if(nums[i-27]0&&cover[i-27]'+')
- wait++;
- }
- }
- for(int i=26;i<210;i++) //left
- if(i%261&&theonei)
- if(nums[i-26]0&&cover[i-26]'+')
- wait++;
- }
- if(nums[i-25]0&&cover[i-25]'+')
- wait++;
- }
- {
- waiter[wait]=i+1;
- cover[i+1]='-';
- {
- waiter[wait]=i+26;
- cover[i+26]='-';
- {
- waiter[wait]=i+27;
- cover[i+27]='-';
- }
- {
- {
- {
- waiter[wait]=i-27;
- cover[i-27]='-';
- {
- waiter[wait]=i-26;
- cover[i-26]='-';
- {
- waiter[wait]=i-1;
- cover[i-1]='-';
- {
- waiter[wait]=i+25;
- cover[i+25]='-';
- {
- waiter[wait]=i+26;
- cover[i+26]='-';
- }
- {
- {
- {
- waiter[wait]=i-27;
- cover[i-27]='-';
- {
- waiter[wait]=i-26;
- cover[i-26]='-';
- {
- waiter[wait]=i-25;
- cover[i-25]='-';
- {
- waiter[wait]=i-1;
- cover[i-1]='-';
- {
- waiter[wait]=i+1;
- cover[i+1]='-';
- {
- waiter[wait]=i+25;
- cover[i+25]='-';
- {
- waiter[wait]=i+26;
- cover[i+26]='-';
- {
- waiter[wait]=i+27;
- cover[i+27]='-';
- }
- }
- theone=waiter[wait];
- }
- }