First Code

As you can see from the previous post there are a lot of things to consider when building something on-chain. It's easy to get overwhelmed by this and reach a state of analysis paralysis. The best way I have found to break out of this is to just start writing code, so that's what I did:

This is the first Go code I've ever written and there were definitely some "learnings". Overall it was a great exercise for getting un-paralyzed and learning a new language at the same time. I have a number of thoughts and comments, but I will maintain those in another post.

If you go run src/main/main.go this code, it'll spew a bunch of info in the output. It's just doing a sample run through of the core game loop. 

Yes, I'm aware that Go doesn't have "classes" just structs, and that the New... functions aren't actually on the struct. But for ease of understanding I've adapted them into a class diagram.

The objects look like this:

erDiagram Pack ||--|{ Tile : "Open Pack" Player ||--|{ Character : "" DungeonTile }|--|| Dungeon : "" Dungeon }|--|{ DungeonMatch : "List Dungeon" Character }|--|{ DungeonMatch : "Play Match" Player { WalletAddress EthAddress string Name int Gold } Character { string Name WalletAddress Owner ColorAttributes ColorAttributes float32 Power } Pack { string Collection string Id WalletAddress Owner } Tile { TileType TileType ColorAttributes ColorAttributes WalletAddress Owner } DungeonTile { int X int Y Tile Tile } Dungeon { string Name WalletAddress Owner int Width int Height int Power int Difficulty array_DungeonTile Tiles } DungeonMatch { Dungeon Dungeon Character Character float32 DungeonMultiplier float32 CharacterMultiplier float32 StartingPower float32 EndingPower int Reward array_int PlayedTiles }

And the flow it's following is this:

graph TD; P1A[Player1] --> P1B[Make Player 1]; P2A[Player2] ---> P2B[Make Player 2]; P1B ---> P1C[New Character]; P2B ---> P2C[Buy & Open Pack x 10]; P2C --> P2D[Make Simple Dungeon]; P2D -.-> P1D; P1C ----> P1D[Play simple Dungeon]; P1D --> P2E[Update Player 2 Gold]; P1D --> P1E[Update Player 1 Gold];


Incomplete implementation

Obviously there are a lot of things missing here. The code is passing around state as if it's readily available, and much of it is not keyed in a way that we could store and retrieve it. At least we have our core objects and can see their interface points.


There are a lot of references to "colors" here, because a concept I'm thinking of with this game is that character stats (and appearances) are determined by colors.