How to build browser game? [Iteration 1] Domains

Dmitry Kmita
ITNEXT
Published in
4 min readJan 15, 2018

--

As goal of these series is to go through as many aspect of web development as possible, play with new tech and learn something new and interesting. And we will do this by creating a text-based browser game.

If you haven’t read previous post about the idea — here it is:

[Iteration 1] >> Domains

To build any application — you have to define the MVP. If you don’t know what MVP is — it’s minimal viable product, or in easy language smallest deliverable, that will bring some value. I have spent some time and defined our MVP:

We have a character, which can walk on map and collect items on it. Character has defined stats, experience points and level. Character also has an inventory, where he has all his items. He can put specific items in specific slots (wear them).

That’s it! Very small, tiny MVP, which will be our base. Then we will iteratively move forward and enhance this game.

To make delivery of this product even more correct — every feature I will talk about will be defined in BDD way.

But first, after defining the MVP — we need to define domains. We need to think how we will store them, and how broad we will go.

We definitely have Character, Map & Item domains. There are 3 core domains for MVP. Then we go a little bit deeper and define character, map & item properties.

Character

Our character will have default attributes like name & gender, but what is important — stats & inventory. I think we should decouple these as separate domains. So that can if we decide to enhance stats or inventory domains in future — we won’t need touching the main character.

Map

Because our map will be 2D, we have tiles, each tile will have X & Y coordinates. pretty easy with that.

Item

I want to make an item very basic from the beginning, we will enhance it later, so as a starting point it will have name, type, picture.

So this is the small graph I created to define the domains:

MVP Domains

Because I use Symfony 3 for back-end — I also use Doctrine as DB ORM, which makes my life much easier. A while ago, first thing I found boring in defining domains — same properties for different purpose in different domains. The problem with PHP is that you can’t extend from more than 1 class, which makes more complicated inheritance a pain.

So there is a small tip for those who hate adding same fields to Entities (like id, createdAt, updatedAt etc), instead of extending from other class (and then mapping in as “@MappedSuperClass”) — use traits! From inheritance perspective traits work much better in this case, because you don’t have an abstract object or logical object to inherit, you just want to auto copy-paste the fields. Also as I mentioned, you can’t inherit more that 1 class in PHP, but you can use as many traits as you want, because they are not dealing with inheritance problems. If you haven’t worked with traits, here’s a link for read, it’s an old feature of PHP, but not many people use it:

So here’s an example of my Character Entity:

No Setters & Getters just for smaller screenshot

As you can see I created UniqueTrait, which is basically an implementation of Primary Key:

Now I can just use this trait in all my entities

Defining MVP & Domains from the start is very important, because it helps you with:

  • Makes sure you don’t overcomplicate your app
  • Gives you a better view on how things will look like
  • Reduces amount of waste
  • Creates a defined piece of work that needs to be done

So now we have an idea covered with defined domains for our MVP project. Doesn’t that sound great? It does not matter what project you are building — always define your MVP and domains first, this will solve a lot of problems in the future and will help to actually release something before it becomes a huge piece of application with loads of unneeded features.

Ok, so we will stop here for now and move to building simple UI in next post.

We will cover ReactJS, its main benefits and disadvantages, so if you love new JS tech — I am sure you will find it interesting!

Hope you enjoyed it and are exited to move on. I will really appreciate if you react by clapping/following/responding to this story, because I wan’t to understand if you find it useful/interesting.

--

--

Writer for

CEO @ Travonto.com :: Solving Problems for Customers :: Coaching & Mentoring Ambitious People :: Building Great Teams :: Engineering Highly Available Products