Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
22 changes: 12 additions & 10 deletions include/laby/global_fr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
84 changes: 69 additions & 15 deletions include/laby/laby.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ enum class Direction { North, West, South, East };
std::vector<Position> 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<std::string> 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<std::string> 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 };
Expand Down Expand Up @@ -164,7 +167,7 @@ class Labyrinth {
std::string message;
bool _won = false;
public:

bool _leave_steps=true;
//////////////////////////////////////////////////////////////////////////
// Constructors
Labyrinth() {
Expand Down Expand Up @@ -363,6 +366,9 @@ class Labyrinth {
return false;
}
message = "";
if(_leave_steps){
footstep();
}
position = devant();
return true;
}
Expand All @@ -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 = "";
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions laby.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -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: [email protected]
License: GPLv2+
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
38 changes: 38 additions & 0 deletions laby.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions laby.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions laby.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

31 changes: 31 additions & 0 deletions share/laby/tiles/foot-e.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions share/laby/tiles/foot-n.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions share/laby/tiles/foot-s.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions share/laby/tiles/foot-w.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.