Skip to content

Commit

Permalink
Added Factory Class For Generator (#18)
Browse files Browse the repository at this point in the history
* started factory

* started Generator

* Added Game To Game Environment Class

* Switched order of parameters in game constructor

now it matches the usual design pattern

* Made Game Factory go Off of Enum Values

Yay now we use enums and its all cool

* Added Map Generator Hard File + Printing Map

Now we can get an instance of either class and print it to the screen

* Added mvwprintw

* Fix playing view
  • Loading branch information
evanugarte authored and drofp committed May 4, 2019
1 parent 4686233 commit 2c20790
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 21 deletions.
5 changes: 3 additions & 2 deletions include/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <ncurses.h>
#include "map_generator_factory.h"
#include "settings_item.h"

using namespace std;

Expand All @@ -14,8 +15,8 @@ namespace roadrun
class Game
{
public:
Game(int height, int width, char player_icon);
void PlayGame();
Game(int width, int height, char player_icon);
void PlayGame(SettingsItem difficulty);

char GetPlayerIcon();
void SetPlayerIcon();
Expand Down
7 changes: 4 additions & 3 deletions include/game_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "settings_item.h"
#include "main_menu.h"
#include "settings_menu.h"
#include "game.h"

namespace roadrun
{
Expand All @@ -21,9 +22,9 @@ class GameEnvironment
SettingsItem difficulty;
MainMenu *main_menu;
SettingsMenu *settings_menu;
//Game game;
const int kHeight = 10;
const int kWidth = 20;
Game *game;
const int kMenuHeight = 10;
const int kMenuWidth = 20;
};
} // namespace roadrun
#endif
5 changes: 4 additions & 1 deletion include/map_generator_factory.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#ifndef MAP_GENERATOR_FACTORY_H_
#define MAP_GENERATOR_FACTORY_H_

#include <string>

#include "map_generator.h"
#include "map_generator_easy.h"
#include "map_generator_hard.h"
#include "settings_item.h"

namespace roadrun
{
class MapGeneratorFactory
{
public:
static MapGenerator* create();
static MapGenerator* create(SettingsItem difficulty);
};
} // namespace roadrun

Expand Down
14 changes: 7 additions & 7 deletions src/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

namespace roadrun
{
Game::Game(int height, int width, char player_icon)
Game::Game(int width, int height, char player_icon)
{
int starty = 0;
int startx = 0;
this->height = height;
this->width = width;

this->player_icon = player_icon;
player_locy = (starty + height) - 1;
player_locy = (starty + height) - 2;
player_locx = (startx + width) / 2;
player_deltax = 0;

// this->map_generator = MapGeneratorFactory::create();

initscr();
clear();
noecho();
Expand All @@ -31,9 +29,10 @@ Game::Game(int height, int width, char player_icon)
refresh();
}

void Game::PlayGame()
void Game::PlayGame(SettingsItem difficulty)
{
bool playing = true;
this->map_generator = MapGeneratorFactory::create(difficulty);

while (playing)
{
Expand All @@ -60,8 +59,9 @@ void Game::PlayGame()
void Game::PrintFrame(WINDOW *game_win, int player_locy, int player_locx)
{
wmove(game_win, player_locy, 0);
wclrtoeol(game_win);
// wclear(game_win);
// wclrtoeol(game_win);
wclear(game_win);
mvwprintw(game_win, 25, 25, "%s", map_generator->GenerateMap());
mvwprintw(game_win, 15, 15, "player loc x is %d", player_locx);
mvwprintw(game_win, player_locy, player_locx, "%c", player_icon);

Expand Down
12 changes: 8 additions & 4 deletions src/game_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ namespace roadrun
GameEnvironment::GameEnvironment()
{
difficulty = SettingsItem::kRegular;
main_menu = new MainMenu(kWidth, kHeight);
settings_menu = new SettingsMenu(kWidth, kHeight);
main_menu = new MainMenu(kMenuWidth, kMenuHeight);
settings_menu = new SettingsMenu(kMenuWidth, kMenuHeight);

const int kHeight = 40;
const int kWidth = 80;
game = new Game(kWidth, kHeight, '^');
}

GameEnvironment::~GameEnvironment()
Expand All @@ -25,11 +29,11 @@ namespace roadrun
if(meme == roadrun::MenuItem::kChooseDifficulty)
{
settings_menu->PrintMenu();
roadrun::SettingsItem meme = settings_menu->GetUserChoice();
difficulty = settings_menu->GetUserChoice();
}
else if (meme == roadrun::MenuItem::kStartGame)
{
// go don
game->PlayGame(difficulty);
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion src/main_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ namespace roadrun
RenderOptions(menu_win, highlight);
}
// mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1]);
clrtoeol();
// clrtoeol();
wclear(menu_win);
clear();
refresh();
wrefresh(menu_win);
endwin();
}

Expand Down
2 changes: 1 addition & 1 deletion src/map_generator_easy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace roadrun
{
char* MapGeneratorEasy::GenerateMap()
{
return "";
return "easy";
}
} // namespace roadrun
5 changes: 3 additions & 2 deletions src/map_generator_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace roadrun
{
MapGenerator* MapGeneratorFactory::create()
MapGenerator* MapGeneratorFactory::create(SettingsItem difficulty)
{
return new MapGeneratorEasy();
if (difficulty == SettingsItem::kRegular) return new MapGeneratorEasy();
else if (difficulty == SettingsItem::kLudicrous) return new MapGeneratorHard();
}
} // namespace roadrun
9 changes: 9 additions & 0 deletions src/map_generator_hard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "map_generator_hard.h"

namespace roadrun
{
char* MapGeneratorHard::GenerateMap()
{
return "hard";
}
} // namespace roadrun

0 comments on commit 2c20790

Please sign in to comment.