diff --git a/README.md b/README.md index f8934e2..ac13854 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,4 @@ Run: make tests Again, this is primitive, assuming g++ and xwidgets and stuff directly -in the standard include path, or $(CONDA_PREFIX)/include. +in the standard include path, or $(CONDA_PREFIX)/include. \ No newline at end of file diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 7992763..ca29009 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -15,16 +15,18 @@ auto PetiteToile = Tile::SmallWeb; auto Sortie = Tile::Exit; auto Mur = Tile::Wall; auto Vide = Tile::Void; -auto debut() { return app -> debut(); } -auto avance() { return app -> avance(); } -auto droite() { return app -> droite(); } -auto gauche() { return app -> gauche(); } -auto pose() { return app -> pose(); } -auto prend() { return app -> prend(); } -auto seme() { return app -> sow(); } -auto ouvre() { return app -> ouvre(); } -auto regarde() { return app -> regarde(); } -bool a_gagne() { return app -> won(); } +auto debut() { return app -> debut(); } +auto avance() { return app -> avance(); } +auto droite() { return app -> droite(); } +auto gauche() { return app -> gauche(); } +auto pose() { return app -> pose(); } +auto prend() { return app -> prend(); } +auto seme() { return app -> sow(); } +auto trace_de_pas() { return app -> footstep(); } +auto traces_de_pas(bool flag) { return app -> footsteps(flag); } +auto ouvre() { return app -> ouvre(); } +auto regarde() { return app -> regarde(); } +bool a_gagne() { return app -> won(); } void LABY(std::string s) { app = laby_level(s); diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index 3f28b27..343573f 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -86,15 +86,18 @@ enum class Direction { North, West, South, East }; std::vector directions = { {-1,0}, {0,-1}, {1,0}, {0,1} }; enum Tile { - AntE, AntN, AntS, AntW, Exit, SmallRock, SmallWeb, Rock, Void, Wall, Web, Outside, RandomRock, RandomWeb + AntE, AntN, AntS, AntW, Exit, SmallRock, SmallWeb, Rock, Void, Wall, Web, Outside, RandomRock, RandomWeb, + FootN, FootS, FootE, FootW }; // Assumption: fake tiles are rendered as void std::vector tilenames = { "ant-e", "ant-n", "ant-s", "ant-w", "exit", "nrock", "nweb", "rock", "void", "wall", "web", "void", "void", "void" + ,"foot-n", "foot-s", "foot-e", "foot-w" }; std::vector tilechars = { - u8"→", u8"↑", u8"↓", u8"←", "x", "ŕ", "ẃ", "r", ".", "o", "w", " ", "R", "W" + u8"→", u8"↑", u8"↓", u8"←", "x", "ŕ", "ẃ", "r", ".", "o", "w", " ", "R", "W", "N", "S", "E", "W" + }; enum PlayDirection { Forward, Backward, None }; @@ -164,7 +167,7 @@ class Labyrinth { std::string message; bool _won = false; public: - + bool _leave_steps=true; ////////////////////////////////////////////////////////////////////////// // Constructors Labyrinth() { @@ -363,6 +366,9 @@ class Labyrinth { return false; } message = ""; + if(_leave_steps){ + footstep(); + } position = devant(); return true; } @@ -385,11 +391,10 @@ class Labyrinth { } bool pose() { - if ( carry == Tile::Rock and - (regarde() == Tile::Void or - regarde() == Tile::Web or - regarde() == Tile::SmallWeb or - regarde() == Tile::SmallRock)) { + if ( carry == Tile::Rock and not + (regarde() == Tile::Rock or + regarde() == Tile::Exit or + regarde() == Tile::Wall) ) { carry = Tile::Void; board.set(devant(), Tile::Rock); message = ""; @@ -398,17 +403,37 @@ class Labyrinth { message = "Je ne peux pas poser."; return false; } - - bool sow() { - Tile tile = board.get(position); - if ( tile == Tile::Web or - tile == Tile::Exit ) { - message = "Je ne peux pas semer."; + + bool footstep(){ + switch(direction) { + case Direction::North: return sow(Tile::FootN); break; + case Direction::East: return sow(Tile::FootE); break; + case Direction::South: return sow(Tile::FootS); break; + case Direction::West: return sow(Tile::FootW); break; + default : return false; + } + return true; + } + + bool footsteps(bool flag){ + _leave_steps = flag; + return true; + } + + bool sow(Tile tile){ + Tile position_tile = board.get(position); + if ( position_tile == Tile::Exit ) { + message = ""; return false; } - board.set(position, Tile::SmallRock); + board.set(position, tile); return true; } + + + bool sow() { + return sow(Tile::SmallRock); + } bool ouvre() { if ( regarde() != Tile::Exit ) { @@ -523,6 +548,20 @@ class Player { time = history.size() - 1; update(); } + + void erase_footsteps() { + //Supprimer ce qu'il y a dans le tableau avec les trace de pas + //Double boucle pour vider + Board board = Board(); + for(int i = 0; i < board.size(); i++){ + for(int j = 0; j < board[i].size(); j++){ + if( board.get(Position(i,j)) == (Tile::FootN or Tile::FootS or Tile::FootE or Tile::FootW)){ + board.set(Position(i,j),Tile::Void); + } + } + } + update(); + } void step_backward() { if ( time > 0 ) { @@ -611,6 +650,21 @@ class LabyBaseApp { player.set_value(value); return res; } + + auto footstep(){ + auto value = player.get_value(); + auto res = value.footstep(); + player.set_value(value); + return res; + } + + auto footsteps(bool flag){ + auto value = player.get_value(); + auto res = value.footsteps(flag); + player.set_value(value); + return res; + } + auto regarde() { return player.get_value().regarde(); } diff --git a/laby.egg-info/PKG-INFO b/laby.egg-info/PKG-INFO new file mode 100644 index 0000000..093e3c9 --- /dev/null +++ b/laby.egg-info/PKG-INFO @@ -0,0 +1,12 @@ +Metadata-Version: 1.1 +Name: laby +Version: 0.0.1 +Summary: Laby-Jupyter: Learn programming, playing with ants and spider webs ;-) In Jupyter :-) +Home-page: https://github.com/nthiery/laby-jupyter/ +Author: Nicolas M. Thiéry +Author-email: nthiery@users.sf.net +License: GPLv2+ +Description: UNKNOWN +Platform: UNKNOWN +Classifier: Development Status :: 3 - Alpha +Classifier: License :: OSI Approved :: GNU General Public License (GPL) diff --git a/laby.egg-info/SOURCES.txt b/laby.egg-info/SOURCES.txt new file mode 100644 index 0000000..e879412 --- /dev/null +++ b/laby.egg-info/SOURCES.txt @@ -0,0 +1,38 @@ +README.md +setup.py +include/laby/global_fr.hpp +include/laby/laby.hpp +include/laby/timer.hpp +include/laby/widget.hpp +laby.egg-info/PKG-INFO +laby.egg-info/SOURCES.txt +laby.egg-info/dependency_links.txt +laby.egg-info/top_level.txt +share/laby/levels/0.laby +share/laby/levels/1a.laby +share/laby/levels/1b.laby +share/laby/levels/1c.laby +share/laby/levels/2a.laby +share/laby/levels/2b.laby +share/laby/levels/2c.laby +share/laby/levels/3a.laby +share/laby/levels/3b.laby +share/laby/levels/4a.laby +share/laby/levels/4b.laby +share/laby/levels/counting-the-rocks.laby +share/laby/levels/this-is-crazy.laby +share/laby/tiles/ant-e.svg +share/laby/tiles/ant-n.svg +share/laby/tiles/ant-s.svg +share/laby/tiles/ant-w.svg +share/laby/tiles/exit.svg +share/laby/tiles/foot-e.svg +share/laby/tiles/foot-n.svg +share/laby/tiles/foot-s.svg +share/laby/tiles/foot-w.svg +share/laby/tiles/nrock.svg +share/laby/tiles/nweb.svg +share/laby/tiles/rock.svg +share/laby/tiles/void.svg +share/laby/tiles/wall.svg +share/laby/tiles/web.svg \ No newline at end of file diff --git a/laby.egg-info/dependency_links.txt b/laby.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/laby.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/laby.egg-info/top_level.txt b/laby.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/laby.egg-info/top_level.txt @@ -0,0 +1 @@ + diff --git a/share/laby/tiles/foot-e.svg b/share/laby/tiles/foot-e.svg new file mode 100644 index 0000000..ffa0561 --- /dev/null +++ b/share/laby/tiles/foot-e.svg @@ -0,0 +1,31 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + diff --git a/share/laby/tiles/foot-n.svg b/share/laby/tiles/foot-n.svg new file mode 100644 index 0000000..768aac9 --- /dev/null +++ b/share/laby/tiles/foot-n.svg @@ -0,0 +1,31 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + diff --git a/share/laby/tiles/foot-s.svg b/share/laby/tiles/foot-s.svg new file mode 100644 index 0000000..9fe55e7 --- /dev/null +++ b/share/laby/tiles/foot-s.svg @@ -0,0 +1,31 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + diff --git a/share/laby/tiles/foot-w.svg b/share/laby/tiles/foot-w.svg new file mode 100644 index 0000000..818e1a1 --- /dev/null +++ b/share/laby/tiles/foot-w.svg @@ -0,0 +1,33 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + +