Skip to content

boardObject ( For Board Games )

Arshia edited this page Aug 28, 2021 · 2 revisions

There Is a boardObject That You Can Work With Boards With This Objects Easier Than Before.


Way To Use :

var player = new boardObject("board");
player.[function]();

Everything In gameObjects Can Be Used Here Too.

All Methods Are Here :

banCell( cell [ The Cell That You Want To Ban ( Make It Read Only ) ] )

     Ban A Cell And Make It Read Only For Some Games Like XO .


openCell( cell [ The Cell That You Want To open ( Make It Normal ) ] )

     Remove The Ban Mode From A Cell And Make It Writable Again.


banIndex( cell [ Get Index From banned Array ] )

     It Will Check If The Cell Is Banned Or Not. If Its Banned It Will Return -1 Else Return The Index In Banned Array.


releaseBans( )

     It Will Remove All Ban Modes From Board. ( Not Remove Data And Text From Board. )


updateData( )

     It Will Update Some Data. ( htmls , texts ).


addText(cell,text,css_class,center)

     Add A Text To Specific Cell Of A Board. ( cell Is Just Place Object Like document.getElementsById("id") Or $("id") Magic Of JSHA XD ) css_class can be list of css classes or one class to set for texts. center will specify that texts will be in center of cell or not.


setText(cell,text,css_class)

     This Will Act Better That addText. Because After Once That You Added A Text, addText Will Not Do What You Want XD. Better That Use setText ( Default Text Is In Center ).


getText(cell);

     Just Get Text Of A Cell.


canEdit(cell,can);

     It Will Make A cell Uneditable. The can Is A Boolean That Specify User Can Edit ( Add Or Set A Text ) To This Cell Or Not.


clear() / clearBoard()

     It Will Clears The Board.


getStatus()

     It Will Give You A JSON That Contains Status Of Game. ( Banned Cells , Width , Height , texts ( A List Of Cells Texts ) , htmls ( A List Of cells HTMLs. ) )


finishCondition(func)

     If "func" is A Function It Will Run This { func(board.getStatus()) }. And Your Function Will RunLike This And Give Status Like This. But If "func" is a string It Will Try To Specify Your Game Type That You Told JSHA To Check For You. Now Just There Is One Option ( "xo" ) Game That Will Report You Winner.


An Example Of Using :

var board = new boardObject("board",3,3,"100px","100px","rgb(255,0,0)",test);

It Will Convert A div Into A Board That Is 3 * 3 And Each Cell Has 100px For Width And 100px For Height And The Color Will Be Red. test Is Just A Function That Will Be Called In Each Click.


You Can Access To The Html Object Like That :

var a = new boardObject("test");
->a.object

You Can Find If Object Is boardObject Like That :

var a = new boardObject("test");
->a.type // If Returns "boardObject" , That's It ! Else Its Not A boardObject.