Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <time.h>
- #include <windows.h>
- using namespace std;
- char k; int p=13; string z;
- vector<string> map(144, "");
- vector<string> bign{"0","1","2","3","4","5","6","7","8"};
- void init() {
- for( int i = 0 ; i < 144; i++ ){
- if( i <=11 || i >=131 || i %12 ==0 || i %12 == 11 ){
- map[i] = "W";
- }
- }
- int t = 0;
- int x = rand()%24;
- x++;
- while( t < x+1 ){
- int y = rand()%144;
- if( map[y] != "W" && y != p ){
- map[y] ="B";
- t++;
- }
- }
- }
- //□■B
- void draw() {
- system( "cls" );
- for( int i = 0 ; i < 144 ; i++ ){
- if( map[i] == "W" ){
- cout << "";
- }
- else if(i == p){
- cout << "□";
- }
- else if( map[i] == "B" && i == p ){
- cout << "□";
- }
- else if( map[i] == "B" ){
- cout << "■";
- }
- else if( map[i] == "b" ){
- cout << "B";
- }
- else if( map[i] == "M" || map[i] == "m" ){
- cout << "M";
- }
- else if( map[i] >= bign[0] && map[i] <= bign[8] ){
- cout << map[i];
- }
- else if( i != p ){
- cout << "■";
- }
- if(i % 12 == 11){
- cout<<'\n';
- }
- }
- }
- bool end(){
- for( int i = 0 ; i < 144 ; i++ ){
- if( map[i] == "B" ){
- return false;
- }
- }
- return true;
- }
- int counter( int p ){
- int a = 0;
- if( map[p-13] == "B" || map[p-13] == "m" ){
- a++;
- }
- if( map[p-12] == "B" || map[p-12] == "m" ){
- a++;
- }
- if( map[p-11] == "B" || map[p-11] == "m" ){
- a++;
- }
- if( map[p-1] == "B" || map[p-1] == "m" ){
- a++;
- }
- if( map[p+1] == "B" || map[p+1] == "m" ){
- a++;
- }
- if( map[p+11] == "B" || map[p+11] == "m" ){
- a++;
- }
- if( map[p+12] == "B" || map[p+12] == "m" ){
- a++;
- }
- if( map[p+13] == "B" || map[p+13] == "m" ){
- a++;
- }
- map[p] = bign[a];
- return a;
- }
- void dis( int p ){
- int count[8] = { -13 , -12 , -11 , -1 , 1 , 11 , 12 , 13 };
- if( counter( p ) == 0 ){
- for(int i = 0 ; i < 8 ; i++ ){
- if( map[p+count[i]] == "" ){
- if( counter( p+count[i] ) !=0 ){
- map[p+count[i]] = bign[counter(p+count[i])];
- }
- else{
- dis( p+count[i] );
- }
- }
- }
- }
- }
- int main() {
- string a,b; //string資料型態可包含文數字組合
- srand( time(NULL) );
- init();
- draw();
- while (1) {
- if( kbhit() ){
- k = _getch();
- if( k == 'q' ){
- break;
- }
- else if( k == 'w' && map[p-12] != "W" ){
- p -= 12;
- }
- else if( k == 's' && map[p+12] != "W" ){
- p += 12;
- }
- else if( k == 'a' && map[p-1] != "W" ){
- p -= 1;
- }
- else if( k == 'd' && map[p+1] != "W" ){
- p +=1;
- }
- else if( k =='c' ){
- if( map[p] == "B" ){
- for( int i = 0 ; i < 144 ; i++ ){
- if( map[i] == "B" ){
- map[i] = "b";
- }
- }
- draw();
- cout << "boom!!!\nGame Over!";
- break;
- }
- dis( p );
- }
- else if( k == 'm' ){
- if( map[p] == "M" ){
- map[p] = "";
- }
- else if( map[p] == "B" ){
- map[p] = "m";
- }
- else if( map[p] =="m" ){
- map[p] = "B";
- }
- else{
- map[p] = "M";
- }
- }
- }
- draw();
- Sleep(300);
- if( end() ){
- draw();
- cout<<"Congratulations!!!\nYou Win!";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement