-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSTextController.cpp
More file actions
50 lines (46 loc) · 1.53 KB
/
MSTextController.cpp
File metadata and controls
50 lines (46 loc) · 1.53 KB
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
//
// Created by c on 3/27/24.
//
#include <iostream>
#include <limits>
#include "MSTextController.h"
MSTextController::MSTextController(MinesweeperBoard &minesweeperboard, MSBoardTestView &player) : board(minesweeperboard), view(player){};
bool MSTextController::isOnBoard(int row, int col) const{
if(board.getFieldInfo(row, col)=='#') return false;
return true;
}
void MSTextController::play() const{
while(board.updateGameState()==RUNNING){
view.display();
int row, col;
do {
std::cout << "Enter field coordinates: ";
std::cin >> row >> col;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}while (!isOnBoard(row, col));
chooseAction(row, col);
}
view.display();
if(board.updateGameState()==FINISHED_LOSS) std::cout << "YOU LOSE" << std::endl;
else std::cout << "YOU WIN" << std::endl;
}
void MSTextController::chooseAction(int row, int col) const{
int choice;
std::cout << "What action you want to perform?" << std::endl;
std::cout << "1.Reveal field 2.Toggle flag" << std::endl;
std::cin >> choice;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
switch (choice){
case 1:
view.revealField(row, col);
break;
case 2:
board.toggleFlag(row, col);
break;
default:
std::cout << "Wrong choice, there is no such action" << std::endl;
break;
}
}