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
|
#include <iostream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int ans1,ans2;
int q=0;
int w=0;
int u=0;
int x;
int y;
int n1,n2;
void bboard(char board[5][5]){//outputs screen board
cout<<" ------------"<<endl;
cout<<"| |1|2|3|4|5|";
//cout<<"1";
int linendernum=0;
for(int y=0;y<5;y++){ //loops that outputs the first board
cout<<endl;
cout<<" ------------"<<endl;
linendernum++;
cout<<"|";
cout<<linendernum;
cout<<"|";
for(int x=0;x<5;x++){
cout<<board[x][y];
cout<<"|";
}//2nd for loop bracket
}//for loop bracket
cout<<endl;
cout<<" ------------"<<endl;
}
void cboard(char mboard[5][5]){//outputs mboard
int linendernum2=0;
cout<<" ------------"<<endl;
cout<<"| |1|2|3|4|5|";
//cout<<"1";
for(int q=0;q<5;q++){ //loops that outputs the board with the dollars
cout<<endl;
cout<<" ------------"<<endl;
linendernum2++;
cout<<"|";
cout<<linendernum2;
cout<<"|";
for(int w=0;w<5;w++){
if(mboard[w][q]!='$'){
mboard[w][q]='#';
}
cout<<mboard[w][q];
cout<<"|";
}
}
cout<<endl;
cout<<" ------------"<<endl;
}
void randomizer(char mboard[5][5]){//the randomizer for gold
int gold=0;
int n1,n2;
while(gold<10){//-------------------------------------------------------------------------------end of the randomizer loop/beggining of the mboarsd loop
int n1=rand()%5;
int n2=rand()%5;
if(mboard[n1][n2]!='$'){
mboard[n1][n2]='$';
gold++;
}
}
}
void guessing(char board[5][5],char mboard[5][5]){
int win=0;
do{
cout<<"Enter first coordinate";
cin>>ans1;
cout<<"Second cord";
cin>>ans2;
if(mboard[ans1-1][ans2-1]=='$'){
board[ans1-1][ans2-1]='$';
cout<<"You gone one gold!"<<endl;
win++;
}
else{
board[ans1-1][ans2-1]=' ';
cout<<"Better luck next time....."<<endl;
}
bboard(board);
}while(win!=10);
}
int main(){
srand(time(NULL));
char board[5][5]={'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'};
char mboard[5][5];
cout<<"Hello, Welcome to TREASURE HUNT!!"<<endl;
bboard(board);
randomizer(mboard);
cboard(mboard);
guessing(board,mboard);
cout<<"Nice Job!";
return 0;
}
| |