C++
for this exercise, you will make a simple Dungeon Crawl game. For an enhanced version, you can add monsters that randomly move around.
Program Requirements
While the program is an introduction to two-dimensional arrays, it is also a review of functions and input validation.
check:
Does the program compile and properly run?
does all functions have prototypes?
Are all functions commented? Is the program itself commented?
Are constants used where appropriate?
Are the required functions implemented?
Is the dungeon array properly passed where necessary?
Is the dungeon properly created with random traps and treasure?
Does the display function properly display the dungeon?
Does the get move function check for inbounds before accepting an input?
Does the check move function properly check for a move onto a trap or treasure?
Does the update dungeon function properly update the dungeon?
make a program that displays a simple dungeon and allows the player to explore it. For example, in the following example G is the player, T is a trap, and X is the treasure. If you hit a trap, you fail. If you reach the treasure you win.
.......... .G........ ......T... .......... ....T..... ......T... .........X
For each move in the game, the user will enter a character for Left, Right, Up, or Down. You need to move the player accordingly and update the dungeon.
Define the size of your dungeon with a constant MAX_SIZE. Then create the dungeon as a MAX_SIZE x MAX_SIZE 2D array.
The functions you need to implement are:
Enhancements
For a more advanced version, add several monsters that randomly move one step in any direction each term. They must not go outside the limits of the dungeon. If the player moves onto an occupied square, she loses.
Your program could also ask the user if they want to play another game and repeat if the response is y.
Programming Suggestions
You should define the board in main and pass it to each of the functions that should access it. Note that when you are passing it, you will be passing it using its address and changes made to the board in a function change the board everywhere.
To pass a 2d array, you need to use something like the following:
void showBoard(char theBoard[][MAX_SIZE])
or
void showBoard(char theBoard[MAX_SIZE][MAX_SIZE])
///////////////////// game with no monster
#include<iostream>
#include<cstdlib>
#include<time.h>
#define MAX_SIZE 8
using namespace std;
char board[MAX_SIZE][MAX_SIZE];
int xP=-1,yP=-1;
int xT=-1,yT=-1;
void createDungeon(char player,int numberOfTrap,char
treasure){
// initialise
for(int i=0;i<MAX_SIZE;i++){
for(int
j=0;j<MAX_SIZE;j++){
board[i][j]='.';
}
}
// random player placed on board
int a=rand()%MAX_SIZE;
int b=rand()%MAX_SIZE;
board[a][b]=player;
xP=a;yP=b;
// random trap placed on board
for(int i=1;i<=numberOfTrap;i++){
while(true){
a=rand()%MAX_SIZE;
b=rand()%MAX_SIZE;
if(board[a][b]=='.'){
board[a][b]='T';
break;
}
}
}
// random treasure placed on board
while(true){
a=rand()%MAX_SIZE;
b=rand()%MAX_SIZE;
if(board[a][b]=='.'){
board[a][b]=treasure;
xT=a;yT=b;
break;
}
}
}
// display board
void showBoard(char theBoard[MAX_SIZE][MAX_SIZE]){
for(int i=0;i<MAX_SIZE;i++){
for(int
j=0;j<MAX_SIZE;j++){
cout<<theBoard[j][i]<<" ";
}
cout<<endl;
}
}
// check user move
bool checkMove(int x,int y,char m,char t){
bool ret=false;
// for left
if(m=='L'){
x--;
if(x>=0){
ret=true;
}
}
// for right
if(m=='R'){
x++;
if(x<MAX_SIZE){
ret=true;
}
}
// for down
if(m=='D'){
y++;
if(y<MAX_SIZE){
ret=true;
}
}
// for up
if(m=='U'){
y--;
if(y>=0){
ret=true;
}
}
// board update possible by new move
if(ret==true){
if(board[x][y]=='.' ||
board[x][y]==t){
ret==true;
}
else{
ret=false;
}
}
return ret;
}
// user move
char getMove(int x,int y,char t){
char ret=' ';
bool b=false;
char m=' ';
while(true){
cout<<"\n L (Left)";
cout<<"\n R (Right)";
cout<<"\n U (Upper)";
cout<<"\n D (Down)";
cout<<"\nEnter Your Move :
";
cin>>m;
// for valid move
if(m=='L' || m=='R' || m=='U' ||
m=='D'){
b=checkMove(x,y,m,t);
if(b==false){
cout<<"\nWrong Move , Please enter correct
move.";
}
else{
ret=m;
break;
}
}
// invalid user move
else{
cout<<"\nInvalid move \n";
}
}
return ret;
}
// user move update in board
void updateDungeon(int x,int y,char player,char m){
board[x][y]='.';
if(m=='L'){
x--;
}
if(m=='R'){
x++;
}
if(m=='D'){
y++;
}
if(m=='U'){
y--;
}
// place player
board[x][y]=player;
// update new move
xP=x;yP=y;
}
// main function
int main(){
srand(time(0));
createDungeon('G',8,'X');
while(true){
showBoard(board);
char m=getMove(xP,yP,'X');
updateDungeon(xP,yP,'G',m);
cout<<endl<<endl;
if(xP==xT && yP==yT){
cout<<"\n******^^^^^^******\n";
showBoard(board);
cout<<"\n\nYou got Treasure.";
cout<<"\nWant to play again [y/n]";
char
again;
cin>>again;
if(again=='Y' ||
again=='y'){
createDungeon('G',8,'X');
}
else{
break;
}
}
}
cout<<"\nGAME OVER";
return(0);
}




