1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// some includes required
// global scope
bool quit = false;
bool playing = false;
enum {dig='d', flag='f'};
char operation;
int column;
int row;
enum { square=178, mine=153, flag=214, rowline=179, space=' ' };
int columns;
int rows;
char* map;
void input()
{
do
{
// didn't look at your code but i think this should be here
cout<<endl<<setw(6)<<"Score = "<<score<<endl<<endl;
cout<<setw(6)<<"Guesses = "<<guesses<<endl<<endl;
cout << "Please enter the Vertical number (1 - " << col << ')' << endl;
cin >> col; // enter col from 1 to columns
--col;
cout << "Now enter the Horizontal number (1 - " << rows << ')' << endl;
cin >> row; // enter col from 1 to rows
--row;
if(!(col < columns && row < rows))
std::cout << "please enter valid data" << std::endl;
else
break;
} while(true);
do
{
cout << "Do you want to dig(d) or flag for a bomb here(f)?" << endl;
operation = getchar();
} while(operation != dig && operation != flag)
}
void update()
{
// you know the row and colum that is being opened next
// do whatever needs to be done! :D
// you need to do something when loosing to reset the playing boolean
}
void render()
{
// render the current field :)
}
// NOTE: still need to implement the mines
void set_game(int row_cnt, int col_cnt, int mines)
{
// set map data
rows = row_cnt;
columns = col_cnt;
// initialize map data
map = new int[rows * columns];
memset(map, square, rows*columns*sizeof(char)); // set data to default
// let's play!
playing = true;
}
void leader()
{
}
void help()
{
}
void new_game()
{
do
{
char option;
cout<<setw(50)<<"Welcome to MINESWEEPER"<<endl<<endl;
cout<<setw(40)<<"Main Menu"<<endl<<endl<<endl;
cout<<setw(10)<< "Please Choose Your Difficulty Level"<<endl<<endl;
cout<<setw(10)<<"1. Beginner - Grid is (8x8) with 10 mines"<<endl<<endl;
cout<<setw(10)<<"2. Intermidiate - Grid is (16x16) with 40 mines"<<endl<<endl;
cout<<setw(9)<<"3. Expert - Grid is (24x24) with 99 mines"<<endl<<endl;
cout<<setw(10)<<"4. Leader Board"<<endl<<endl;
cout<<setw(10)<<"5. How to Play Minesweeper."<<endl<<endl<<endl;
cout<<setw(10)<<"Press Q to quit the game back to windows"<<endl;
cout<<endl<<endl<<endl<<endl<<endl<<"by Scott Brooks& F'n' A Games"<<endl<<endl;
cin>>option;
cout<<endl;
cin.ignore();
switch(option)
{
case '1': set_game(8, 8, 10);
break;
case '2': set_game(16, 16, 40);
break;
case '3': set_game(24, 24, 99);
break;
case '4': leader();
break;
case '5': help();
break;
case 'Q':
quit = true;
playing = false;
break;
default:
cout<<"Please Enter 1, 2, 3, 4, 5 or Q"<<endl;
}
} while(playing != true && quit != false);
}
void init()
{
// load media (not needed, your's is text-based)
// start screen (not needed, you allways ask when a new game is played)
// set random seeds
srand(time(0));
}
int main(void)
{
init(); // initializes the game
while(!quit)
{
new_game();
while(playing)
{
input();
update();
render();
}
}
}
|