For this final assignment, you are required to create a solution, as a team (you
ID: 3826002 • Letter: F
Question
For this final assignment, you are required to create a solution, as a team (you may have a team of up to 4 members), to a game or graphical application of your choice! Some game possibilities are listed below:
Chess
Texas Hold 'em
Battleship
Checkers
Others?
Your goal for the assignment is build a complete graphical, and possibly networked, game or application. As a team you must ultimately decide how you will implement graphics. You have many tools and library options available to implement the graphics portion of the assignment. Some include the Unreal Engine, SFML, Qt, SDL, Allegro, DirectX, OpenGL, etc. Please be sure to also add some directions of how to play the game or use your application.
Aside from the requirements listed in the above paragraph, you are free to complete this assignment as you see fit. During our normally scheduled class period on Wednesday, April 26, we will have a Gamefest! At which point you will need to allow other students in the class play your game or use your application.
Have fun with this assignment!
please lebel the file like main.ccp, use graphic user interface, and use C++ only.
Thank you very much in advance
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
//enum declaration
enum destroy {w_unbomb, w_bomb,
s_unbomb , s_bomb};
const char view[] = {'-', 'O', '-', 'X'};
//size
const int size = 15;
//holds the value of the grid
destroy mat[size];
//function prototypes
void placebomb(int axis);
void runprocess(char stp);
void initmat();
bool exitgame();
void display();
//main method
int main() {
srand(time(0));
char val;
do {
initmat();
display();
char cmdline;
while (cin >> cmdline) {
runprocess(cmdline);
if (exitgame()) {
cout << "you won!!!!!" << endl;
break;
}
}
cout << "want to play again press? (y/n) ";
val = 'n';
cin >> val;
} while (val == 'y');
return 0;
}
//run commands
void runprocess(char stp) {
switch (stp) {
case 'q':
exit(0);
break;
case 'b':
int pos;
cin >> pos;
if (pos>=0 && pos<size) {
placebomb(pos);
} else {
cout << " bombing values range must be between 0 and " << size-1 << endl;
}
display();
break;
default:
cerr << "Invalid!!! " << stp << endl;
break;
}
}
//drop bomb at particular axis
void placebomb(int axis) {
switch (mat[axis]) {
case w_unbomb:
mat[axis] = w_bomb;
break;
case s_unbomb:
mat[axis] = s_bomb;
break;
}
return;
}
//initialize the grid values
void initmat() {
for (int i=0; i<size; i++) { // clear mat
mat[i] = w_unbomb;
}
int begin = rand() % (size-4); // Place a 3-cell ship in mat.
mat[begin+0] = s_unbomb;
mat[begin+1] = s_unbomb;
mat[begin+2] = s_unbomb;
}
//displays the grid
void display() {
cout << endl;
for (int i=0; i<size; i++) {
cout << " " << view[mat[i]];
}
cout << endl;
for (int axis=0; axis<size; axis++) {
cout << setw(2) << axis;
}
cout << endl << endl;
}
//game over condition
bool exitgame() {
for (int axis=0; axis<size; axis++) {
if (mat[axis] == s_unbomb) {
return false;
}
}
return true;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
- - - - - - - - - - - - - - -
0 1 2 3 4 5 6 7 8 91011121314
b0
O - - - - - - - - - - - - - -
0 1 2 3 4 5 6 7 8 91011121314
b1
O O - - - - - - - - - - - - -
0 1 2 3 4 5 6 7 8 91011121314
b14
O O - - - - - - - - - - - - O
0 1 2 3 4 5 6 7 8 91011121314
b5
O O - - - X - - - - - - - - O
0 1 2 3 4 5 6 7 8 91011121314
b6
O O - - - X X - - - - - - - O
0 1 2 3 4 5 6 7 8 91011121314
b2
O O O - - X X - - - - - - - O
0 1 2 3 4 5 6 7 8 91011121314
b7
O O O - - X X X - - - - - - O
0 1 2 3 4 5 6 7 8 91011121314
you won!!!!!
want to play again press? (y/n) n
sh-4.2$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.