I’m working a minimal game with Java and mysql. I encountered some difficulties with how to design my tables correctly. I need some advices: Let me be specific, I have 3 classes:
Node
public class Node {
private Integer id;
private Integer position;
private Integer foodTax;
private Boolean hasTreasureMap;
private Integer currentPlayer; // playerId
Treasure
public class Treasure {
Integer id;
private Integer position; // nodeId
private Integer goldValue;
Player
public class Player {
private Integer id;
private Integer wealth;
private Integer strength;
private Integer start;
private Integer goal;
private Integer currentPosition; // nodeId
private Integer currentGoal; // another nodeId
private Vector<Integer> path;
private Vector<Integer> treasureIds;
private int currentMoveIndex;
Graph<Integer> telescope;
I’m a newbie to mysql, and database in general. I think I have to use foreign key in this case. However, I’m still vague how to implement it. Besides, there are several constraints:
- Treasure’s position is fixed.
- Node position is fix.
- Only player position can be changed.
- A node can only have a player at a time.( I try to make it as simple as I can, cause if there are two players in the same node, I don’t know how to handle it )
So the only foreign key here in my opinion is ‘currentPlayer’ id of class Node? Please correct me if I was wrong. Any idea?
Best regards,
Chan Nguyen
IT’s still not clear what you’re trying to store, but you could have a table for Nodes:
…I have no idea what the
Telescopeis for. Again, this suggestion might not work, I’m not exactly sure what you’re doing with this data.