Draw Texture in a grid like Trainyard

Hello to everyone!!! Is there someone that knows a way to draw texture on a grid with continuous rails like game Trainyard??

I can think of few different ways, but here is a starting point for one way. Create a Tile class. The Tile class would have an array of textures. Each texture would represent one of the possible track runs. The Tile Class would detect when a finger move entered and exited the game object on which the Tile class was a component. Based on the finger move, a specific texture/state would be selected. For example if the finger move came in on the left and and exited at the bottom, a texture that started on the left and curved down would be selected from the array and dispalyed.

The board would consist of an array of game objects with the Tile class as a component. To run the train after the track has been constructed, you could start at the beginning and walk from tile to tile looking at the state of each tile to build a path for the train.

Ok, i understand your way with tile map! Can you give me a code or a pseudo-code that implements this way? Thanks a lot!