
My previous post "
How to make a 3D JavaScript shooter in a couple of days " showed that the topic of developing browser games is very interesting and for this reason I decided to devote another weekend to another of my ideas.
This time the weekend fell on the New Year holidays and the free time was a little more than usual, so I’ll slowly and tell the story and start with a little story.
2002 Summer
Ten years ago I worked as a night watchman, but the caretaker was not quite normal for me. Since I was obsessed with computers since childhood (at the age of seven I first met Agat), I came to work with my laptop and modem and didn’t sleep until the next morning.
')
I spent all night online. It was very convenient for me to “work” like this, because in fact I received money for what I did most often at night, only in this case you don’t need to share a telephone line with someone and go very quietly over a dark apartment for a cup of tea . And everything was great and smooth, until suddenly there were quite frequent interruptions with the provider, which, for several reasons, I could not change. Since I always take the job seriously, and it was hard not to sleep without a connection, it was urgently necessary to have a replacement in the form of “offline” entertainment.
That's when I downloaded a rather interesting “toy” somewhere. I unfortunately can’t remember exactly now its name, most likely “Fish Tycoon”, it was written by a Russian programmer (that's for sure). The game offered to build its empire based on fish trade (yes, and why not), gradually expanding the trading network needed to master the entire market, which was the result and could theoretically lead to victory in the game (it did not work). I worked as a watchman for about half a year and during that time I managed to play enough.
The years went by, I changed jobs, went about my business, hired again, moved to another city, created various projects, but often recalled with warmth that half a year and "that very" game. To be honest, the idea to write an analogue settled in my head probably about two years ago, but I always put off this undertaking for a number of reasons. Besides, it always seemed to me that there would be a lot of code there.
year 2013. Winter
And here came the next New Year holidays. As it should be, I finished everything until the end of the year, closed all my obligations and, with a clear conscience and fun, met my new year at home with my family. Waiting from day to day the next replenishment in the family, I could not afford to drink at the table more than a glass of champagne, on this already the first of January, when everyone was sleeping peacefully in their beds I lay and thought through the architecture of the new project.
I almost immediately decided not to focus on fish, although nostalgia made me first give the project the code name “fish”, I then decided to disregard the name of the product, leaving only the word “product” itself.
And on the night from first to second, I sat down at my laptop and made the first sketches. First of all, I clearly decided that I would have a convenient schedule reflecting the situation on the market in real time and it will definitely be on SVG. Here is this:

Secondly, I set a goal to develop for a couple of nights a simple model, in which there will be both an element of risk and a practical calculation.
So, what is the result?
Not having knowledge in economics and finance, I built a model according to my own rules. The most important figure is the cost of goods in a specific period of time (purchase price), I calculate it with the help of time of day and sine, as well as a certain number of calls to Math.random ().
Having this figure as a starting point, it is quite easy to come up with an option of calculating the price for sale, and by getting a couple of these values ​​and adding some “accidents” to them, you can extract the coefficient of buyers' activity.
In order to sell the purchased goods, we need to have a sales outlet and an employee who will do this.
For this, I implemented a model of a small shop, which can be easily transformed into a warehouse, other options for stores or an office. You can also add several employee options - managers to increase the profitability of trading operations and accountants, which will help to optimize taxation.
The whole code is very simple, you can change various formulas and coefficients ad infinitum, I confess, I got stuck on this case once before 5 am. It turned out the game in the game.
Let's go back to the process. The game cycle is calculated on a 24-hour basis, from 23:00 to 5:00 the next day, any trading operations are stopped, and the market does not work on weekends; therefore, a new batch of goods cannot be purchased. The rest of the time, the trading process automatically takes place, the probability of sales is calculated in a cycle, its volume taking into account the number of sellers in the store.
By the way, sellers know how long they have been working, how many goods they have already sold, this can be used further to simulate the process of increasing trading experience or, for example, to demand a salary increase threatening the owner with dismissal.
In order not to wait for a long time before the night or weekend passes, you can use various options for speeding up the process x5 and x10 to ensure that the day runs unnoticed.
When starting, a small help is given on the gameplay and a list of buttons that are more convenient to use than the mouse.
When buying and selling goods, we gradually come up against the ceiling of the size of stocks of goods, then we need to rent more shops and hire sellers, every day we get a calculation of how much is sold, for what amount, the cost of rent is calculated, the sellers are paid and the results are summarized.
By the way, all events are broadcast to the log and you can always pause and grasp the details of what is happening.
You can talk for a long time about what other moments await in the game, but then it will not be so interesting
to play .
I almost forgot, the name of the topic is “4200 bytes” - this is the size after packing and compressing gzip of all .js files of the project.
Remembering the wishes of the readers of the previous topic, I posted all the sources on
github for detailed study.
This version will not be updated and no shortcomings will be corrected, I want to keep this project for myself, but if someone suddenly gets an idea, please use it for health.
The last time many questions were written personally, I suggest this time to write everything in the comments to the post.