Siemka, mam problem z przekazaniem wartości parametru introGameMode, mianowicie: chciałbym go przekazać z tej klasy
#include "IntroController.h"
#include "GameManager.h"
IntroController::IntroController(IntroView &v) : view(v)
{}
void IntroController::handleEvent(sf::Event &event) {
auto mouse_position = sf::Mouse::getPosition(view.getWindow());
auto translated_pos = view.getWindow().mapPixelToCoords(mouse_position);
//std::cout<<game_mode<<std::endl;
if(view.getRect_easy_mode().getGlobalBounds().contains(translated_pos)){
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
{
introGameMode = INTRO_EASY;
}
}
else if(view.getRect_normal_mode().getGlobalBounds().contains(translated_pos)){
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
{
introGameMode = INTRO_NORMAL;
}
}
else if(view.getRect_hard_mode().getGlobalBounds().contains(translated_pos)){
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
{
introGameMode = INTRO_HARD;
}
}
if(view.getRect_small_size().getGlobalBounds().contains(translated_pos)){
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
{
introSize = intro_small;
}
}
else if(view.getRect_normal_size().getGlobalBounds().contains(translated_pos)){
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
{
introSize = intro_normal;
}
}
else if(view.getRect_big_size().getGlobalBounds().contains(translated_pos)){
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
{
introSize = intro_big;
}
}
if(view.getRect().getGlobalBounds().contains(translated_pos)){
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
{
finished = true;
}
}
}
IntroSize IntroController::getIntroSize() const {
return introSize;
}
IntroGameMode IntroController::getIntroGameMode() {
return introGameMode;
}
do tego konstruktora :
Minesweeperboard::Minesweeperboard(int width, int high, IntroController &introController):introController(introController) {
srand(time(NULL));
game_status = RUNNING;
firstMove = true;
this ->width = width;
this ->high = high;
double amountsOfMines=0;
int row=0, column=0;
// for(int i=0; i<high; i++){//row = i
// for(int j=0; j<width; j++){//column = j
// board[i][j].hasMine = false;
// board[i][j].hasFlag = false;
// board[i][j].isRevealed = false;
//
// }
// }
// if(introController.getIntroSize()==intro_small){
// width=10;
// high=10;
// }
// if(introController.getIntroSize()==intro_normal){
// width=15;
// high=20;
// }
// if(introController.getIntroSize()==intro_big){
// width=20;
// high=30;
// }
if(introController.getIntroGameMode() == INTRO_EASY){
amountsOfMines = 0.1*width*high;
for(int i=0; i<amountsOfMines; i++){
row = rand()% high;
column = rand()% width;
board[row][column].hasMine = true;
}
}
if(introController.getIntroGameMode()==INTRO_NORMAL){
amountsOfMines = 0.2*width*high;
for(int i=0; i<amountsOfMines; i++){
row = rand()% high;
column = rand()% width;
board[row][column].hasMine = true;
}
}
if(introController.getIntroGameMode()==INTRO_HARD){
amountsOfMines = 0.3*width*high;
for(int i=0; i<amountsOfMines; i++){
row = rand()% high;
column = rand()% width;
board[row][column].hasMine = true;
}
}
void Minesweeperboard::debug_display() const {
for(int i=0; i<high; i++){
for(int j=0; j<width; j++){
if(board[i][j].hasMine) std::cout<<"[M";
else std::cout<<"[.";
if(board[i][j].isRevealed) std::cout<<"o";
else std::cout<<".";
if(board[i][j].hasFlag) std::cout<<"f]";
else std::cout<<".]";
}
std::cout<<std::endl;
}
}
dodam ze eventy działając poprawnie.
easyConfig()
żebyś to załapał.