• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Inheritance (Practice)

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,249
Solutions
71
Reaction score
621
Location
Hell
Hello otlanders! I have been learning C++ inheritance for about a week now and I have grasped the basic concept of it and understand the basic questions that are Frequently Asked. BUT it is time for me to get a bit advanced on this field too, and of course I need Tasks or Some sort of Project in order to be able to get into the advanced parts of C++ Inhertiance. I have been looking on the internet for Tasks &/ Projects but haven't found anything that im looking for, it's mostly basic tasks and teachings.

So I am wondering if you guys could give me some ideas &/ tasks &/ projects which I could work and improve my skills on. I'd be thankful if you could take some time and write down some stuff xD
 
For example, I hate function Map::getPathTo in old open tibias server like YurOTS.
It can be written much better.

It's not even trying to go diagonally when it should.
YurOTS/map.cpp at master · divinity76/YurOTS · GitHub

#Edit:
Oh, it shouldn't be related to open tibia...? I think I just made a mistake, sorry about that.

Kind regards,
Adrik
 
Last edited:
How about a calculator? You could use a class for each operation that inherits from a generic operation class.
 
It needs to be in C++?
if you know Java, it's almost the same (but easier)..
with Java, I'd recommend you doing a simple game (like the dino-game on Chrome when ur internet is offline, or a game like Mario / Megaman), where you should use a GameStateManager, states for each level/menu/endgame, a superclass for objects and every object extending this superclass, etc.

The concept is the same for all languages, but I don't know much about user interface in C++, since Java is much easier for that.
You can also try to do a small game in C++, without visual, just to practice inheritance...
 
You can also do what I did, build a text based game, inspired by "Arena Fighter" (exercise program), and make it into a very simple Tibia looking game.
You could inheritance between creature classes and item classes in whatever way you want :)

I built something that load/save your character to .txt files, enter/leave shop, buy hp/skill/atk/m.m, go into arena and fight monster that's a challenge to your current level.
Such project took me about 15 hours of C++ coding to complete, but it was kinda fun.

Try something like that :D
You can always imagine something to do, and just find new ways how to do it, you can keep anything very simple, but on your own demand, you can go more advanced and do things in more complex ways that suits your experience and by that, getting a really good exercise :)

Another idea I got while writing this, there's an exercise for inheritance, there you're supposed to write a text-based vending machine.
There all items inside it, should inheritance from a basic item class, that becomes different classes for drinks, snacks, food..
That one is a good exercise too, but for me, boring as hell, I like developing games that allow violence and levels :p

Good luck and hope it goes well for you! :)
 
Don't forget to learn about composition and concepts, too, and you'll know when you really should use inheritance (tip: not that much).
 
Back
Top