I began to study the node, so I am writing my first game, these are checkers.
I have 2 functions (on the client), 1 function draws a field, the second function draws checkers, based on their coordinates.
So when 2 users play, everything looks the same, that is: black at the top, white at the bottom. For example, if I play white, this is very convenient, but an opponent who plays black is still not very comfortable.
Are there any ideas how to deploy a board for a user who plays with black checkers?
Server sends:
return { "white": { "P": ["5.0","5.2","5.4","5.6", "6.1","6.3","6.5","6.7", "7.0","7.2","7.4","7.6"], "K": [], }, "black": { "P": ["0.1","0.3","0.5","0.7", "1.0","1.2","1.4","1.6", "2.1","2.3","2.5","2.7"], "K": [], } };
These are the coordinates of where the pawn is based on the type of queen or pawn.
Users get the coordinates and the client draws:
Customer:
/** * ΠΠ³ΡΠΎΠ²ΠΎΠ΅ ΠΏΠΎΠ»Π΅ */ board: function() { // ID Π΄Π»Ρ Π³Π΅Π½Π΅ΡΠ°ΡΠΈΠΈ ΠΏΠΎΠ»Ρ var board_id = "#board"; for (var i = 0; i < 8; i++) { for (var j = 0; j < 8; j++) { var coord = i + '.' + j; if ((i%2==0 && j%2==0)|| (i%2!=0 && j%2!=0)) { $(board_id).append('<div class="cell cell_white" data-item="cell" data-coord="'+coord+'">'+coord+'</div>'); } else { $(board_id).append('<div class="cell cell_black" data-item="cell" data-coord="'+coord+'">'+coord+'</div>'); } } } }, /** * Π Π°Π·Π»ΠΎΠΆΠΈΡΡ ΡΠ°ΡΠΊΠΈ */ expanded: function(coordChecker) { $('[data-item="cell"]').find($('.checker')).remove(); var checkers_coords = coordChecker; for (var checkerColor in checkers_coords) { var checkers = checkers_coords[checkerColor]; // ΡΠΈΠΏ ΡΠ°ΡΠΊΠΈ [Π΄Π°ΠΌΠΊΠ° ΠΈΠ»ΠΈ ΠΏΠ΅ΡΠΊΠ°] for (var checkerType in checkers) { // ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΡΠ°ΡΠΊΠΈ var checkersCoord = checkers[checkerType]; checkersCoord.forEach(function(checkerCoord) { if(checkerColor == 'white') { if(checkerType == 'K') { console.log('ΠΠ΅Π»Π°Ρ Π΄Π°ΠΌΠΊΠ°'); } else { $('[data-item="cell"][data-coord="'+checkerCoord+'"]').html('<div class="checker ck_white" data-item="checker" data-checker="white" data-coord="'+checkerCoord+'"></div>'); } } else { if(checkerType == 'K') { console.log('Π§Π΅ΡΠ½Π°Ρ Π΄Π°ΠΌΠΊΠ°'); } else { $('[data-item="cell"][data-coord="'+checkerCoord+'"]').html('<div class="checker ck_black" data-item="checker" data-checker="black" data-coord="'+checkerCoord+'"></div>'); } } }); } } },
Here are the coordinates: