Pie Rule

Game development with Board Game Arena Studio
Post Reply
User avatar
ZPolansky
Posts: 5
Joined: 08 December 2013, 19:56

Pie Rule

Post by ZPolansky »

Hello!

I am currently working on a game with BGAstudio, and I am almost done, but I have one rule left to implement.
It's the "Pie rule", where the player to go second may choose, after the first move only, to go first and take the opponent's move as their own.
This is seen in games like Hex and Kalah already on here.

Currently, I have made the appropriate game states and buttons and have those working, I just need to switch the players when necessary.
I have:

Code: Select all

$sql = "UPDATE player SET player_color = '000000' WHERE player_color = 'AAAAAA'"; //000000 is a tempcolor, to switch AAAAAA and 555555
self::DbQuery( $sql );
$sql = "UPDATE player SET player_color = 'AAAAAA' WHERE player_color = '555555'";
self::DbQuery( $sql );
$sql = "UPDATE player SET player_color = '555555' WHERE player_color = '000000'";
self::DbQuery( $sql );
but that seems to only switch the players' scores, and not the colors for the player panels. I don't really know how to mess around with the player panels, or anything like that. Anyone know what I should be doing?
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Pie Rule

Post by Rudolf »

Hello,
bravo for your work...
first an advice:
maybe you could use WHEN and THEN in your mysql request to make only one call to db
set color = WHEN ..... THEN .... WHEN ... THEN

with that, no need of tempcolor...

second don't you forget to notify change and manage the change in javascript file ?
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Pie Rule

Post by Rudolf »

Code: Select all

$sql = "UPDATE player SET player_color = CASE  player_color  WHEN 'AAAAAA' THEN '555555'  WHEN '555555' THEN 'AAAAAA' END WHERE player_color in( '555555','AAAAAA') ";


WHERE is there to optimize search speed but not essential...
User avatar
ZPolansky
Posts: 5
Joined: 08 December 2013, 19:56

Re: Pie Rule

Post by ZPolansky »

Thank you for the advice. However, my main problem is how to swap the players (e.g. the colors of the names on the player panels).
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: Pie Rule

Post by Rudolf »

As I said, you have to play with javascript code (not only php) ;):
launch a notify from php (for example notifyallplayers ('changecolors',....
and manage notify_changecolors in your javascript file to change
after setup, php is not synchronized with javascript until next refresh /F5...
you can also force a F5...another trick.
User avatar
ZPolansky
Posts: 5
Joined: 08 December 2013, 19:56

Re: Pie Rule

Post by ZPolansky »

Yes I understand that, but I don't know how to make the player panels change color. I can't find what makes them the colors they are.

Even with the database player_color swapped, even if the js goes through a refresh, the player panels remain the same.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Pie Rule

Post by Een »

Hello JackLance,

This works well in Hex, so I gave your read access to Hex in the studio so that you can look how it was done (I think it will be quicker if you take a look directly at an example ;) )

Cheers,
Een
User avatar
ZPolansky
Posts: 5
Joined: 08 December 2013, 19:56

Re: Pie Rule

Post by ZPolansky »

Thanks, that was very helpful! :)
Post Reply

Return to “Developers”