summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Prakt1/prg2p1/mastermind/main.cpp
blob: c981178be9dfb2bb02f9800bec25a7ee45fc86ae (plain)
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
#include <iostream>

#include <cstdlib>

#include <ctime>

#include "mastermind.h"



using std::cout;

using std::cin;

using std::endl;



const int MAXROUND=8;



void playRound(MastermindDigits&);



int main()

{

	int menuSel=0;

	int input=0;

	

	MastermindDigits game;

	

	srand(time(0));



	do {

		system ("cls");

		cout << "1: Spiel" << endl;

		cout << "2: Testmodus" << endl;

		cout << "Ende: beliebige Taste"<<endl;

		cin >> menuSel;

		switch (menuSel)

		{

		case 1 :

			{				

				game.makeDigitsToGuess();

				playRound(game);

				break;

			}

		case 2:

			{

				cout << "Please enter test values (1111 - 6666): ";

				cin >> input;

				MastermindDigits testGame(input);

				playRound(testGame);

				break;

			}

		default: menuSel=0;

		}

		

	} while (menuSel!=0);



	return 0;

}



void playRound(MastermindDigits& game)

{

	int tip;

	int won=0;

	int round=1;



	do {

		cout << endl << "Ihr Tip: ";

		cin >> tip;

		MastermindDigits user(tip);

		cout << "Position richtig: " << game.locationRight(user) << endl;

		cout << "Ansonsten richtig: " << game.locationWrong(user) << endl;

		if (game.locationRight(user)==4)

		{

			won=1;

			cout << endl << "Sie haben gewonnen!" << endl;

			system("pause");

		}

		round++;

	} while ((won==0) && (round <= MAXROUND));

}