/////////////////////////////////////////////////////////////////////////
////////////// game with Monster
#include<iostream>
#include<cstdlib>
#include<time.h>
#define MAX_SIZE 8
using namespace std;
char board[MAX_SIZE][MAX_SIZE];
int xP=-1,yP=-1;
int xT=-1,yT=-1;
int xM[MAX_SIZE],yM[MAX_SIZE];
void createDungeon(char player,int numberOfTrap,char treasure,int
monstarNo){
// initialise
for(int i=0;i<MAX_SIZE;i++){
for(int
j=0;j<MAX_SIZE;j++){
board[i][j]='.';
}
}
// random player placed on board
int a=rand()%MAX_SIZE;
int b=rand()%MAX_SIZE;
board[a][b]=player;
xP=a;yP=b;
// random trap placed on board
for(int i=1;i<=numberOfTrap;i++){
while(true){
a=rand()%MAX_SIZE;
b=rand()%MAX_SIZE;
if(board[a][b]=='.'){
board[a][b]='T';
break;
}
}
}
// random treasure placed on board
while(true){
a=rand()%MAX_SIZE;
b=rand()%MAX_SIZE;
if(board[a][b]=='.'){
board[a][b]=treasure;
xT=a;yT=b;
break;
}
}
// random moster placed on board
for(int i=1;i<=monstarNo;i++){
while(true){
a=rand()%MAX_SIZE;
b=rand()%MAX_SIZE;
if(board[a][b]=='.'){
board[a][b]='M';
xM[i-1]=a;
yM[i-1]=b;
break;
}
}
}
}
// display board
void showBoard(char theBoard[MAX_SIZE][MAX_SIZE]){
for(int i=0;i<MAX_SIZE;i++){
for(int
j=0;j<MAX_SIZE;j++){
cout<<theBoard[j][i]<<" ";
}
cout<<endl;
}
}
// check user move
bool checkMove(int x,int y,char m,char t){
bool ret=false;
// for left
if(m=='L'){
x--;
if(x>=0){
ret=true;
}
}
// for right
if(m=='R'){
x++;
if(x<MAX_SIZE){
ret=true;
}
}
// for down
if(m=='D'){
y++;
if(y<MAX_SIZE){
ret=true;
}
}
// for up
if(m=='U'){
y--;
if(y>=0){
ret=true;
}
}
// board update possible by new move
if(ret==true){
if(board[x][y]=='.' ||
board[x][y]==t){
ret==true;
}
else{
ret=false;
}
}
return ret;
}
// random direction
char rDirection(){
char ret=' ';
int r=rand()%4;
if(r==0){ret='L';}
if(r==1){ret='R';}
if(r==2){ret='U';}
if(r==4){ret='D';}
return(ret);
}
// monster move
bool updateMosterMove(int _n,char p){
for(int i=0;i<_n;i++){
char ch=rDirection();
bool
b=checkMove(xM[i],yM[i],ch,p);
if(b==true){
board[xM[i]][yM[i]]='.';
if(ch=='L'){xM[i]--;}
if(ch=='R'){xM[i]++;}
if(ch=='U'){yM[i]--;}
if(ch=='D'){yM[i]++;}
board[xM[i]][yM[i]]='M';
}
}
}
// user move
char getMove(int x,int y,char t){
char ret=' ';
bool b=false;
char m=' ';
while(true){
cout<<"\n L (Left)";
cout<<"\n R (Right)";
cout<<"\n U (Upper)";
cout<<"\n D (Down)";
cout<<"\nEnter Your Move :
";
cin>>m;
// for valid move
if(m=='L' || m=='R' || m=='U' ||
m=='D'){
b=checkMove(x,y,m,t);
if(b==false){
cout<<"\nWrong Move , Please enter correct
move.";
}
else{
ret=m;
break;
}
}
// invalid user move
else{
cout<<"\nInvalid move \n";
}
}
return ret;
}
// user move update in board
void updateDungeon(int x,int y,char player,char m){
board[x][y]='.';
if(m=='L'){
x--;
}
if(m=='R'){
x++;
}
if(m=='D'){
y++;
}
if(m=='U'){
y--;
}
// place player
board[x][y]=player;
// update new move
xP=x;yP=y;
}
// check monster eat player
bool check(int _n){
bool ret=false;
for(int i=0;i<_n;i++){
if(xM[i]==xP &&
yM[i]==yP){
ret=true;
break;
}
}
return ret;
}
// main function
int main(){
srand(time(0));
createDungeon('G',8,'X',4);
while(true){
showBoard(board);
char m=getMove(xP,yP,'X');
updateDungeon(xP,yP,'G',m);
cout<<endl<<endl;
updateMosterMove(4,'G');
bool b=check(4);
if(b==true){
cout<<"\n\nYou lost game .\n";
showBoard(board);
cout<<"\nWant to play again [y/n]";
char
again;
cin>>again;
if(again=='Y' ||
again=='y'){
createDungeon('G',8,'X',4);
}
else{
break;
}
}
else{
if(xP==xT
&& yP==yT){
cout<<"\n******^^^^^^******\n";
showBoard(board);
cout<<"\n\nYou got Treasure.";
cout<<"\nWant to play again [y/n]";
char again;
cin>>again;
if(again=='Y' || again=='y'){
createDungeon('G',8,'X',4);
}
else{
break;
}
}
}
}
cout<<"\nGAME OVER";
return(0);
}





