N
N
nepster-web2014-08-07 17:07:12
PHP
nepster-web, 2014-08-07 17:07:12

What is the best way to interact with classes and database?

I am making a game portal and I have some questions in order to organize the work with games as conveniently and correctly as possible.
That is, for example, we have several games, and I need to organize the following things:
- creating an application for the game
- game statistics
- and so on.
So the first thing I did was a general table of all games.

'game_id'     => 'int(11) unsigned NOT NULL AUTO_INCREMENT',
            'name'        => 'varchar(200) NOT NULL',
            'alias'       => 'varchar(200) NOT NULL unique',
            'logo'        => 'varchar(200)',
            'status'      => 'tinyint(1) NOT NULL DEFAULT 0',
            'sort'        => 'tinyint(4) NOT NULL DEFAULT 0',
            
            'description' => 'text',
            'rules'       => 'text',
            
            'category'    => 'int(11) unsigned DEFAULT 0',          
                    
            'count_players_in_game'  => 'int(11) NOT NULL DEFAULT 0',
            'count_players_play'     => 'int(11) NOT NULL DEFAULT 0',
            'count_players_waiting'  => 'int(11) NOT NULL DEFAULT 0',

Application table for games
That is, users create applications according to the desired rules (for example, play the transfer fool, with a deck of 52 cards, take 30 seconds per move, etc.)
'proposal_id'   int(11) unsigned NOT NULL AUTO_INCREMENT,
            'game_id'       int(11) unsigned NOT NULL DEFAULT '0',
            'date_start'    datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
            'date_end'      datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
            'status'        tinyint(1) NOT NULL DEFAULT '0',
            'money'         tinyint(1) NOT NULL DEFAULT '0',
            'bank'          decimal(12,5) NOT NULL DEFAULT '0.00000',
            'rules'         text NOT NULL,
            'hash'          varchar(100) DEFAULT NULL,
            'token'         varchar(64) NOT NULL,

Table of users who are waiting, that is,
if a request is created, users can connect to it (based on the number of players rule)
'waiting_id'    int(11) unsigned NOT NULL AUTO_INCREMENT,
            'proposal_id'   int(11) unsigned NOT NULL,
            'user_id'       int(11) unsigned NOT NULL,
            'sort'          tinyint(1) NOT NULL DEFAULT '0',
            'root'          tinyint(1) NOT NULL DEFAULT '0',
            'hash'          varchar(100) DEFAULT NULL,

Now I have a number of questions, how best to organize the structure of work with games in such a way that there would be no problems in the future.
Question 1. How to make friends base and classes of games?
For each game we have a class.
For example, there is a game Durak, we have a special class Durak.php that describes the technical aspects of the game, such as:
- Game rules (available rules and options)
- Is it possible to play with a computer (all sorts of proxies for connecting a bot, etc. ) .)
- any configuration pieces and so on.
Now we have an alias field in the table, if we store the value "Durak" in this field, for example, and when working with the game, refer to the class based on the alias in the table. Will this be the right decision?

Well, for example, the user enters the Durak game page, I take the value from the alias field and, based on it, connect the game class, take the rules config from there and generate a page for the user with the rules of this game.
Question 2: How do you keep track of extensibility?
For example, the next step is to add games with tables. That is, the difference is that the user creates applications according to the desired rules, and they join the table and our rules are static.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2014-08-07
@nepster-web

Read about ORM - Object Relation Mapping.
And also read about PHP-framework, in particular about Laravel .
I think after a month of study, a lot will fall into place.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question