My own fictional maps

Would it be possible for me to reuse the OSM code somehow so I could make my own website with fictional game maps and stuff like that?

I believe all the code is open source, so yes.

However, are you are sure you are not really talking about a slippy map tile viewer. Whilst these are sued by the OSM web site, they are not part of OSM and can be used without it. leaflet.js is one of the common ones.

Okay, which API should I go about figuring out in order to do this? Can I exclusively use leaflet.js?

I think we have to clarify what you are doing first. Leaflet is a javascript library, for use in web pages. It will need some code to invoke it. You will need to provide map tiles for it and create them by appropriate means.

The real part of the OSM infrastructure is directed towards maintaining the vector data from which those tiles are drawn and providing the software that renders the data into tiles. Whether you need any of that will depend on how you see yourself creating tiles and whether you need services (like (reverse-) geocoding, or routing, that work on the vector data).

Just as an example, https://opengeofiction.net/ is exactly the sort of thing that you’re talking about. You might want to start reading here: https://wiki.openstreetmap.org/wiki/The_Rails_Port .