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() // ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° располоТСния крСстиков/Π½ΠΎΠ»ΠΈΠΊΠΎΠ² }); 
  1. Please explain at least in words how best to organize the code? that there was no sheet of code

  2. 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 ...

  • 3
    This is bad - the logic in View. Divide into View and model at least. - VladD
  • 2
    I send bugreport: you can win and lose at the same time) That is, after a win, the computer can go again and win too - Duck Learns to Hide
  • VladD, in any case, this problem will not solve in a javascript mvc, the view and presentation are combined (at least in the backbone this principle is used). In the model, you can make any small part of the logic associated with the processing or extraction of data from the database, but the main part of the logic will remain in view - cyklop77

0