@@ -671,7 +671,7 @@ export const BackgammonBoard = () => {
671671 < div className = "flex gap-6" >
672672 { /* Board */ }
673673 < div className = "bg-amber-100 rounded-lg p-6 shadow-xl flex-1" >
674- < h2 className = "text-2xl font-bold text-center mb-6 text-amber-900" > Backgammon Board </ h2 >
674+ < h2 className = "text-2xl font-bold text-center mb-6 text-amber-900" > WEB3 НАРДЫ </ h2 >
675675
676676 { /* Clickable area for field 0 (dead white checkers) - above top row */ }
677677 < div
@@ -724,12 +724,85 @@ export const BackgammonBoard = () => {
724724 </ div >
725725
726726 { /* Top half: cells 12-1 (right to left) */ }
727- < div className = "flex gap-4 mb-[100px] " >
727+ < div className = "flex gap-4 mb-4 " >
728728 { Array . from ( { length : 12 } , ( _ , i ) => 12 - i ) . map ( cell => renderPoint ( cell , true ) ) }
729729 </ div >
730730
731+ { /* Center: Dice images and roll button - always reserve space */ }
732+ < div className = "flex justify-center items-center gap-2 my-4 min-h-[48px]" >
733+ { ( ( isItBlackTurn && blackDiceRolled ) || ( ! isItBlackTurn && whiteDiceRolled ) ) &&
734+ ( isItBlackTurn ? blackAvailableMoveValues : whiteAvailableMoveValues ) . map ( ( value , index ) => (
735+ < Image key = { index } src = { `/${ value } .png` } alt = { `Dice ${ value } ` } width = { 48 } height = { 48 } />
736+ ) ) }
737+ { ( ( isItBlackTurn && ! blackDiceRolled ) || ( ! isItBlackTurn && ! whiteDiceRolled ) ) &&
738+ ( ( ) => {
739+ // Determine if current user can roll dice
740+ const isCurrentUserBlack =
741+ currentAddress &&
742+ blackPlayer &&
743+ typeof blackPlayer === "string" &&
744+ currentAddress . toLowerCase ( ) === blackPlayer . toLowerCase ( ) ;
745+ const isCurrentUserWhite =
746+ currentAddress &&
747+ whitePlayer &&
748+ typeof whitePlayer === "string" &&
749+ currentAddress . toLowerCase ( ) === whitePlayer . toLowerCase ( ) ;
750+
751+ // Determine button state and text
752+ let buttonText = "КИНУТЬ КОСТИ" ;
753+ let isButtonActive = false ;
754+
755+ if ( isItBlackTurn && ! blackDiceRolled ) {
756+ // Black's turn, dice not rolled
757+ if ( isCurrentUserBlack ) {
758+ buttonText = "КИНУТЬ КОСТИ" ;
759+ isButtonActive = true ;
760+ } else {
761+ buttonText = "ЖДЕМ ЧЕРНОГО" ;
762+ isButtonActive = false ;
763+ }
764+ } else if ( ! isItBlackTurn && ! whiteDiceRolled ) {
765+ // White's turn, dice not rolled
766+ if ( isCurrentUserWhite ) {
767+ buttonText = "КИНУТЬ КОСТИ" ;
768+ isButtonActive = true ;
769+ } else {
770+ buttonText = "ЖДЕМ БЕЛОГО" ;
771+ isButtonActive = false ;
772+ }
773+ }
774+
775+ return (
776+ < button
777+ className = { `btn ${ isButtonActive ? "btn-primary" : "btn-disabled" } ` }
778+ disabled = { ! isButtonActive }
779+ onClick = { async ( ) => {
780+ if ( ! isButtonActive ) return ;
781+ try {
782+ if ( isItBlackTurn ) {
783+ await writeBackgammonAsync ( {
784+ functionName : "rollDiceBlack" ,
785+ } ) ;
786+ } else {
787+ await writeBackgammonAsync ( {
788+ functionName : "rollDiceWhite" ,
789+ } ) ;
790+ }
791+ } catch ( error ) {
792+ console . error ( "Error rolling dice:" , error ) ;
793+ const userMessage = parseErrorMessage ( error ) ;
794+ notification . error ( userMessage ) ;
795+ }
796+ } }
797+ >
798+ { buttonText }
799+ </ button >
800+ ) ;
801+ } ) ( ) }
802+ </ div >
803+
731804 { /* Bottom half: cells 13-24 (left to right) */ }
732- < div className = "flex gap-4" >
805+ < div className = "flex gap-4 mt-4 " >
733806 { Array . from ( { length : 12 } , ( _ , i ) => 13 + i ) . map ( cell => renderPoint ( cell , false ) ) }
734807 </ div >
735808
@@ -803,7 +876,7 @@ export const BackgammonBoard = () => {
803876 ) }
804877 { winner === 0 && (
805878 < div className = "flex items-center gap-3" >
806- < div className = "text-xl font-bold text-amber-900" > ХОДИТ :</ div >
879+ < div className = "text-xl font-bold text-amber-900" > ХОД :</ div >
807880 { isItBlackTurn ? (
808881 < div className = "w-10 h-10 rounded-full bg-gray-800 border-2 border-gray-900 shadow-md flex items-center justify-center" >
809882 < div className = "w-6 h-6 rounded-full bg-gray-900" > </ div >
@@ -828,40 +901,6 @@ export const BackgammonBoard = () => {
828901 ⚠️ Сначала верните фишки с бара (поле 25)!
829902 </ div >
830903 ) }
831- { ( ( isItBlackTurn && blackDiceRolled ) || ( ! isItBlackTurn && whiteDiceRolled ) ) && (
832- < div className = "flex flex-col gap-2" >
833- < div className = "text-xl font-bold text-amber-900" > ХОДЫ:</ div >
834- < div className = "flex gap-2" >
835- { ( isItBlackTurn ? blackAvailableMoveValues : whiteAvailableMoveValues ) . map ( ( value , index ) => (
836- < Image key = { index } src = { `/${ value } .png` } alt = { `Dice ${ value } ` } width = { 48 } height = { 48 } />
837- ) ) }
838- </ div >
839- </ div >
840- ) }
841- { ( ( isItBlackTurn && ! blackDiceRolled ) || ( ! isItBlackTurn && ! whiteDiceRolled ) ) && (
842- < button
843- className = "btn btn-primary"
844- onClick = { async ( ) => {
845- try {
846- if ( isItBlackTurn ) {
847- await writeBackgammonAsync ( {
848- functionName : "rollDiceBlack" ,
849- } ) ;
850- } else {
851- await writeBackgammonAsync ( {
852- functionName : "rollDiceWhite" ,
853- } ) ;
854- }
855- } catch ( error ) {
856- console . error ( "Error rolling dice:" , error ) ;
857- const userMessage = parseErrorMessage ( error ) ;
858- notification . error ( userMessage ) ;
859- }
860- } }
861- >
862- Кинуть кости
863- </ button >
864- ) }
865904 </ >
866905 ) }
867906 </ div >
0 commit comments