# Dungeon crawler game

**URL:** https://discuss.ocaml.org/t/dungeon-crawler-game/3850
**Category:** Learning
**Created:** [May 25, 2019, 5:13pm UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850 "2019-05-25T17:13:30Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![alugocp](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/alugocp/32/1620_2.png) [@alugocp](https://discuss.ocaml.org/u/alugocp)
#### Post date: [May 25, 2019, 5:13pm UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/1 "2019-05-25T17:13:30Z")

</div>

Hey all! I recently made a simple text-based dungeon crawler using a mix functional and object-oriented programming in OCaml. Feel free to check it out if it interests you 🙂 I have a video of the game being played and explained [here](https://www.youtube.com/watch?v=De8OH6279qA). You can find the source on GitHub [here](https://github.com/alugocp/crypts-and-camls).

---

<div class="post-metadata">

### Author: ![bramford](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bramford/32/316_2.png) [@bramford](https://discuss.ocaml.org/u/bramford)
#### Post date: [May 29, 2019, 2:05am UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/2 "2019-05-29T02:05:23Z")

</div>

Cool. I see you’ve made heavy use of the object system. If you’re interested in games built using the more idiomatic functional/ocaml approach (i.e. modules), you should check out [a-nikolaev/wanderers](https://github.com/a-nikolaev/wanderers).

I also wrote [bramford/2d-exploration-game](https://github.com/bramford/2d-exploration-game) - a simple terminal/ncurses game while I was learning ocaml. I tried a couple of different approaches using the module system. I never felt that I got it quite right so while it is quite simple, it may not be the best example.

---

<div class="post-metadata">

### Author: ![fccm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/fccm/32/1587_2.png) [@fccm](https://discuss.ocaml.org/u/fccm)
#### Post date: [May 29, 2019, 8:23am UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/3 "2019-05-29T08:23:59Z")

</div>

Nice, I hope you will make more adventures 🙂

On my side I started a shmup game with abstract graphics because I’m fond of Kenta Cho games, not yet in a git repository, I put it in a gist: [shmup\_av6.ml](https://gist.github.com/fccm/ade9aee7b4594dc9c130b40098ad92ab)

Quite functional too, only shot and missed variables are imperative.

My best score is:  
shot: 460  
missed: 25  
score: 435

---

<div class="post-metadata">

### Author: ![ivg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ivg/32/103_2.png) [@ivg](https://discuss.ocaml.org/u/ivg)
#### Post date: [May 29, 2019, 12:37pm UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/4 "2019-05-29T12:37:46Z")

</div>

The name made my day 😃

Speaking of the code a small piece of advice, instead of writting

```ocaml
        | (k,`String v) when k="name" -> e#set_name v
        | (k,`Int i) when k="health" -> e#set_health i
        | (k,`Int i) when k="damage" -> e#set_dmg i

```

you can do

```ocaml
        | ("name",`String v) -> e#set_name v
        | ("health",`Int i) -> e#set_health i
        | ("damage",`Int i) -> e#set_dmg i

```

---

<div class="post-metadata">

### Author: ![alugocp](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/alugocp/32/1620_2.png) [@alugocp](https://discuss.ocaml.org/u/alugocp)
#### Post date: [June 2, 2019, 9:32pm UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/5 "2019-06-02T21:32:56Z")

</div>

Brilliant! I’ll keep that in mind for next time, thanks

---

<div class="post-metadata">

### Author: ![alugocp](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/alugocp/32/1620_2.png) [@alugocp](https://discuss.ocaml.org/u/alugocp)
#### Post date: [June 2, 2019, 9:33pm UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/6 "2019-06-02T21:33:47Z")

</div>

That’s so cool! I’d love to see it when you put it on Github

---

<div class="post-metadata">

### Author: ![alugocp](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/alugocp/32/1620_2.png) [@alugocp](https://discuss.ocaml.org/u/alugocp)
#### Post date: [June 2, 2019, 9:34pm UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/7 "2019-06-02T21:34:27Z")

</div>

That sounds great, I’ll check it out 🙂

---

<div class="post-metadata">

### Author: ![fccm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/fccm/32/1587_2.png) [@fccm](https://discuss.ocaml.org/u/fccm)
#### Post date: [June 3, 2019, 10:03am UTC](https://discuss.ocaml.org/t/dungeon-crawler-game/3850/8 "2019-06-03T10:03:42Z")

</div>

I updated it to remove the dependencies on ageom and timeline by including the pieces of code used: [shmup\_av10.ml](https://gist.github.com/fccm/ade9aee7b4594dc9c130b40098ad92ab)

As there is only one source code file, you can run it directly with ocaml:

```auto
opam install ocamlsdl2

```

If you’re using SDL2 version 2.0.9, or if you installed an older version:

```auto
opam install ocamlsdl2.0.02

```

Then you can run the game with:

```auto
eval $(opam env)
ocaml -I $(ocamlfind query sdl2) sdl2.cma shmup_av10.ml

```

I created a [basic webpage](http://www.linux-nantes.org/~fmonnier/ocaml/shmup_av/) for this game, there are screenshots and an executable binary for Windows.
