Skip to content

Commit

Permalink
add some draw method for Map class
Browse files Browse the repository at this point in the history
  • Loading branch information
linkliu committed Aug 8, 2024
1 parent 5b58adf commit 71cbfb8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
6 changes: 0 additions & 6 deletions debug_tool.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#include "debug_tool.h"
#include "map.h"
#include "mnode.h"
#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <curses.h>
#include <iostream>
#include <thread>
#include <utility>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
void print_map(Map &tMap)
{
for (int firdex = 0; firdex < tMap.GetMapRow(); firdex++)
Expand Down
2 changes: 1 addition & 1 deletion dijstra_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DIJAlgorithm : public Algorithm
DIJAlgorithm() = default;
DIJAlgorithm(Map& _map):Algorithm(_map){}
DIJAlgorithm(Map& _map, MNode& _start, MNode& _end):Algorithm(_map, _start, _end){}
map<int, map> Resolve() override;
map<int, int> Resolve() override;
vector<int> FindPath() override;
};
#endif
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>
#include <string>
#include "bfs_algorithm.h"
#include "map_config.h"
#include "mnode.h"
#include "map.h"
using std::cout;
Expand All @@ -24,6 +25,7 @@ int main(int argc, char* argv[])
endNode.NStateSetter(ENodeState::NONE);
tMap.Draw(startNode, EDrawType::TYPE);
tMap.Draw(endNode, EDrawType::TYPE);
tMap.DrawTerrain(MapConfig::TerrainMap);
BFSAlgorithm bfs(tMap, startNode, endNode);
map<int, int> bfsSolveMap = bfs.Resolve();
refresh();
Expand Down
31 changes: 31 additions & 0 deletions map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <curses.h>
#include <iostream>
#include <list>
#include <map>
#include <ncurses.h>
#include <sstream>
#include <stdexcept>
Expand Down Expand Up @@ -395,3 +396,33 @@ list<MNode> Map::GetNeighbors(const MNode& node)
return neighborsList;
}

void Map::DrawTerrain(const map<ENodeType, list<pair<int, int>>>& terMap)
{
if(Size() > 0 && terMap.size()>0)
{
for (pair<ENodeType, list<pair<int, int>>> firPair : terMap)
{
ENodeType &nType = firPair.first;
list<pair<int, int>>& typeList = firPair.second;
for (pair<int, int> secPair : typeList)
{
MNode& terNode = GetNode(secPair.first, secPair.second);
terNode.NTypeSetter(nType);
Draw(terNode, EDrawType::TYPE);
}
}
refresh();
}
}

void Map::DrawOriginPath(const map<int, int>& orimap)
{

}

void Map::DrawFinalPath(const vector<int>& pathVec)
{

}


5 changes: 5 additions & 0 deletions map.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include<map>
#include <utility>
#include<list>
#include <vector>
using std::map;
using std::list;
using std::pair;
using std::vector;

class Map
{
Expand Down Expand Up @@ -58,5 +60,8 @@ class Map
int ExchMapIndexToNum(int _mapIndex_Y, int _mapIndex_X) const;
list<MNode> GetNeighbors(const MNode& node);
bool NodeCheck(const MNode& node);
void DrawTerrain(const map<ENodeType, list<pair<int, int>>>& terMap);
void DrawOriginPath(const map<int, int> & oriMap);
void DrawFinalPath(const vector<int>& pathVec);
};
#endif
2 changes: 1 addition & 1 deletion map_config.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef _MAP_CONFIG_H
#define _MAP_CONFIG_H

#include "mnode.h"
#include <list>
#include <map>
#include <utility>
using std::map;
using std::list;

class MapConfig
{
public:
Expand Down

0 comments on commit 71cbfb8

Please sign in to comment.