C++ for this exercise, you will make a simple Dungeon Crawl game. For an enhanced version,...
C++ Project - Create a memory game in c++ using structs and pointers. For this exercise, you will create a simple version of the Memory Game. You will again be working with multiple functions and arrays. You will be using pointers for your arrays and you must use a struct to store the move and pass it to functions as needed. Program Design You may want to create two different 4x4 arrays. One to store the symbols the player is...
Write a c program that will allow two users to play a tic-tac-toe game. You should write the program such that two people can play the game without any special instructions. (assue they know how to play the game). Prompt first player(X) to enter their first move. .Then draw the gameboard showing the move. .Prompt the second player(O) to enter their first move. . Then draw the gameboard showing both moves. And so on...through 9 moves. You will need to:...
Objective: To write a program to allow a game of Tic Tac Toe to be played, and to determine when the game is over Complete the TicTacToe program below. It will allow for a full game of Tic Tac Toe between two players, and it will tell you who won or if the game is over with no winner. Details: The TicTacToe board is stored in a 3x3 multidimensional list of characters containing spaces at the start of the game...
Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user to enter...
write a program for python 3 write the functions that could be used in an implementation of the game tic-tac-toe. Below are the definitions of the different functions. The code to test each function is currently in the main() of the lab10.py file. • A function to build the board. This method should create a list of the numbers 1 – 9 and return that list. build_board () -> list • A void function to display the board. (see the...
To decide your fate, you will play a board game on a simple board: a linear track with 16 sequential spaces numbered from 1 to 15. The “zero” space is marked “Start,” and your token is placed on it. The jailer has one silver coin and places it on a random numbered space. The jailer then gives you a gold coin, and you are allowed to place it on any numbered space that you want except that the coins must...
First step is to draw a structure chart to help you understand
the decomposition of functions for this program. Remember to start
with the overall problem and break it down into inputs,
computations, and outputs. One possible functional decomposition
includes the following (Note: you are NOT required to apply
these functions in your program!):
Create
a function welcome_screen() that displays an initial program
welcome message along with the rules of Battleship.
Create
a function initialize_game_board() that sets each cell in...
can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...
C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...
You will create a PYTHON program for Tic-Tac-Toe game. Tic-Tac-Toe is normally played with two people. One player is X and the other player is O. Players take turns placing their X or O. If a player gets three of his/her marks on the board in a row, column, or diagonal, he/she wins. When the board fills up with neither player winning, the game ends in a draw 1) Player 1 VS Player 2: Two players are playing the game...