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
|
#include<iostream>
#include<Windows.h>
#include<time.h>
#include <conio.h>
#include<fstream>
using namespace std;
int get_digit();
void goto_xy(int col, int row);
void hide_ans(int line);
void display_question_marks(int r); // r --> rows, t --- number of tries
int main()
{
srand(time(0));
int answer[4], col, guess[4] = {0}, i, rows = 17, tries = 1,Number,num;
hide_ans(rows);
// system("COLOR 02");
display_question_marks(rows);
col = 20;
while(tries <= 7)
{
for(i = 0; i <4; i++)
{
goto_xy(col, rows);
cin >> guess[i];
col = col + 5;
}
col = 20;
rows = rows - 2;
tries = tries + 1;
display_question_marks(rows);
}
cout<<"The answer is : "<<endl;
system("pause");
return 0;
}
void goto_xy(int c, int r) // Function moves cursor to correct column and row (screen)
{
COORD coord;
coord.X = c;
coord.Y = r;
//Use a built-in function that will use the "coord" coordinates and place the cursor
// at the requird location on the screen.
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
return;
}
int get_digit() // generates random digits 1 - 9
{
int num;
num = rand() % 8 + 1;
return(num);
}
void hide_ans(int line) // display title, hides the answer
{ // prints row numnbers line --> rows
int col, i, ro;
col = 20;
ro = 3;
goto_xy(25, 0);
cout << "**Master Mind**\n";
cout<<" Guess the correct number sequence to win!"<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3); //replace the number with a number for the color you want
for (i = 0; i < 4; i++)
{
goto_xy(col, ro);
cout << (char)219;
col = col + 5;
}
for(i = 1; i <= 7; i++) // prints number of attempts
{
goto_xy(15, line);
cout << i;
line = line - 2;
}
return;
}
void display_question_marks(int r)
{
int col, i, ro,guess;
col = 15;
ro = 17;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4); //replace the 0 with a number for the color you want
col = col + 5;
for(i = 0; i < 4; i++) // prints questions marks on current attempt
{
goto_xy(col, r);
cout << "?";
col = col + 5;
}
return;
}
|