made on the backbone the simplest version of the noughts and crosses:
http://fh79272k.bget.ru/files/works/tic_tac_toe/1/
https://github.com/zlodiak/ttt_1
but there are doubts about the chosen architecture (if you can call it that way). The main class APP.TttView contains too many methods and is long. and this is a sure sign that the program is designed randomly
The game consists of several view:
APP.TttView // ΠΎΡΠ½ΠΎΠ²Π° ΠΈΠ³ΡΡ APP.FieldView // Π³Π΅Π½Π΅ΡΠ°ΡΠΈΡ ΠΈΠ³ΡΠΎΠ²ΠΎΠ³ΠΎ ΠΏΠΎΠ»Ρ APP.CellView // Π³Π΅Π½Π΅ΡΠ°ΡΠΈΡ ΠΊΠ»Π΅ΡΠΊΠΈ I put almost all the logic in the main view:
APP.TttView = Backbone.View.extend({ render(), // ΠΎΡΡΠΈΡΠΎΠ²ΠΊΠ° ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΈΠ³ΡΡ playerStep(), // handler Ρ
ΠΎΠ΄Π° ΠΈΠ³ΡΠΎΠΊΠ° compStep(), // handler Ρ
ΠΎΠ΄Π° ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ° addStep(), // Π·Π°ΠΏΠΈΡΡ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΠΈ ΠΎΠ± ΠΎΡΠ΅ΡΠ΅Π΄Π½ΠΎΠΌ Ρ
ΠΎΠ΄Π΅ Π² ΡΠΏΠ΅Ρ.ΠΌΠ°ΡΡΠΈΠ² winnerCheck() // Π²ΡΠ·ΡΠ²Π°Π΅ΡΡΡ ΠΏΠΎΡΠ»Π΅ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Ρ
ΠΎΠ΄Π°. Π·Π΄Π΅ΡΡ ΠΆΠ΅ Π²ΡΠ·ΡΠ²Π°Π΅ΡΡΡ alert Π² ΡΠ»ΡΡΠ°Π΅ ΠΏΠΎΠ±Π΅Π΄Ρ }); In APP.FieldView, there is a method that checks whether crosses or zeroes are added to a line:
APP.FieldView = Backbone.View.extend({ checkCellLines() // ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° ΡΠ°ΡΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΊΡΠ΅ΡΡΠΈΠΊΠΎΠ²/Π½ΠΎΠ»ΠΈΠΊΠΎΠ² }); Please explain at least in words how best to organize the code? that there was no sheet of code
and please tell me if I did the right thing, made checkCellLines () in APP.FieldView? all the same, APP.FieldView is not obliged to check anything, it is simply responsible for displaying the field ...