It’s time to add Players and the ability to change the current player on every next turn. - react typescript
to show which turn is right now, and some styles:Now let’s add these 2 new props to Board types:
// src/components/Board.tsx type BoardProps={ board: BoardModel; currentPlayer: PlayerModel; onChangePlayer: => void; onSetBoard: => void; };after every figure movement and in else conditions we will check that our selected figure label is the same as a current player’s label. This will allow us to move only current players’ figures:
// src/components/Board/Board.tsx const handleCellClick==> { if ) { selected.moveFigure; setSelected; onChangePlayer; // change player after we move the figure updateBoard; } else { if { // we can only select our figures setSelected; } } }; I also want to add logic that will calculate the correct available cell where we can move our figure. According to the rules, every figure can be moved only forward for the neighbor's dark cell. For example, the figure from C3 can be moved only to D4 or B4 cells, and figure A3 only to B4 cells://src/models/CellModel.ts isForwardCell: boolean { const { cell, label }=selectedFigure; const dx=Math.abs; const dy=cell.y - targetCell.y; return label===Labels.
After all of these changes we can select only figures based on which turn is now and move the figure only to the correct cell:
Singapore Latest News, Singapore Headlines
Similar News:You can also read news stories similar to this one that we have collected from other news sources.
Special and General Principle of Relativity | HackerNoonRelativity: The Special and General Theory by Albert Einstein is part of HackerNoon’s Book Blog Post series. - science physics
Read more »
The Count of Monte Cristo, Illustrated: Chapter 76 - Progress of Cavalcanti the Younger | HackerNoonThe Count of Monte Cristo Volume Four, Chapter 76: Progress of Cavalcanti the Younger,by Alexandre Dumas, père is part of HackerNoon’s Book Blog Post series. - hackernoonbooks thecountofmontecristo
Read more »
Moby-Dick; or The Whale: Chapter 93 - The Castaway | HackerNoonMoby-Dick; or The Whale, Chapter 93: The Castaway by Herman Melville is part of HackerNoon’s Book Blog Post series. - hackernoonbooks mobydickorthewhale
Read more »
Propensity to Motion, Repetition and Imitation | HackerNoonWhen the voluntary power is suspended during sleep, there commences a ceaseless flow of sensitive motions, or ideas of imagination, which compose our dreams. - hackernoonbooks projectgutenberg
Read more »
How to Grow your Video Business with Data | HackerNoonTV watching used to be a family affair a decade ago, but today in most households, content watching has become a personal activity. - dataanalytics ottstreaming
Read more »