Skip to main content

Raymii.org Raymii.org Logo

Quis custodiet ipsos custodes?
Home | About | All pages | Cluster Status | RSS Feed

CookieNumberPrinter, incremental / idle game style numbers in C++

Published: 12-09-2020 | Author: Remy van Elst | Text only version of this article


❗ This post is over three years old. It may no longer be up to date. Opinions may have changed.


To level up my software development skills, I'm programming a command line game in my spare time. It is a clone of the famous cookieclicker game by ortiel. A clone of a game is simple enough to get up and running fairly quickly, but also extensible enough when needed. How do you store huge score numbers when they don't fit in a long long? How do you write a game loop, how to use threads to handle user input? Saving a game (how to design a proper save format)? Also a great way to learn about project organization, software architecture and to try out design patterns.

As the game is a clone of CookieCliker, which itself is an incremental game, I had to figure out how to work with large numbers. Since this is not a university math project, I allowed myself the luxury of using Boosts Multiprecision. The library handles the large numbers, including caluclation and operations with such a number. I did want to print the numbers in Idle Style, where large numbers are displayed with a suffix, like 1 million instead of 1000000 and so on.

This C++ class can be used to print Boost's cpp_dec_float numbers in incremental style. It's just one header. You can get the code here.

[If you like this class, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get $100 credit for 60 days). (referral link)][99]

Please do keep in mind that this is a hobby project, the code might not be up to your professional standards. As of now the class in my game has diverged a bit to also support a few other boost numbers and can directly be used as an output stream (std::cout << cookienumber instead of std::cout << cookienumber.print()).

Idle Style numbers?

If you're wondering what Idle / Incremental game style is, let me show you. A lot of mobile games show numbers in idle style, here is a picture of one:

idle miner

Here is a screenshot of my game, where you can see I have 5p cookies as well as prices for certain items with suffixes:

c_ookieclicker

Even though one is a flashy Android game and one is a humble command line application, you see the idle style printing.

In the future I might show more of the game, or even make the git repository public. For now it's just me and a few friends.

Download and building and an example

I assume you have a working C++ compiler setup and have compiled before.

Install boost:

apt install libboost-all-dev

Clone the git repository

git clone https://github.com/RaymiiOrg/cookienumberprinter

Go in the folder and cmake / make

cd cookienumberprinter
mkdir build
cd build
cmake .. 
make

Run the example:

./cookienumberprinter

Output should be:

CookieNumberPrinter by https://raymii.org, examples.
Should print:
0
1
1.1
100.3
1234
123 thousand
1 million
8 million
12 billion
3 quintillion
897a
11yyy
Here we go!

0
1
1.1
100.3
1234
123 thousand
1 million
8 million
12 billion
3 quintillion
897a
11yyy

Process finished with exit code 0
Tags: boost , c++ , cmake , cookies , cpp , development , games , idle , software