<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.doc.boardgamearena.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Grandepezzin</id>
	<title>Board Game Arena - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.doc.boardgamearena.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Grandepezzin"/>
	<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/Special:Contributions/Grandepezzin"/>
	<updated>2026-09-21T17:50:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.0</generator>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11482</id>
		<title>Create a game in BGA Studio: Complete Walkthrough</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11482"/>
		<updated>2022-01-20T07:56:21Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This document is not a tutorial, but step by step instructions on how to build your own first game adaptation using BGA Studio framework.&lt;br /&gt;
&lt;br /&gt;
Before you read this material, you must:&lt;br /&gt;
* Read the overall presentations of the BGA [[Studio]].&lt;br /&gt;
* Some-what know the languages used by BGA Studio: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
* Create a game using one of the available tutorials. Don&#039;t bother with a new game if you have not completed at least one of the tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck or have questions about this page post on [https://forum.boardgamearena.com/viewforum.php?f=12 BGA Developers forum].&lt;br /&gt;
If you&#039;re uncomfortable posting on the public forum you can send messages directly to developers who post answers on that forum but NOT the BGA admins.&lt;br /&gt;
If you find typos in this wiki - fix it.&lt;br /&gt;
&lt;br /&gt;
== Select a First Game ==&lt;br /&gt;
&lt;br /&gt;
For your first &#039;&#039;&#039;real&#039;&#039;&#039; game you must either&lt;br /&gt;
* Select a game from [https://en.studio.boardgamearena.com/licensing Available Licenses]&lt;br /&gt;
* Or from the Public Domain&lt;br /&gt;
&lt;br /&gt;
But what if the game you want is not there? If you are able to successfully publish your first game, you would gain the trust of the BGA admins and they will be happy to assist you in obtaining a license for a game you really want to do or you can request a license yourself. You can read more about game licenses on [[BGA Game licenses]] page.&lt;br /&gt;
&lt;br /&gt;
Once you selected the game but before creating a new project, please take a few seconds to check that someone is not already developing this game. If it is the case, maybe you can propose to join the project?&lt;br /&gt;
&lt;br /&gt;
[http://en.studio.boardgamearena.com/#!projects Check the list of current projects]&lt;br /&gt;
&lt;br /&gt;
Even if you see a few projects with name of the game they may not be active. There are a lot of abandoned game projects. If it&#039;s not clear by the status, post to Developers forum asking if anybody is actively working on the project or send a message to the developers listed for the abandoned projects, and at the same time ask admins on the same forum post to send you graphics for that game if they have them (there a button on [https://en.studio.boardgamearena.com/licensing Available Licenses] page to request graphics, but it will just send an email).&lt;br /&gt;
&lt;br /&gt;
If your goal was to fix bugs in an existing project, first try to locate it on Studio, projects developed by BGA admins are not in the Studio. Then get read only access to the project and you can create your own as a copy of the existing one. Contact existing project admin about getting write access to the original project or if they are willing to take your patches - apply them.&lt;br /&gt;
&lt;br /&gt;
If you want to take over an existing project first ask on the forum to see if project is abandoned, then get read only access (via project list) and see if this worth using it, if it has no code or graphics just start from the scratch, don&#039;t worry about project name it can be renamed later.&lt;br /&gt;
&lt;br /&gt;
== Create a project ==&lt;br /&gt;
&lt;br /&gt;
If you have not already, you have to create a project in BGA Studio for this game. If the original game name is taken use gamenameYOURINITIALS&lt;br /&gt;
template, i.e.&amp;quot;heartsla&amp;quot;. Don&#039;t worry too much about the name, if game would be good enough to be publish it will be renamed to original name. &lt;br /&gt;
&lt;br /&gt;
Find and start the game in turn based mode, make sure it works.&lt;br /&gt;
&lt;br /&gt;
Second, modify the text in .tpl file, reload the page in the browser and make sure your ftp sync works as expected.&lt;br /&gt;
Note: if you have not setup [http://en.doc.boardgamearena.com/Tools_and_tips_of_BGA_Studio#File_Sync FTP auto-sync] yet, do it now, manually copying files is a no-starter.&lt;br /&gt;
&lt;br /&gt;
Update your project status in [http://en.studio.boardgamearena.com/#!studio Control Panel &amp;gt; Manage games] page, you can say &amp;quot;development started&amp;quot; or &amp;quot;waiting for license&amp;quot; or &amp;quot;waiting for graphics&amp;quot; or combination of those.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Development Tools ==&lt;br /&gt;
&lt;br /&gt;
At some point you need to setup your development environment which consist of multiple tools, such as&lt;br /&gt;
* Editor or IDE&lt;br /&gt;
* Browser with dev tools&lt;br /&gt;
* File sync tools&lt;br /&gt;
* BGA Web tools&lt;br /&gt;
* Image manipulation tools&lt;br /&gt;
* Version control tools&lt;br /&gt;
&lt;br /&gt;
Please scan though articles from [[Studio#BGA_Studio_user_guide]] especially related to debugging and tools, there is a lot of useful info there.&lt;br /&gt;
&lt;br /&gt;
== Hook version control system ==&lt;br /&gt;
&lt;br /&gt;
If it&#039;s a real game, I would commit the code to version control right at start. You are going to find yourself in the situation when the game does not even start anymore and there is no way of debugging it unless you have a way to revert. That is where version control becomes very handy.&lt;br /&gt;
If you don&#039;t know what I am talking about then at least back-up your files after each of major steps. Starting now.&lt;br /&gt;
You can also create a project on github, but make sure &#039;&#039;&#039;you don&#039;t commit original publisher graphics files&#039;&#039;&#039; and &#039;&#039;&#039;you don&#039;t include a file with your sftp password&#039;&#039;&#039; (github is automatically crawled for passwords by hackers; a hacking attempt occurred on BGA studio for this reason in June 2020).&lt;br /&gt;
You can (and should) also commit your modification periodically via Studio Control Panel.&lt;br /&gt;
&lt;br /&gt;
== Obtain game graphics ==&lt;br /&gt;
&lt;br /&gt;
If you developing a game from Available Licenses games, ask the admins to send you graphics by contacting studio@boardgamearena.com. While that request is being processed (it can take time, as it often requires some back and forth  between the admins and the publishers) you can proceed to next step - project creation.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t get original graphics you go to &#039;&#039;&#039;Scavenger Hunt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you developing a public domain card game you can borrow standard cards from BGA generic assets, see [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Standard game pieces - meeples, cubes, dice can be found here as well [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Go to boardgamegeek.com find your game and obtain 3D game box image, 2D box image, and if you lucky they also sometime have boards and token scans in &amp;quot;Game Pieces&amp;quot; section of Images&lt;br /&gt;
* If that fail google &amp;quot;boardgame &amp;lt;name&amp;gt;&amp;quot; and check Images section&lt;br /&gt;
* Get the rules PDF as well, there tools that allows you to extract graphics from PDF, which usually good for meeples, cubes and such (can use pdfimages command line tool)&lt;br /&gt;
&lt;br /&gt;
Once you get the graphics one way or another you have to massage it to fit in the BGA criteria, which usually involves&lt;br /&gt;
* If publisher sends graphics in one token/card per file mode, you have to stitch them in sprite and scale down&lt;br /&gt;
* For non square tiles and game pieces you need transparency&lt;br /&gt;
* Usually you chop off scoring &amp;quot;ring&amp;quot; around the board of the game since scoring track not needed for online adaptation&lt;br /&gt;
&lt;br /&gt;
More details about graphics requirements can be found here [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
[[File:Rrr_search.png]]&lt;br /&gt;
&lt;br /&gt;
== Obtain game documentation ==&lt;br /&gt;
&lt;br /&gt;
Also at this time obtain a electronic copy of rules, such as PDF (English version). &lt;br /&gt;
&lt;br /&gt;
Also grab any other documents you may find on boardgamegeek such as FAQ, additional Reference books, and user created assistant documents, such&lt;br /&gt;
as cheat-sheets (may be easier to get a data from these then trying to scrub pdf). You create and place them in the doc/ folder of the project then&lt;br /&gt;
exclude them from version control. There is also a misc/ folder now but it will hold up to 1 Mb of data files which would be checked in, so rules pdf&#039;s may not fit there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Update game infos and box graphics ==&lt;br /&gt;
&lt;br /&gt;
Even it does not nothing yet start with making sure game looks descent in the game selector, meaning it has nice box graphics and information is correct. &lt;br /&gt;
&lt;br /&gt;
For that we need to edit [[Game_meta-information: gameinfos.inc.php|gameinfos.inc.php]].&lt;br /&gt;
What you would do for real game you would go to http://boardgamegeek.com find the game and use the information from web-site to fill the gameinfos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step is to replace game_box.png with proper images, usually you can find all images including publisher logo on boardgamegeek website.&lt;br /&gt;
&lt;br /&gt;
Details about images can be found here: [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
Now important step. You have to LOAD these files in studio website through control panel. So go to Control Panel -&amp;gt; Manager Games -&amp;gt; YOURPROJECT&lt;br /&gt;
and press Reload for &#039;Reload game informations&#039; and &#039;Reload game box image&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Gamepanel_sharedcode.png]]&lt;br /&gt;
&lt;br /&gt;
Now try to start the game again. If you some-how introduced a syntax error in gameinfos file it may not actually work (game won&#039;t start).&lt;br /&gt;
Always use &amp;quot;Express Start&amp;quot; button to start the game. You should see a standard state prompt from template. You should see X players on the right, testdude0 .. testdudeX-1.&lt;br /&gt;
To switch between them press the red arrow button near their names, it will open another tab. This way you don&#039;t need to login and logout from multiple accounts!&lt;br /&gt;
&lt;br /&gt;
== Fix source copyright ==&lt;br /&gt;
&lt;br /&gt;
Now since you have your own project, you want put your name in the copyright header, so replace&lt;br /&gt;
&lt;br /&gt;
  © &amp;lt;Your name here&amp;gt; &amp;lt;Your email address here&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
  © John Snow &amp;lt;jsnow@gameofthrones.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well not exactly this but whatever your real name is. For all files in project directory, its about 10 files. Make sure project still starts after that :)&lt;br /&gt;
&lt;br /&gt;
== Reduce the Rules ==&lt;br /&gt;
&lt;br /&gt;
Programming a game will take a lot more time than you may think. Most of the projects in the studio are abandoned because of lack of patience or skill.&lt;br /&gt;
To keep sane, start the game with *reduced* rules and try to complete that first.&lt;br /&gt;
&lt;br /&gt;
* If it has any expansions - do not even attempt to deal with them, not even - &amp;quot;I will just add graphics for them now and not use&amp;quot; - waste of time if you don&#039;t complete basic&lt;br /&gt;
* If it has advanced rules - start with basic rules only, i.e. &amp;quot;beginner game&amp;quot;&lt;br /&gt;
* If it has special rules for 2 player vs 4, start with most basic form (i.e. 4), restrict to 4 players &lt;br /&gt;
* If it has 50 unique cards of 2 each - start with 2 unique cards with 25 each (just to keep it moving)&lt;br /&gt;
* Any sort of rules that you think can be removed and not included in base - set aside for now &lt;br /&gt;
* Ignore any sort of cool animations - dice rolling, card flipping, choo-choo sounds of the trains - all this fluff can be added later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Game Elements ==&lt;br /&gt;
Technically game elements are already designed by board game designer but your job is to map it to program space.&lt;br /&gt;
Each physical piece (card, token, cube) will leave footprints all over the code (unfortunatly in multiple disconnected places).&lt;br /&gt;
To prepare the game you need to sort out these elements, i.e. categorize. I usually have to the following categorization (in object oriented view):&lt;br /&gt;
* Instance - all individual pieces are instances, i.e. two red cubes are two instances of &#039;red cube&#039; type (class)&lt;br /&gt;
* Type - element type which distinctly represents that element in appearence (i.e. red cube is different type than blue cube)&lt;br /&gt;
* Super Type - one of more common types that similar properties (i.e. red OR cube)&lt;br /&gt;
* Player color - supertype specific for player color (sometimes there is no colors but like player 1 - but is conceptually the same, I use color because its easier to track)&lt;br /&gt;
&lt;br /&gt;
Personally I like to encode my elements in string using reverse dns notation listing all the properties above, i.e.&lt;br /&gt;
  meeple_ff0000_7 - this is instance #7 of type meeple_ff0000 (red meeple)&lt;br /&gt;
Or&lt;br /&gt;
  card_yellow_magic_2 - this is instance #2 of yellow card (in this case yellow is color of deck not related to player color) that can do magic&lt;br /&gt;
&lt;br /&gt;
So every game element would be in the&lt;br /&gt;
&lt;br /&gt;
1. Database - instances. The db record would be something like &lt;br /&gt;
  key|location|state&lt;br /&gt;
  meeple_ff0000_7|slot_action_2|1&lt;br /&gt;
  meeple_ff0000_2|tableau_ff0000|0&lt;br /&gt;
2. Material file - types and supertypes, we never need repeating info here, so never list individual instances but only types or supertypes, in this case we don&#039;t really need to define red meeple vs blue meeple&lt;br /&gt;
  &#039;meeple&#039;=&amp;gt;{&#039;name&#039;=&amp;gt;totranslate(&#039;Meeple&#039;)}&lt;br /&gt;
3. Client (js, css, tpl, etc) - instances and types. For example my meeple will be like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;meeple_ff0000_7&amp;quot; class=&amp;quot;meeple meeple_ff0000&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
with .css something like&lt;br /&gt;
  .meeple { background-image: url(img/tokens.png); width: 2em; height: 2em;}&lt;br /&gt;
  .meeple_ff0000 {background-position: 20% 0%;}&lt;br /&gt;
4. Game php - setup and logic. During setup you have to generate all the pieces and place them in right positions. Also sometimes you need to reference elements to code the logic (I usually try to encode all rules in material file as much as possible)&lt;br /&gt;
&lt;br /&gt;
For complex card games I think it is the best to keep all these info and rules in spreadsheet and generate other files such as material.inc.php.&lt;br /&gt;
See more info below about design of the individual layers.&lt;br /&gt;
&lt;br /&gt;
== Create Initial Layout and Game Graphics ==&lt;br /&gt;
&lt;br /&gt;
Mentally it is easier to start with game layout and graphics pieces. Even when nothing is working its give you moral satisfaction!&lt;br /&gt;
&lt;br /&gt;
There are a few ways how the html could have been generated. You could have started with nothing and generate&lt;br /&gt;
it all by javascript, or you could have started with complete game markup in html and make javascript just hide and move pieces around. BGA framework also provides a third way, which is mix of both, plus a template engine to generate HTML using PHP. The only thing that is really annoying about the template engine is that you cannot put any translatable strings in the template (which means any visible text at all). If you are using the template approach all strings have to extracted as variables and injected through PHP (.view.php). This page explains the template engine in great detail:[[Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl|Template Engine]].&lt;br /&gt;
&lt;br /&gt;
The other disadvantage of the template engine is you cannot run and debug it locally, in the beginning of development it&#039;s a lot faster run off local pages, &lt;br /&gt;
you can do it with some trickery described here [[Tools_and_tips_of_BGA_Studio#Speed_up_CSS_development_and_layout|Tools and Tips for BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
During this step you have to decide what technical solutions you will be using, such as&lt;br /&gt;
* Use inline positioning of all moving pieces, controlled by JS. There are a few classes that already exist in Studio to help with that (see [[Studio#Game_interface_.28Client_side.29|Game Interface - Client Side]]). OR use html/css layout engine to position pieces (my personal choice).&lt;br /&gt;
* Use BGA template engine OR create all ui elements by JS OR manually write or generate complete html markup. The game usually contain 200-300 pieces, it seems wrong but actually its faster to type all of this up in html/css when trying write than debug code for page generator.&lt;br /&gt;
Static HTML markup also means you have to use players color or abstracted player number (such as red is 1, blue is 2) not player id&#039;s anywhere in JS, since player id is dynamic by nature.&lt;br /&gt;
&lt;br /&gt;
Start by creating and mapping all games assets, best way is probably to open rule book on &amp;quot;boardgame contents&amp;quot; page and go through every piece. Every pieces of boardgame would have its &amp;quot;print&amp;quot; in multiple files in your game:&lt;br /&gt;
* Some sort if &amp;quot;div&amp;quot; in html, where id of element match id of element in database (easiest way)&lt;br /&gt;
* Css for the element (either unique or for class), usually with background propery refering to part of sprite image&lt;br /&gt;
* Entry in material.inc.php referring to static properties of the element, i.e. name, tooltip, rules, etc&lt;br /&gt;
* Entry in .tpl file to represent static or initial location on the table OR creation template&lt;br /&gt;
&lt;br /&gt;
Here are some specific examples:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create entry in .tpl file for the board, it will be static entry as we never need to create this dynamically&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;board&amp;quot; class=&amp;quot;board shadow board4p&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create entry in .css file for this board and other board variants (in example below we have 4 ppl board whcih is diffrent than 2 ppl board)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.board {&lt;br /&gt;
	position: relative;&lt;br /&gt;
	width: 980px;&lt;br /&gt;
	height: 433px;&lt;br /&gt;
	margin-bottom: 5px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.board4p {&lt;br /&gt;
	background-image: url(img/board4p.jpg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That would be pretty much it for the board itself, as it does not really need a tooltip so we don&#039;t need entry in material.inc.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board Slots&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are interactive areas on the board, usually illustrated as such. In most cases you can get away with rectangular shapes, but sometimes you have to create circle or oval shapes (and in really advanced case would be some svg paths). For slots you can do the following:&lt;br /&gt;
&lt;br /&gt;
Entry in material.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;token_types = array(&lt;br /&gt;
...&lt;br /&gt;
&#039;slot_action_2&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;type&#039; =&amp;gt; &#039;slot_action&#039;,&lt;br /&gt;
  &#039;name&#039; =&amp;gt; clienttranslate(&amp;quot;2 Gray Track Advancements&amp;quot;),&lt;br /&gt;
  &#039;tooltip&#039; =&amp;gt; clienttranslate(&amp;quot;This action gives you two advancements of gray track. You cannot use this action if you cannot complete all advancements.&amp;quot;),&lt;br /&gt;
  &#039;o&#039;=&amp;gt;&amp;quot;1,0,0,gg&amp;quot;, // automatic rules&lt;br /&gt;
),&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in template inside the &amp;quot;board&amp;quot; div&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;slot_action_2&amp;quot; class=&amp;quot;slot_action_2 slot_action slot_w_1 slot&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in .css with absolute position within the board (its actually better to use percentage - would be easier to scale later)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.slot_action_2 {&lt;br /&gt;
	top: 83px;&lt;br /&gt;
	left: 37px;&lt;br /&gt;
}&lt;br /&gt;
.slot_action {&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	width: 46px;&lt;br /&gt;
	height: 26px;&lt;br /&gt;
	padding: 9px 7px 6px 4px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Meeples&#039;&#039;&#039; - also cards, tokens, other mobile stuff&lt;br /&gt;
&lt;br /&gt;
In CSS these guys will use &amp;quot;sprite&amp;quot; images with transparency, so it will look like this this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	background-image: url(img/tokens.png);&lt;br /&gt;
	width: 25px;&lt;br /&gt;
	height: 25px;&lt;br /&gt;
}&lt;br /&gt;
.meeple_ff0000 { /* red */&lt;br /&gt;
	background-position: 14% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As for creation you can either generate them using template (where whole thing wrapped in template block and {COLOR} replace with all possible colors in .view.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_1&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_2&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can declare a template js var in .tpl file &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    var jstpl_mepple = &#039;&amp;lt;div id=&amp;quot;meeple_${color}_${num}&amp;quot; class=&amp;quot;meeple meeple_${color} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;; // this is in .tpl file at the bottom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and create in js, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 var tokenDiv = this.format_block(&#039;jstpl_mepple&#039;, {&lt;br /&gt;
                                &amp;quot;color&amp;quot; : color,&lt;br /&gt;
                                &amp;quot;num&amp;quot; : i&lt;br /&gt;
                            }); // this in js code somewhere before placing it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you dealing with cards and decks, there are pre-build components that can generate stuff for you.&lt;br /&gt;
&lt;br /&gt;
When do you create dom element matching game element?&lt;br /&gt;
* If you have static layout you create it in .tpl file and its always there, but during initial setup or during notification it moved in proper spot (including &amp;quot;removed from the game&amp;quot; spot)&lt;br /&gt;
* If you dynamically generated pieces you create the element during notification, and sometimes during animation. Also don&#039;t forgot to hook event listener to it if its interactive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One of the greatest parts about the web is all client side code can be viewed in your browser, so if you wondering how something is done in another BGA game just load the page and spy on it! In Chrome that would be right click and &amp;quot;Inspect Element&amp;quot;. That would immediately show html of the given element alongside with css used for it (on the right). Another great way to learn is you can add yourself to any BGA project as read only from the project page!&lt;br /&gt;
&lt;br /&gt;
So at the end of this stage you should complete the following (keeping in mind reduced rules/material for first iteration):&lt;br /&gt;
* Create a layout of the game, with positioning of main board, player areas, zones, other supporting areas, etc&lt;br /&gt;
* Create css and html snippets for all game pieces: boards, tokens, meeples, etc. Place them all in initial template (even if they&#039;re not supposed to be visible at start). I.e. create fake player&#039;s hand with cards, put meeples on the board&lt;br /&gt;
* Hook layout to number of players and colors picked by the game and test with multiple players&lt;br /&gt;
* Figure out what you want to display in mini-player boards and hook it up&lt;br /&gt;
* Create material.inc.php and populate with initial values (names, tooltips, rules) for all relevant game elements or classes of elements&lt;br /&gt;
&lt;br /&gt;
If at this time you don&#039;t have graphics yet create pieces with just CSS, you can use shape, background color and object text using css ::after construct to fake the pieces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Injected_text.png]]&lt;br /&gt;
&lt;br /&gt;
== Hook Input and Animation ==&lt;br /&gt;
&lt;br /&gt;
This step can be done before or after some of the server steps, or you go in iterations switching back and forward until you get it done, up to you.&lt;br /&gt;
&lt;br /&gt;
At this time you want to hook clicking on pieces and buttons and provide some reaction, such of moving a piece. The handler code will be replaced later by the server hook, but at the beginning you want your game to be alive as early as possible. &lt;br /&gt;
&lt;br /&gt;
Usually all pieces will be hooked to onclick during JS &amp;quot;setup&amp;quot; method, in addition if you create elements during server notification they have to be hooked up at that time.&lt;br /&gt;
&lt;br /&gt;
You can play with animation effects you want put in place, in general all the pieces that move in real game should be moving, such as meeples, resources tokens/cubes, cards, vp tokens. &lt;br /&gt;
Regular piece animation is provided by BGA framework, but if you use html layout positioning not inline positioning you have to remove absolute positions (inline position styling) after each move. The set of functions for relative position token animation can found in https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js &lt;br /&gt;
&lt;br /&gt;
Also its a good idea to give player a visual cues on what game elements are clickable now, usually it will be a style, such as &amp;quot;active_slot&amp;quot;, with visual effect of white dashed outline (outline is better then border, because border changes will make piece slightly move since it changes the size) or box-shadow (i.e. neon glow)&lt;br /&gt;
&lt;br /&gt;
If you read [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] you know that you should not get carried away with animation, you are creating a board game not a video game... That also applies to sound effects (in general, you should not use any sounds effects beside already provided by framework).&lt;br /&gt;
&lt;br /&gt;
See [[Game_interface_logic:_yourgamename.js#Players_input|Player&#039;s Input]] and [[Game_interface_logic:_yourgamename.js#Access_and_manipulate_the_DOM|Animation and DOM Manipulation]] for JS reference.&lt;br /&gt;
&lt;br /&gt;
== Create Database Schema ==&lt;br /&gt;
&lt;br /&gt;
At some point you have to design your game database. Do it sooner then later since it would be harder to change it later, since some&lt;br /&gt;
code decisions would be based on that.&lt;br /&gt;
&lt;br /&gt;
If you have grid-based abstract game use template from reversi, if you have a card game use template from hearts (the cards one also commented out in generated template for your project). The cards database goes with php class called [[Deck]].&lt;br /&gt;
&lt;br /&gt;
In general make it as simple as possible. &lt;br /&gt;
Think about it, your game has 300 pieces (likely less). Using database to store this amount of data is like shooting a mosquito with a tank.&lt;br /&gt;
Anything more complex then one table with 5 columns or two tables will only going to make it harder to develop and not improve performance.&lt;br /&gt;
You can forget about normalising and any fancy stuff you learn about databases in school. String field for a primary key would be as fast as integer when we talking about this size of data. So don&#039;t over-optimize with trying to have integers field that have state based on bitmask!&lt;br /&gt;
&lt;br /&gt;
Also remember that static (non dynamic) information about the game does not need to be stored in the database, that all include everything that does not change, i.e&lt;br /&gt;
all token/card properties such as name, tooltips, &amp;quot;strength&amp;quot;, color, etc. This is stored in material.inc.php and server has access to it from anywhere, as well as client&lt;br /&gt;
if you send it with getAllDatas(). The only reason store some of it in database if it can affect your queries (i.e. type of token).&lt;br /&gt;
&lt;br /&gt;
Usually design process will contain the following steps:&lt;br /&gt;
* Design game model - model that represent your game in progress, such as at any given step you can restore the game from that model&lt;br /&gt;
* Mapping - now map real game to that model&lt;br /&gt;
* Encoding - now represent this model in database and material file with reasonable amount of fields&lt;br /&gt;
&lt;br /&gt;
Example: &#039;&#039;&#039;The card game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but as part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in your database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
* The card state is very simple, it&#039;s usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position itself usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what info changes and what info is static, static info is always candidate for material file or html&lt;br /&gt;
* For dynamic stuff we should try to reduce amount of fields we need, i.e. we need a field for card, so its one, we need to know what zone cards belong to, its 2, and we have possible few other fields, but if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face  down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
You can also use cards database schema and [[Deck]] implementation for most purposes (even you not dealing with cards).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another Example: &#039;&#039;&#039;The euro game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based &lt;br /&gt;
games can be in most case represented by (string: token_key, string: location, int: state), example of such database schema can be found here:&lt;br /&gt;
[https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php tokens.php].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See [[Game database model: dbmodel.sql]] for details about editing the file.&lt;br /&gt;
&lt;br /&gt;
Note: the simpler the database is the less debugging of db issues you have to deal with including database migration. The tokens database above - if you use it you never have to worry about migration because you don&#039;t need extra tables in 95% of the games.&lt;br /&gt;
Here are some example of how real games are mapped to such database:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chess&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
- chess is grid base game and normally you would use positional columns, but just for the sake of argument, the chess game will look like this&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_white&lt;br /&gt;
|f3&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|P_black_2&lt;br /&gt;
|c6&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|K_black&lt;br /&gt;
|e8&lt;br /&gt;
|1&lt;br /&gt;
|}&lt;br /&gt;
And the state in this case indicated that kind was moved for example (which means castling cannot be performed)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Classic card game&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Lets pretend we need 2 decks for that game&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_spades_1&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_2&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|2 /* position */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_1&lt;br /&gt;
|tableau_common&lt;br /&gt;
|1 /* face down */&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Eminent Domain (card game)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|card_tech_23&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|1 /* face up */&lt;br /&gt;
|-&lt;br /&gt;
|reource_s_22 /* silicon */&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|2 /*  production state */&lt;br /&gt;
|-&lt;br /&gt;
|fighter_F_1&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also look at other games that use Tokens database and access layer: Nippon, Dungeon Petz, Lewis &amp;amp; Clark, Battleship, Russian Railroads, Khronos&lt;br /&gt;
&lt;br /&gt;
== Implement Game Setup ==&lt;br /&gt;
&lt;br /&gt;
Once you have your database schema you can do a proper game setup. Usually you open rulebook on the &amp;quot;Game Setup&amp;quot; page&lt;br /&gt;
and implement these step by step populating the database (using db access API).&lt;br /&gt;
Game initialization is performed in php method setupNewGame, this method is called once when game table is created.&lt;br /&gt;
Game notifications cannot be sent during this time.&lt;br /&gt;
&lt;br /&gt;
== Implement One time game model synchronisation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now at any point in the game we need to make sure that database information can be reflected back in UI, so we fix getAllDatas function&lt;br /&gt;
to return all possible data we need to reconstruct the game. The template for getAllDatas already taking care of player info, but you &lt;br /&gt;
have to alter it to return all other data from database visible to the &amp;quot;current&amp;quot; player.&lt;br /&gt;
&lt;br /&gt;
After that on the client side we should display this data, so in your .js file in setup function (which is the receiver of getAllDatas) you add calls that handle data send by server, usually by calling animation function such as &amp;quot;placeToken&amp;quot; or &amp;quot;placeCard&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Create State Machine ==&lt;br /&gt;
&lt;br /&gt;
Now you need to create a game state machine. &lt;br /&gt;
&lt;br /&gt;
The state handling spread across 4 files, so you have to make sure all the pieces are connected together.&lt;br /&gt;
The state machine states.inc.php defines all the states, and function handlers on php side in a form of string,&lt;br /&gt;
and if any of these functions are not implemented it would be very hard to debug because it will break in random places.&lt;br /&gt;
&lt;br /&gt;
Please first watch this again [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine  BGA game state machine]&lt;br /&gt;
and then please read [[Your game state machine: states.inc.php]].&lt;br /&gt;
&lt;br /&gt;
Now the state machine should be relatively simple. If you find yourself with machine with more than 20 states its probably not the way to go.&lt;br /&gt;
Not all the player interactions need separate states, a lot of things can be implemented directly on client, i.e. if your player need to select&lt;br /&gt;
a reward token, which offers choice of resource, instead of two states on server just have one state on server and possible few states on client (client side states)&lt;br /&gt;
to collect this info.&lt;br /&gt;
&lt;br /&gt;
== Handle Turn Order ==&lt;br /&gt;
&lt;br /&gt;
If your game goes in clockwise order in natural sitting position nothing really needed you just use standard API and you are good. However if position is complecated&lt;br /&gt;
it may require some trickery.&lt;br /&gt;
&lt;br /&gt;
Usually turn order is done by &amp;quot;game state&amp;quot; (see state machine above). Basically it would be two choices:&lt;br /&gt;
* Turn order depends on game situation (such as we take player with highest number of red cubes)&lt;br /&gt;
* Turn order is custom and assign on previos step - i.e. we not playing in clockwise order anymore. In this case you either need to extend player table with new order info (CANNOT use player_no column) or use order markers that come with game (i.e. marker_ff0000 on position_1). In this we can build player array in right order and pick next player based on previous player using existing helper function such as $this-&amp;gt;createNextPlayerTable($player_ids)&lt;br /&gt;
&lt;br /&gt;
== Implement Notification handling ==&lt;br /&gt;
&lt;br /&gt;
Now to implement things for real we have hook UI actions to ajax calls, and process notifications send by server.&lt;br /&gt;
So previously we hooked onclick js handler right to client animation, in real game its a two&lt;br /&gt;
step operation. When user clicks on something, client sends an ajax call to server, server processes it and updates database, server sends&lt;br /&gt;
notification in response, client hooks animations to server notification. See [[Game_interface_logic:_yourgamename.js#Notifications|JS Notifications]].&lt;br /&gt;
&lt;br /&gt;
Exception to this is client states, if you need to process two step user interaction such as select meeple, place meeple, you may want &lt;br /&gt;
to avoid sending data to server until step is complete (which may involve direct client side animation). See [[BGA_Studio_Cookbook#Multi_Step_Interactions:_Select_Worker.2FPlace_Worker_-_Using_Selection|Multi-Step Interactions]]&lt;br /&gt;
&lt;br /&gt;
Part of the sending notifications would be to update player&#039;s scoring, BGA uses standard control for score (on JS side), see [[Game_interface_logic:_yourgamename.js#Update_players_score|Update Player&#039;s Score]].&lt;br /&gt;
&lt;br /&gt;
In BGA there is only two ways interact with the server (officially)&lt;br /&gt;
* Initial data dump - when JS client starts it gets all current data via setup() method&lt;br /&gt;
* Game actions - ajaxcall from client, it returns error or ok (not data), then server send butch of notifications to client&lt;br /&gt;
&lt;br /&gt;
Note current ajaxcall is super vebosy and prone to errors, I suggest to use helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
				if (!args) args = []; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
				&lt;br /&gt;
				args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
&lt;br /&gt;
				if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
					this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
						this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                                handler); // this is real result handler - it called both on success and error, its is optional param - you rarely need it&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you insert a single action you have to update multiples files:&lt;br /&gt;
* in ggg.js add ajaxcall, i.e. something like &lt;br /&gt;
  this.addActionButton(&#039;pass&#039;,_(&#039;Pass&#039;),()=&amp;gt;this.ajaxcallwrapper(&#039;pass&#039;));&lt;br /&gt;
* in states.php - add action &#039;pass&#039; to list of possible actions&lt;br /&gt;
  &#039;possibleactions&#039; =&amp;gt; [&#039;pass&#039;,&#039;playCard&#039;]&lt;br /&gt;
* in action.php - add action hander, see https://en.doc.boardgamearena.com/Players_actions:_yourgamename.action.php&lt;br /&gt;
* in game.php - add action hander, there you must do the following&lt;br /&gt;
** call checkAction to validate the action&lt;br /&gt;
** possible do more game specific check to validate what player doing is legal (even its not possible from your js side - player can cheat - not allow that)&lt;br /&gt;
** do some database maniplations, using access api&lt;br /&gt;
** send notifications - this is the &amp;quot;reply&amp;quot; for action&lt;br /&gt;
** transition to new state (it very rare that  user will remain in the same state, except for multi-active states)&lt;br /&gt;
* back to ggg.js add notification subsciption and notification handler (two separate things)&lt;br /&gt;
&lt;br /&gt;
== Wrap Up ==&lt;br /&gt;
&lt;br /&gt;
* Implement game progression (getGameProgression() in php)&lt;br /&gt;
* Implement Zombie turn  (zombieTurn() in php)&lt;br /&gt;
* Define and implemented some meaningful statistics for your game (i.e. total points, point from source A, B, C...)&lt;br /&gt;
* The games logs should explain what happened if player was not looking&lt;br /&gt;
* You need to implemented tiebreaking (using aux score field) and updated tiebreaker description in meta-data&lt;br /&gt;
* Make sure all UI strings are marked for translation&lt;br /&gt;
* UI elements which are images (i.e. tokens, cards) should have tooltips&lt;br /&gt;
&lt;br /&gt;
== Alpha ==&lt;br /&gt;
When you think you game is completely working there is still bunch of stuff you have to do/check before telling admin that game is ready, please go though this [[Pre-release checklist]].&lt;br /&gt;
&lt;br /&gt;
If you think its completely ready, let admin know (studio@boardgamearena.com) and it they will push it to alpha.&lt;br /&gt;
&lt;br /&gt;
Finally, visit the game page for your alpha game (https://boardgamearena.com/gamepanel?game=…) to add the following information if you can:&lt;br /&gt;
* Links to the rules (in multiple languages if available).&lt;br /&gt;
* Links to teaching videos.&lt;br /&gt;
* In the &amp;quot;On the web&amp;quot; section, links to:&lt;br /&gt;
** The official website for the game (if there is one).&lt;br /&gt;
** The BoardGameGeek page for the game.&lt;br /&gt;
* Consider writing a summary of the rules.&lt;br /&gt;
&lt;br /&gt;
== Level Up ==&lt;br /&gt;
&lt;br /&gt;
When you successfully created a basic game and you want more, it&#039;s time to make it fancy!&lt;br /&gt;
&lt;br /&gt;
* Add game externtions and variants using gameoptions file&lt;br /&gt;
* Add user preferences for customizations&lt;br /&gt;
* Use theming! That involves replacing hardwood background, changing tooltips, using different sounds, different fonts, changing state prompt and logs&lt;br /&gt;
* You can use fancy scoring board at the end of game instead of default nothing&lt;br /&gt;
* And finally super cool dice rolling, card flipping and victory points evaporating effects&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Tutorial_reversi&amp;diff=11481</id>
		<title>Tutorial reversi</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Tutorial_reversi&amp;diff=11481"/>
		<updated>2022-01-20T05:27:16Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* The database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Using this tutorial, you can build a complete working game on the BGA environment: Reversi.&lt;br /&gt;
&lt;br /&gt;
Before you read this tutorial, you must:&lt;br /&gt;
* Read the overall presentations of the BGA Framework ([[Studio|see here]]).&lt;br /&gt;
* Know the [http://en.wikipedia.org/wiki/Reversi#Rules rules of Reversi].&lt;br /&gt;
* Know the languages used on BGA: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
&lt;br /&gt;
== Create your first game ==&lt;br /&gt;
&lt;br /&gt;
With the initial skeleton of code provided initially, you can already start a game from the BGA Studio. For now, we are going to work with one player only. Most of the time it is simpler to proceed with only one player during the early phase of development of your game, as it&#039;s easy and fast to start/stop games.&lt;br /&gt;
&lt;br /&gt;
(If you choose to start with 2 players, you should see two names on the right: testdude0 and testdude1. To switch between them, press the red arrow button near their names; it will open another tab. This way you don&#039;t need to login and logout from multiple accounts.) &lt;br /&gt;
&lt;br /&gt;
Reminder: Always use the &amp;quot;Express Start&amp;quot; button to start the game. &lt;br /&gt;
&lt;br /&gt;
Thus, you can start a &amp;quot;Reversi&amp;quot; game, and arrive on a void, empty game. Yeah.&lt;br /&gt;
&lt;br /&gt;
== Let it look like Reversi ==&lt;br /&gt;
&lt;br /&gt;
It&#039;s always a good idea to start with a little bit of graphic work. Why? Because this helps to figure out how the final game will be, and issues that may appear later.&lt;br /&gt;
&lt;br /&gt;
Be careful designing the layout of your game: you must always keep in mind that players with a 1024px screen width must be able to play. Usually, it means that the width of the play area can be 750px (in the worst case).&lt;br /&gt;
&lt;br /&gt;
For Reversi, it&#039;s useless to have a 750x750px board - much too big, so we choose this one which fit perfectly (536x528):&lt;br /&gt;
&lt;br /&gt;
[[File:Board.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note that we are using a jpg file. Jpg are lighter than png, so faster to load. Later we are going to use PNGs for discs for transparency purpose.&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s make it appear in our game:&lt;br /&gt;
* upload board.jpg in your &amp;quot;img/&amp;quot; directory.&lt;br /&gt;
* edit &amp;quot;reversi_reversi.tpl&amp;quot; to add a &#039;div&#039; for your board.&lt;br /&gt;
&lt;br /&gt;
Note: If you are building this game by following the tutorial, you will have a different project name than &#039;reversi&#039;. The file names in your project will be different than shown in this tutorial, replacing &#039;reversi&#039; with your project name. It should be trivial to find the right file in your project, but be sure that any code (other than comments) that references &#039;reversi&#039; is changed to your actual project name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* edit your reversi.css file to transform it into a visible board:&lt;br /&gt;
&lt;br /&gt;
 #board {&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Refresh your page. Here&#039;s your board:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi1.jpg]]&lt;br /&gt;
&lt;br /&gt;
If the board does not appear, check the image filename. Remember file names are case sensitive!&lt;br /&gt;
&lt;br /&gt;
== Make the squares appear ==&lt;br /&gt;
&lt;br /&gt;
Now, we need to create some invisible HTML elements where squares are. These elements will be used as position references for white and black discs. &lt;br /&gt;
We need 64 squares. To avoid writing 64 &#039;div&#039; elements on our template, we are going to use the &amp;quot;block&amp;quot; feature.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s modify our template like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;board&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- BEGIN square --&amp;gt;&lt;br /&gt;
        &amp;lt;div id=&amp;quot;square_{X}_{Y}&amp;quot; class=&amp;quot;square&amp;quot; style=&amp;quot;left: {LEFT}px; top: {TOP}px;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we created a &amp;quot;square&amp;quot; block, with 4 variable elements: X, Y, LEFT and TOP. We are going to use this block 64 times during page load.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s do it in our &amp;quot;reversi.view.php&amp;quot; file, inside the build_page function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $this-&amp;gt;page-&amp;gt;begin_block( &amp;quot;reversi_reversi&amp;quot;, &amp;quot;square&amp;quot; );&lt;br /&gt;
        &lt;br /&gt;
        $hor_scale = 64.8;&lt;br /&gt;
        $ver_scale = 64.4;&lt;br /&gt;
        for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
        {&lt;br /&gt;
            for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
            {&lt;br /&gt;
                $this-&amp;gt;page-&amp;gt;insert_block( &amp;quot;square&amp;quot;, array(&lt;br /&gt;
                    &#039;X&#039; =&amp;gt; $x,&lt;br /&gt;
                    &#039;Y&#039; =&amp;gt; $y,&lt;br /&gt;
                    &#039;LEFT&#039; =&amp;gt; round( ($x-1)*$hor_scale+10 ),&lt;br /&gt;
                    &#039;TOP&#039; =&amp;gt; round( ($y-1)*$ver_scale+7 )&lt;br /&gt;
                ) );&lt;br /&gt;
            }        &lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: as you can see, squares in our &amp;quot;board.jpg&amp;quot; files do not have an exact width/height in pixels, and that&#039;s the reason we are using floating point numbers here.&lt;br /&gt;
&lt;br /&gt;
Now, to finish our work and check if everything works fine, we are going to style our square a little bit in our CSS stylesheet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#board {&lt;br /&gt;
    width: 536px;&lt;br /&gt;
    height: 528px;&lt;br /&gt;
    background-image: url(&#039;img/board.jpg&#039;);&lt;br /&gt;
    position: relative;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.square {&lt;br /&gt;
    width: 62px;&lt;br /&gt;
    height: 62px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-color: red;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Explanations:&lt;br /&gt;
* With &amp;quot;position: relative&amp;quot; on board, we ensure square elements are positioned relatively to board.&lt;br /&gt;
* For the test, we use a red background color for the square. This is a useful tip to figure out if everything is fine with invisible elements.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s refresh and check our our (beautiful) squares:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi2.jpg]]&lt;br /&gt;
&lt;br /&gt;
If the red squares do not appear, check your css file (Chrome DevTools: Application &amp;gt; Frames &amp;gt; top &amp;gt; Stylesheets &amp;gt; reversi.css). If your changes are not there try clearing your cache!&lt;br /&gt;
&lt;br /&gt;
Hint: Now that we know our squares are set up correctly, we can hide the red background. You can remove the &amp;quot;background-color: red;&amp;quot; line from your .square class in the CSS stylesheet.&lt;br /&gt;
&lt;br /&gt;
== The discs ==&lt;br /&gt;
&lt;br /&gt;
Now, our board is ready to receive some disc tokens!&lt;br /&gt;
&lt;br /&gt;
[Note: Throughout this tutorial, sometimes &amp;quot;tokens&amp;quot; is used, and sometimes &amp;quot;discs&amp;quot; is used. They are often swapped if you&#039;re looking at code in the reversi example project.]&lt;br /&gt;
&lt;br /&gt;
At first, we introduce a new &#039;div&#039; element as a child of &amp;quot;board&amp;quot; to host all these tokens (in our template):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    &amp;lt;!-- END square --&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;div id=&amp;quot;tokens&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s introduce a new piece of art with the discs. We need some transparency here so we are using a png file:&lt;br /&gt;
&lt;br /&gt;
[[File:tokens.png]]&lt;br /&gt;
&lt;br /&gt;
Upload this image file &amp;quot;tokens.png&amp;quot; in your &amp;quot;img/&amp;quot; directory.&lt;br /&gt;
&lt;br /&gt;
Important: we are using ONE file for both discs. It&#039;s really important that you use a minimum number of graphic files for your game with this &amp;quot;CSS sprite&amp;quot; technique, because it makes the game loading faster and more reliable. [http://www.w3schools.com/css/css_image_sprites.asp Read more about CSS sprites].&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s separate the disc with some CSS stuff:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.token {&lt;br /&gt;
    width: 56px;&lt;br /&gt;
    height: 56px;&lt;br /&gt;
    position: absolute;&lt;br /&gt;
    background-image: url(&#039;img/tokens.png&#039;);&lt;br /&gt;
}&lt;br /&gt;
.tokencolor_ffffff { background-position: 0px 0px;   }&lt;br /&gt;
.tokencolor_000000 { background-position: -56px 0px;   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this CSS code, we apply the classes &amp;quot;token&amp;quot; and &amp;quot;tokencolor_ffffff&amp;quot; to a div element and we&#039;ve got a white token. Yeah.&lt;br /&gt;
&lt;br /&gt;
Note the &amp;quot;position: absolute&amp;quot; which allows us to position tokens on the board and make them &amp;quot;slide&amp;quot; to their positions.&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s make a first token appear on our board. Disc tokens are not visible at the beginning of the game: they appear dynamically during the game. For this reason, we are going to make them appear from our Javascript code, with a BGA Framework technique called &amp;quot;JS template&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In our template file (reversi_reversi.tpl), let&#039;s create the piece of HTML needed to display our token:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Templates&lt;br /&gt;
&lt;br /&gt;
var jstpl_token=&#039;&amp;lt;div class=&amp;quot;token tokencolor_${color}&amp;quot; id=&amp;quot;token_${x_y}&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: we already created the &amp;quot;templates&amp;quot; section for you in the game skeleton.&lt;br /&gt;
&lt;br /&gt;
As you can see, we defined a JS template named &amp;quot;jstpl_token&amp;quot; with a piece of HTML and two variables: the color of the token and its x/y coordinates. Note that the syntax of the argument is different for template block variables (braces &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;) and JS template variables (dollar and braces &amp;lt;code&amp;gt;${}&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s create a method in our Javascript code (in the &amp;quot;reversi.js&amp;quot; file) that will make a token appear on the board, using this template. Add under the section //// Utility methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        addTokenOnBoard: function( x, y, player )&lt;br /&gt;
        {&lt;br /&gt;
            dojo.place( this.format_block( &#039;jstpl_token&#039;, {&lt;br /&gt;
                x_y: x+&#039;_&#039;+y,&lt;br /&gt;
                color: this.gamedatas.players[ player ].color&lt;br /&gt;
            } ) , &#039;tokens&#039; );&lt;br /&gt;
            &lt;br /&gt;
            this.placeOnObject( &#039;token_&#039;+x+&#039;_&#039;+y, &#039;overall_player_board_&#039;+player );&lt;br /&gt;
            this.slideToObject( &#039;token_&#039;+x+&#039;_&#039;+y, &#039;square_&#039;+x+&#039;_&#039;+y ).play();&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At first, with &amp;quot;dojo.place&amp;quot; and &amp;quot;this.format_block&amp;quot; methods, we create a HTML piece of code and insert it as a new child of &amp;quot;tokens&amp;quot; div element.&lt;br /&gt;
&lt;br /&gt;
Then, with BGA &amp;quot;this.placeOnObject&amp;quot; method, we place this element over the panel of some player. Immediately after, using BGA &amp;quot;this.slideToObject&amp;quot; method, we make the disc slide to the &amp;quot;square&amp;quot; element, its final destination.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&#039;overall_player_board_&#039;+player&amp;quot; refers to the div element that contains each player&#039;s information and avatar. By initially placing the token here, it gives the effect that the player&#039;s avatar is throwing the token onto the board.&lt;br /&gt;
&lt;br /&gt;
Note: don&#039;t forget to call the &amp;quot;play()&amp;quot;, otherwise the token remains at its original location.&lt;br /&gt;
&lt;br /&gt;
Note: note that during all the process, the parent of the new disc HTML element will remain &amp;quot;tokens&amp;quot;. placeOnObject and slideToObject methods are only moving the position of elements on screen, and they are not modifying the HTML tree.&lt;br /&gt;
&lt;br /&gt;
Before we can show a token, we need to set the player colors in the setupNewGame function in reversi.game.php:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $default_colors = array( &amp;quot;ffffff&amp;quot;, &amp;quot;000000&amp;quot; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Probably you&#039;ll have to remove the line &amp;quot;self::reattributeColorsBasedOnPreferences( $players, $gameinfos[&#039;player_colors&#039;] );&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, to test if everything works fine, just add &amp;quot;this.addTokenOnBoard( 2, 2, [player_id] )&amp;quot; in the &amp;quot;setup&amp;quot; Javascript method in reversi.js, and restart the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A token should appear and slide immediately to its position, like this:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi3.jpg]]&lt;br /&gt;
&lt;br /&gt;
== The database ==&lt;br /&gt;
&lt;br /&gt;
We did most of the client-side programming, so let&#039;s have a look on the other side now.&lt;br /&gt;
&lt;br /&gt;
To design the database model of our game, the best thing to do is to follow the &amp;quot;Go to game database&amp;quot; link at the bottom of our game, to access the database directly with a [http://www.phpmyadmin.net/ PhpMyAdmin] instance. Your PhpMyAdmin username/password is in your welcome email (and currently the same as the SFTP username/password).&lt;br /&gt;
&lt;br /&gt;
Then, you can create the tables you need for your game (do not remove existing tables!), and report every SQL command used in your &amp;quot;dbmodel.sql&amp;quot; file. How do you generate SQL to create table after creating the table in the UI? See [https://www.itsupportguides.com/knowledge-base/tech-tips-tricks/how-to-generate-sql-create-table-script-using-phpmyadmin/ here]. Add &#039;IF NOT EXISTS&#039; to the CREATE TABLE sql (see example below).&lt;br /&gt;
&lt;br /&gt;
[[File:reversi4.jpg]]&lt;br /&gt;
&lt;br /&gt;
The database model of Reversi is very simple: just one table with the squares of the board. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `board` (&lt;br /&gt;
  `board_x` smallint(5) unsigned NOT NULL,&lt;br /&gt;
  `board_y` smallint(5) unsigned NOT NULL,&lt;br /&gt;
  `board_player` int(10) unsigned DEFAULT NULL,&lt;br /&gt;
  PRIMARY KEY (`board_x`,`board_y`)&lt;br /&gt;
) ENGINE=InnoDB;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add the above SQL to dbmodel.sql. Now, a new database with a &amp;quot;board&amp;quot; table will be created each time we start a Reversi game. This is why after modifying our dbmodel.sql it&#039;s a good time to stop &amp;amp; start again our game.&lt;br /&gt;
&lt;br /&gt;
== Setup the initial game position ==&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;setupNewGame&amp;quot; method of our reversi.game.php is called during initial setup: this is the place to initialize our data and to place the initial tokens on the board (initially, there are 4 tokens on the board).&lt;br /&gt;
&lt;br /&gt;
Let&#039;s do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Init the board&lt;br /&gt;
        $sql = &amp;quot;INSERT INTO board (board_x,board_y,board_player) VALUES &amp;quot;;&lt;br /&gt;
        $sql_values = array();&lt;br /&gt;
        list( $blackplayer_id, $whiteplayer_id ) = array_keys( $players );&lt;br /&gt;
        for( $x=1; $x&amp;lt;=8; $x++ )&lt;br /&gt;
        {&lt;br /&gt;
            for( $y=1; $y&amp;lt;=8; $y++ )&lt;br /&gt;
            {&lt;br /&gt;
                $token_value = &amp;quot;NULL&amp;quot;;&lt;br /&gt;
                if( ($x==4 &amp;amp;&amp;amp; $y==4) || ($x==5 &amp;amp;&amp;amp; $y==5) )  // Initial positions of white player&lt;br /&gt;
                    $token_value = &amp;quot;&#039;$whiteplayer_id&#039;&amp;quot;;&lt;br /&gt;
                else if( ($x==4 &amp;amp;&amp;amp; $y==5) || ($x==5 &amp;amp;&amp;amp; $y==4) )  // Initial positions of black player&lt;br /&gt;
                    $token_value = &amp;quot;&#039;$blackplayer_id&#039;&amp;quot;;&lt;br /&gt;
                    &lt;br /&gt;
                $sql_values[] = &amp;quot;(&#039;$x&#039;,&#039;$y&#039;,$token_value)&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        $sql .= implode( &#039;,&#039;, $sql_values );&lt;br /&gt;
        self::DbQuery( $sql );&lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        // Active first player&lt;br /&gt;
        self::activeNextPlayer();  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We create one table entry for each square, with a &amp;quot;NULL&amp;quot; value which means &amp;quot;empty square&amp;quot;. For 4 specific squares, we place an initial token.&lt;br /&gt;
&lt;br /&gt;
At the end, we call activeNextPlayer to make the first player active at the beginning of the game.&lt;br /&gt;
&lt;br /&gt;
You need to remove the call to self::reattributeColorsBasedOnPreferences() in SetupNewGame() so that any player color preferences do not override the two colors supported here.&lt;br /&gt;
&lt;br /&gt;
Now, we need to make these tokens appear on the client side. The first step is to return the token positions with our &amp;quot;getAllDatas&amp;quot; PHP method (called during each page reload):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Get reversi board token&lt;br /&gt;
        $result[&#039;board&#039;] = self::getObjectListFromDB( &amp;quot;SELECT board_x x, board_y y, board_player player&lt;br /&gt;
                                                       FROM board&lt;br /&gt;
                                                       WHERE board_player IS NOT NULL&amp;quot; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We are using the BGA framework &amp;quot;getObjectListFromDB&amp;quot; method that formats the result of this SQL query in a PHP array with x, y and player attributes.&lt;br /&gt;
&lt;br /&gt;
Last, we process this array client side, and place a disc token on the board for each array item. We do this using our Javascript &amp;quot;setup&amp;quot; method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            for( var i in gamedatas.board )&lt;br /&gt;
            {&lt;br /&gt;
                var square = gamedatas.board[i];&lt;br /&gt;
                &lt;br /&gt;
                if( square.player !== null )&lt;br /&gt;
                {&lt;br /&gt;
                    this.addTokenOnBoard( square.x, square.y, square.player );&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our &amp;quot;board&amp;quot; entry created in &amp;quot;getAllDatas&amp;quot; can be used here as &amp;quot;gamedatas.board&amp;quot; in our Javascript. We are using our previously developed &amp;quot;addTokenOnBoard&amp;quot; method.&lt;br /&gt;
&lt;br /&gt;
Reload... and here we are:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi5.jpg]]&lt;br /&gt;
&lt;br /&gt;
It starts to smell Reversi here...&lt;br /&gt;
&lt;br /&gt;
== The game state machine ==&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s stop our game again, because we are going to start the core game logic.&lt;br /&gt;
&lt;br /&gt;
You already read [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine Focus on BGA game state machine], so you know that this is the heart of your game logic. For reversi, it&#039;s very simple. Here&#039;s a diagram of our game state machine:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi6.jpg]]&lt;br /&gt;
&lt;br /&gt;
And here&#039;s our &amp;quot;states.inc.php&amp;quot;, according to this diagram:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$machinestates = array(&lt;br /&gt;
&lt;br /&gt;
    1 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;gameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&amp;quot;Game setup&amp;quot;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stGameSetup&amp;quot;,&lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;&amp;quot; =&amp;gt; 10 )&lt;br /&gt;
    ),&lt;br /&gt;
    &lt;br /&gt;
    10 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;playerTurn&amp;quot;,&lt;br /&gt;
		&amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&#039;${actplayer} must play a disc&#039;),&lt;br /&gt;
		&amp;quot;descriptionmyturn&amp;quot; =&amp;gt; clienttranslate(&#039;${you} must play a disc&#039;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;activeplayer&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot; =&amp;gt; &amp;quot;argPlayerTurn&amp;quot;,&lt;br /&gt;
        &amp;quot;possibleactions&amp;quot; =&amp;gt; array( &#039;playDisc&#039; ),&lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;playDisc&amp;quot; =&amp;gt; 11, &amp;quot;zombiePass&amp;quot; =&amp;gt; 11 )&lt;br /&gt;
    ),&lt;br /&gt;
    &lt;br /&gt;
    11 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;nextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;game&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stNextPlayer&amp;quot;,&lt;br /&gt;
        &amp;quot;updateGameProgression&amp;quot; =&amp;gt; true,        &lt;br /&gt;
        &amp;quot;transitions&amp;quot; =&amp;gt; array( &amp;quot;nextTurn&amp;quot; =&amp;gt; 10, &amp;quot;cantPlay&amp;quot; =&amp;gt; 11, &amp;quot;endGame&amp;quot; =&amp;gt; 99 )&lt;br /&gt;
    ),&lt;br /&gt;
   &lt;br /&gt;
    99 =&amp;gt; array(&lt;br /&gt;
        &amp;quot;name&amp;quot; =&amp;gt; &amp;quot;gameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;description&amp;quot; =&amp;gt; clienttranslate(&amp;quot;End of game&amp;quot;),&lt;br /&gt;
        &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;manager&amp;quot;,&lt;br /&gt;
        &amp;quot;action&amp;quot; =&amp;gt; &amp;quot;stGameEnd&amp;quot;,&lt;br /&gt;
        &amp;quot;args&amp;quot; =&amp;gt; &amp;quot;argGameEnd&amp;quot;&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s create in reversi.game.php the methods that are declared in this game states description file:&lt;br /&gt;
* argPlayerTurn&lt;br /&gt;
* stNextPlayer&lt;br /&gt;
&lt;br /&gt;
... and start a new Reversi game.&lt;br /&gt;
&lt;br /&gt;
As you can see on the screen capture below, the BGA framework makes the game jump to our first game state &amp;quot;playerTurn&amp;quot; right after the initial setup. That&#039;s why the status bar contains the description of playerTurn state (&amp;quot;XXXX must play a disc&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
[[File:reversi7.jpg]]&lt;br /&gt;
&lt;br /&gt;
== The rules ==&lt;br /&gt;
&lt;br /&gt;
We will use the &amp;quot;getPossibleMoves&amp;quot; PHP method to:&lt;br /&gt;
* Indicate to the current player where she is allowed to play by returning a list of coordinates&lt;br /&gt;
* Check if the player has the right to play in the spot they choose&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is pure PHP programming here, and there are no special things from the BGA framework that can be used. This is why we won&#039;t go into details here. The overall idea is:&lt;br /&gt;
* Create a &amp;quot;getTurnedOverDiscs(x,y)&amp;quot; method that returns coordinates of discs that would be turned over if a token would be played at x,y.&lt;br /&gt;
* Loop through all free squares of the board and call the &amp;quot;getTurnedOverDiscs&amp;quot; method on each of them. If at least 1 token is turned over, this is a valid move.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: Keep in mind that making a database query is slow, so please don&#039;t load the entire game board with a SQL query multiple times. In our implementation, we load the entire board once at the beginning of &amp;quot;getPossibleMoves&amp;quot;, and then pass the board as an argument to all methods.&lt;br /&gt;
&lt;br /&gt;
If you want to look into details, please look at the &amp;quot;utility method&amp;quot; sections of reversi.game.php. If building the tutorial yourself, copy the functions under &amp;quot;Utility functions&amp;quot; comment from the Reversi tutorial.&lt;br /&gt;
&lt;br /&gt;
== Display allowed moves ==&lt;br /&gt;
&lt;br /&gt;
Now we want to highlight the squares where the player can place a disc.&lt;br /&gt;
&lt;br /&gt;
To do this, we add a &amp;quot;argPlayerTurn&amp;quot; method in reversi.game.php. This method is called on the server each time we enter into &amp;quot;playerTurn&amp;quot; game state, and its result is transferred automatically to the client-side:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function argPlayerTurn()&lt;br /&gt;
    {&lt;br /&gt;
        return array(&lt;br /&gt;
            &#039;possibleMoves&#039; =&amp;gt; self::getPossibleMoves( self::getActivePlayerId() )&lt;br /&gt;
        );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We use the &amp;quot;getPossibleMoves&amp;quot; method we just developed.&lt;br /&gt;
&lt;br /&gt;
Each time we enter into a new game state, we use the &amp;quot;onEnteringState&amp;quot; Javascript method (in the reversi.js file, under &amp;quot;Game &amp;amp; client states&amp;quot;). This lets us use the data returned by the method above on the client side.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        onEnteringState: function( stateName, args )&lt;br /&gt;
        {&lt;br /&gt;
           console.log( &#039;Entering state: &#039;+stateName );&lt;br /&gt;
            &lt;br /&gt;
            switch( stateName )&lt;br /&gt;
            {&lt;br /&gt;
            case &#039;playerTurn&#039;:&lt;br /&gt;
                this.updatePossibleMoves( args.args.possibleMoves );&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, when we enter into &amp;quot;playerTurn&amp;quot; game state, we call our &amp;quot;updatePossibleMoves&amp;quot; method (under the &amp;quot;Utility functions&amp;quot; section). This method looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        updatePossibleMoves: function( possibleMoves )&lt;br /&gt;
        {&lt;br /&gt;
            // Remove current possible moves&lt;br /&gt;
            dojo.query( &#039;.possibleMove&#039; ).removeClass( &#039;possibleMove&#039; );&lt;br /&gt;
&lt;br /&gt;
            for( var x in possibleMoves )&lt;br /&gt;
            {&lt;br /&gt;
                for( var y in possibleMoves[ x ] )&lt;br /&gt;
                {&lt;br /&gt;
                    // x,y is a possible move&lt;br /&gt;
                    dojo.addClass( &#039;square_&#039;+x+&#039;_&#039;+y, &#039;possibleMove&#039; );&lt;br /&gt;
                }            &lt;br /&gt;
            }&lt;br /&gt;
                        &lt;br /&gt;
            this.addTooltipToClass( &#039;possibleMove&#039;, &#039;&#039;, _(&#039;Place a disc here&#039;) );&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here&#039;s what this does. At first, it removes all &amp;quot;possibleMove&amp;quot; classes currently applied with the very useful combination of &amp;quot;dojo.query&amp;quot; and &amp;quot;removeClass&amp;quot; method.&lt;br /&gt;
&lt;br /&gt;
Then it loops through all possible moves our PHP &amp;quot;updatePossibleMoves&amp;quot; function created for us, and adds the &amp;quot;possibleMove&amp;quot; class to each corresponding square.&lt;br /&gt;
&lt;br /&gt;
Finally, it uses the BGA framework &amp;quot;addTooltipToClass&amp;quot; method to associate a tooltip to all those highlighted squares so that players can understand their meaning.&lt;br /&gt;
&lt;br /&gt;
To see the possible moves we need to create a CSS class (&amp;quot;possibleMove&amp;quot;) that can be applied to a &amp;quot;square&amp;quot; element to highlight it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.possibleMove {&lt;br /&gt;
    background-color: white;&lt;br /&gt;
    opacity: 0.2;&lt;br /&gt;
    filter:alpha(opacity=20); /* For IE8 and earlier */  &lt;br /&gt;
    cursor: pointer;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And here we are:&lt;br /&gt;
&lt;br /&gt;
[[File:reversi8.jpg.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s play ==&lt;br /&gt;
&lt;br /&gt;
From now, it&#039;s better to restart a game with 2 players, because we are going to implement a complete Reversi turn. The summary of what we are going to do is:&lt;br /&gt;
* When we click on a &amp;quot;possibleMove&amp;quot; square, send the move to the server.&lt;br /&gt;
* Server side, check the move is correct, apply Reversi rules and jump to next player.&lt;br /&gt;
* Client side, change the disc position to reflect the move.&lt;br /&gt;
&lt;br /&gt;
First we associate each click on a square to one of our methods using our Javascript &amp;quot;setup&amp;quot; method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            dojo.query( &#039;.square&#039; ).connect( &#039;onclick&#039;, this, &#039;onPlayDisc&#039; );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the use of the &amp;quot;dojo.query&amp;quot; method to get all HTML elements with &amp;quot;square&amp;quot; class in just one function call. Now, our &amp;quot;onPlayDisc&amp;quot; method is called each time someone clicks on a square.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s our &amp;quot;onPlayDisc&amp;quot; method below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        onPlayDisc: function( evt )&lt;br /&gt;
        {&lt;br /&gt;
            // Stop this event propagation&lt;br /&gt;
            dojo.stopEvent( evt );&lt;br /&gt;
&lt;br /&gt;
            // Get the clicked square x and y&lt;br /&gt;
            // Note: square id format is &amp;quot;square_X_Y&amp;quot;&lt;br /&gt;
            var coords = evt.currentTarget.id.split(&#039;_&#039;);&lt;br /&gt;
            var x = coords[1];&lt;br /&gt;
            var y = coords[2];&lt;br /&gt;
&lt;br /&gt;
            if( ! dojo.hasClass( &#039;square_&#039;+x+&#039;_&#039;+y, &#039;possibleMove&#039; ) )&lt;br /&gt;
            {&lt;br /&gt;
                // This is not a possible move =&amp;gt; the click does nothing&lt;br /&gt;
                return ;&lt;br /&gt;
            }&lt;br /&gt;
            &lt;br /&gt;
            if( this.checkAction( &#039;playDisc&#039; ) )    // Check that this action is possible at this moment&lt;br /&gt;
            {            &lt;br /&gt;
                this.ajaxcall( &amp;quot;/reversi/reversi/playDisc.html&amp;quot;, {&lt;br /&gt;
                    x:x,&lt;br /&gt;
                    y:y&lt;br /&gt;
                }, this, function( result ) {} );&lt;br /&gt;
            }            &lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What we do here is:&lt;br /&gt;
* We stop the propagation of the Javascript &amp;quot;onclick&amp;quot; event. Otherwise, it can lead to random behavior so it&#039;s always a good idea.&lt;br /&gt;
* We get the x/y coordinates of the square by using &amp;quot;evt.currentTarget.id&amp;quot;.&lt;br /&gt;
* We check that clicked square has the &amp;quot;possibleMove&amp;quot; class, otherwise we know for sure that we can&#039;t play there.&lt;br /&gt;
* We check that &amp;quot;playDisc&amp;quot; action is possible, according to current game state (see &amp;quot;possibleactions&amp;quot; entry in our &amp;quot;playerTurn&amp;quot; game state defined above). This check is important to avoid issues if a player double clicks on a square.&lt;br /&gt;
* Finally, we make a call to the server using BGA &amp;quot;ajaxcall&amp;quot; method with argument x and y. Be sure to update the first parameter to match your game if building the tutorial yourself. E.g. &amp;quot;/yourgamename/yourgamename/playDisc.html&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now, we have to manage this &amp;quot;playDisc&amp;quot; action on the server side. At first, we introduce a &amp;quot;playDisc&amp;quot; entry point in our &amp;quot;reversi.action.php&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    public function playDisc()&lt;br /&gt;
    {&lt;br /&gt;
        self::setAjaxMode();     &lt;br /&gt;
        $x = self::getArg( &amp;quot;x&amp;quot;, AT_posint, true );&lt;br /&gt;
        $y = self::getArg( &amp;quot;y&amp;quot;, AT_posint, true );&lt;br /&gt;
        $result = $this-&amp;gt;game-&amp;gt;playDisc( $x, $y );&lt;br /&gt;
        self::ajaxResponse( );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we get the 2 arguments x and y from the javascript call, and call a corresponding &amp;quot;playDisc&amp;quot; method in our game logic (reversi.game.php).&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s have a look of this playDisc method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function playDisc( $x, $y )&lt;br /&gt;
    {&lt;br /&gt;
        // Check that this player is active and that this action is possible at this moment&lt;br /&gt;
        self::checkAction( &#039;playDisc&#039; );  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... at first, we check that this action is possible according to current game state (see &amp;quot;possible action&amp;quot;). We already did it on client side, but it&#039;s important to do it on server side too (otherwise it would be possible to cheat).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        // Now, check if this is a possible move&lt;br /&gt;
        $board = self::getBoard();&lt;br /&gt;
        $player_id = self::getActivePlayerId();&lt;br /&gt;
        $turnedOverDiscs = self::getTurnedOverDiscs( $x, $y, $player_id, $board );&lt;br /&gt;
        &lt;br /&gt;
        if( count( $turnedOverDiscs ) &amp;gt; 0 )&lt;br /&gt;
        {&lt;br /&gt;
            // This move is possible!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...now, we are using the &amp;quot;getTurnedOverDiscs&amp;quot; method again to check that this move is possible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Let&#039;s place a disc at x,y and return all &amp;quot;$returned&amp;quot; discs to the active player&lt;br /&gt;
            &lt;br /&gt;
            $sql = &amp;quot;UPDATE board SET board_player=&#039;$player_id&#039;&lt;br /&gt;
                    WHERE ( board_x, board_y) IN ( &amp;quot;;&lt;br /&gt;
            &lt;br /&gt;
            foreach( $turnedOverDiscs as $turnedOver )&lt;br /&gt;
            {&lt;br /&gt;
                $sql .= &amp;quot;(&#039;&amp;quot;.$turnedOver[&#039;x&#039;].&amp;quot;&#039;,&#039;&amp;quot;.$turnedOver[&#039;y&#039;].&amp;quot;&#039;),&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
            $sql .= &amp;quot;(&#039;$x&#039;,&#039;$y&#039;) ) &amp;quot;;&lt;br /&gt;
                       &lt;br /&gt;
            self::DbQuery( $sql );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... we update the database to change the color of all turned over disc + the disc we just placed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Update scores according to the number of disc on board&lt;br /&gt;
            $sql = &amp;quot;UPDATE player&lt;br /&gt;
                    SET player_score = (&lt;br /&gt;
                    SELECT COUNT( board_x ) FROM board WHERE board_player=player_id&lt;br /&gt;
                    )&amp;quot;;&lt;br /&gt;
            self::DbQuery( $sql );&lt;br /&gt;
            &lt;br /&gt;
            // Statistics&lt;br /&gt;
            self::incStat( count( $turnedOverDiscs ), &amp;quot;turnedOver&amp;quot;, $player_id );&lt;br /&gt;
            if( ($x==1 &amp;amp;&amp;amp; $y==1) || ($x==8 &amp;amp;&amp;amp; $y==1) || ($x==1 &amp;amp;&amp;amp; $y==8) || ($x==8 &amp;amp;&amp;amp; $y==8) )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnCorner&#039;, $player_id );&lt;br /&gt;
            else if( $x==1 || $x==8 || $y==1 || $y==8 )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnBorder&#039;, $player_id );&lt;br /&gt;
            else if( $x&amp;gt;=3 &amp;amp;&amp;amp; $x&amp;lt;=6 &amp;amp;&amp;amp; $y&amp;gt;=3 &amp;amp;&amp;amp; $y&amp;lt;=6 )&lt;br /&gt;
                self::incStat( 1, &#039;discPlayedOnCenter&#039;, $player_id );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... now, we update both player score by counting all disc, and we manage game statistics.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Notify&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;playDisc&amp;quot;, clienttranslate( &#039;${player_name} plays a disc and turns over ${returned_nbr} disc(s)&#039; ), array(&lt;br /&gt;
                &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
                &#039;player_name&#039; =&amp;gt; self::getActivePlayerName(),&lt;br /&gt;
                &#039;returned_nbr&#039; =&amp;gt; count( $turnedOverDiscs ),&lt;br /&gt;
                &#039;x&#039; =&amp;gt; $x,&lt;br /&gt;
                &#039;y&#039; =&amp;gt; $y&lt;br /&gt;
            ) );&lt;br /&gt;
&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;turnOverDiscs&amp;quot;, &#039;&#039;, array(&lt;br /&gt;
                &#039;player_id&#039; =&amp;gt; $player_id,&lt;br /&gt;
                &#039;turnedOver&#039; =&amp;gt; $turnedOverDiscs&lt;br /&gt;
            ) );&lt;br /&gt;
            &lt;br /&gt;
            $newScores = self::getCollectionFromDb( &amp;quot;SELECT player_id, player_score FROM player&amp;quot;, true );&lt;br /&gt;
            self::notifyAllPlayers( &amp;quot;newScores&amp;quot;, &amp;quot;&amp;quot;, array(&lt;br /&gt;
                &amp;quot;scores&amp;quot; =&amp;gt; $newScores&lt;br /&gt;
            ) );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... then we notify about all these changes. We are using for that 3 notifications (&#039;playDisc&#039;, &#039;turnOverDiscs&#039; and &#039;newScores&#039; that we are going to implement on client side later). Note that the description of the &#039;playDisc&#039; notification will be logged in the game log.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            // Then, go to the next state&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;playDisc&#039; );&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
            throw new feException( &amp;quot;Impossible move&amp;quot; );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... finally, we jump to the next game state if everything goes fine (&#039;playDisc&#039; is the name of a transition in the &#039;playerTurn&#039; game state description above which leads to state 11 which is &#039;nextPlayer&#039;).&lt;br /&gt;
&lt;br /&gt;
To make the statistics work, we have to initialize them in stats.inc.php:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    // Statistics existing for each player&lt;br /&gt;
    &amp;quot;player&amp;quot; =&amp;gt; array(&lt;br /&gt;
    &lt;br /&gt;
        &amp;quot;discPlayedOnCorner&amp;quot; =&amp;gt; array(   &amp;quot;id&amp;quot;=&amp;gt; 10,&lt;br /&gt;
                                &amp;quot;name&amp;quot; =&amp;gt; totranslate(&amp;quot;Discs played on a corner&amp;quot;), &lt;br /&gt;
                                &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;int&amp;quot; ),&lt;br /&gt;
                                &lt;br /&gt;
        &amp;quot;discPlayedOnBorder&amp;quot; =&amp;gt; array(   &amp;quot;id&amp;quot;=&amp;gt; 11,&lt;br /&gt;
                                &amp;quot;name&amp;quot; =&amp;gt; totranslate(&amp;quot;Discs played on a border&amp;quot;), &lt;br /&gt;
                                &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;int&amp;quot; ),&lt;br /&gt;
&lt;br /&gt;
        &amp;quot;discPlayedOnCenter&amp;quot; =&amp;gt; array(   &amp;quot;id&amp;quot;=&amp;gt; 12,&lt;br /&gt;
                                &amp;quot;name&amp;quot; =&amp;gt; totranslate(&amp;quot;Discs played on board center part&amp;quot;), &lt;br /&gt;
                                &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;int&amp;quot; ),&lt;br /&gt;
&lt;br /&gt;
        &amp;quot;turnedOver&amp;quot; =&amp;gt; array(   &amp;quot;id&amp;quot;=&amp;gt; 13,&lt;br /&gt;
                                &amp;quot;name&amp;quot; =&amp;gt; totranslate(&amp;quot;Number of discs turned over&amp;quot;), &lt;br /&gt;
                                &amp;quot;type&amp;quot; =&amp;gt; &amp;quot;int&amp;quot; )    &lt;br /&gt;
    )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A last thing to do on the server side is to activate the next player when we enter the &amp;quot;nextPlayer&amp;quot; game state (in the &amp;quot;reversi.game.php&amp;quot; file, under &amp;quot;Game state reactions&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    function stNextPlayer()&lt;br /&gt;
    {&lt;br /&gt;
        // Active next player&lt;br /&gt;
        $player_id = self::activeNextPlayer();&lt;br /&gt;
&lt;br /&gt;
        // Check if both player has at least 1 discs, and if there are free squares to play&lt;br /&gt;
        $player_to_discs = self::getCollectionFromDb( &amp;quot;SELECT board_player, COUNT( board_x )&lt;br /&gt;
                                                       FROM board&lt;br /&gt;
                                                       GROUP BY board_player&amp;quot;, true );&lt;br /&gt;
&lt;br /&gt;
        if( ! isset( $player_to_discs[ null ] ) )&lt;br /&gt;
        {&lt;br /&gt;
            // Index 0 has not been set =&amp;gt; there&#039;s no more free place on the board !&lt;br /&gt;
            // =&amp;gt; end of the game&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            return ;&lt;br /&gt;
        }&lt;br /&gt;
        else if( ! isset( $player_to_discs[ $player_id ] ) )&lt;br /&gt;
        {&lt;br /&gt;
            // Active player has no more disc on the board =&amp;gt; he looses immediately&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            return ;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // Can this player play?&lt;br /&gt;
&lt;br /&gt;
        $possibleMoves = self::getPossibleMoves( $player_id );&lt;br /&gt;
        if( count( $possibleMoves ) == 0 )&lt;br /&gt;
        {&lt;br /&gt;
&lt;br /&gt;
            // This player can&#039;t play&lt;br /&gt;
            // Can his opponent play ?&lt;br /&gt;
            $opponent_id = self::getUniqueValueFromDb( &amp;quot;SELECT player_id FROM player WHERE player_id!=&#039;$player_id&#039; &amp;quot; );&lt;br /&gt;
            if( count( self::getPossibleMoves( $opponent_id ) ) == 0 )&lt;br /&gt;
            {&lt;br /&gt;
                // Nobody can move =&amp;gt; end of the game&lt;br /&gt;
                $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;endGame&#039; );&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {            &lt;br /&gt;
                // =&amp;gt; pass his turn&lt;br /&gt;
                $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;cantPlay&#039; );&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            // This player can play. Give him some extra time&lt;br /&gt;
            self::giveExtraTime( $player_id );&lt;br /&gt;
            $this-&amp;gt;gamestate-&amp;gt;nextState( &#039;nextTurn&#039; );&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, when we play a disc, the rules are checked and the disc appears in the database.&lt;br /&gt;
&lt;br /&gt;
[[File:reversi9.jpg]]&lt;br /&gt;
&lt;br /&gt;
Of course, as we don&#039;t manage notifications on client side, we need to press F5 after each move to see the changes on the board.&lt;br /&gt;
&lt;br /&gt;
== Make the move appear automatically ==&lt;br /&gt;
&lt;br /&gt;
Now, what we have to do is process the notifications sent by the server and make the move appear on the interface.&lt;br /&gt;
&lt;br /&gt;
In our &amp;quot;setupNotifications&amp;quot; method, we register 2 methods for the 2 notifications we created at the previous step (&#039;playDisc&#039; and &#039;turnOverDiscs&#039;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            dojo.subscribe( &#039;playDisc&#039;, this, &amp;quot;notif_playDisc&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;playDisc&#039;, 500 );&lt;br /&gt;
            dojo.subscribe( &#039;turnOverDiscs&#039;, this, &amp;quot;notif_turnOverDiscs&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;turnOverDiscs&#039;, 1500 );&lt;br /&gt;
            dojo.subscribe( &#039;newScores&#039;, this, &amp;quot;notif_newScores&amp;quot; );&lt;br /&gt;
            this.notifqueue.setSynchronous( &#039;newScores&#039;, 500 );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, we associate each of our 3 notifications with a method prefixed with &amp;quot;notif_&amp;quot;. We also define these notifications as &amp;quot;synchronous&amp;quot;, with a duration in millisecond. It tells the user interface to wait some time after executing the notification, to let the animation end before starting the next notification. In our specific case, the animation will be the following:&lt;br /&gt;
* Make a disc slide from the player panel to its place on the board&lt;br /&gt;
* (wait 500ms)&lt;br /&gt;
* Make all turned over discs blink (and of course turned them over)&lt;br /&gt;
* (wait 1500ms)&lt;br /&gt;
* Update the player scores&lt;br /&gt;
* (wait 500ms)&lt;br /&gt;
&lt;br /&gt;
The 2nd parameter in dojo.subscribe call (this) is the &#039;context&#039;, and will be passed in as a parameter to the specified method.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s have a look now on the &amp;quot;playDisc&amp;quot; notification handler method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        notif_playDisc: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            // Remove current possible moves (makes the board more clear)&lt;br /&gt;
            dojo.query( &#039;.possibleMove&#039; ).removeClass( &#039;possibleMove&#039; );        &lt;br /&gt;
        &lt;br /&gt;
            this.addTokenOnBoard( notif.args.x, notif.args.y, notif.args.player_id );&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No surprise here, we re-used some existing stuff to:&lt;br /&gt;
* Remove the highlighted squares.&lt;br /&gt;
* Add a new disc on board, coming from player panel.&lt;br /&gt;
&lt;br /&gt;
Now, here&#039;s the method that handles the turnOverDiscs notification:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        notif_turnOverDiscs: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            // Get the color of the player who is returning the discs&lt;br /&gt;
            var targetColor = this.gamedatas.players[ notif.args.player_id ].color;&lt;br /&gt;
&lt;br /&gt;
            // Make these discs blink and set them to the specified color&lt;br /&gt;
            for( var i in notif.args.turnedOver )&lt;br /&gt;
            {&lt;br /&gt;
                var token = notif.args.turnedOver[ i ];&lt;br /&gt;
                &lt;br /&gt;
                // Make the token blink 2 times&lt;br /&gt;
                var anim = dojo.fx.chain( [&lt;br /&gt;
                    dojo.fadeOut( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y } ),&lt;br /&gt;
                    dojo.fadeIn( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y } ),&lt;br /&gt;
                    dojo.fadeOut( { &lt;br /&gt;
                                    node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y,&lt;br /&gt;
                                    onEnd: function( node ) {&lt;br /&gt;
&lt;br /&gt;
                                        // Remove any color class&lt;br /&gt;
                                        dojo.removeClass( node, [ &#039;tokencolor_000000&#039;, &#039;tokencolor_ffffff&#039; ] );&lt;br /&gt;
                                        // ... and add the good one&lt;br /&gt;
                                        dojo.addClass( node, &#039;tokencolor_&#039;+targetColor );&lt;br /&gt;
                                                             &lt;br /&gt;
                                    } &lt;br /&gt;
                                  } ),&lt;br /&gt;
                    dojo.fadeIn( { node: &#039;token_&#039;+token.x+&#039;_&#039;+token.y  } )&lt;br /&gt;
                                 &lt;br /&gt;
                ] ); // end of dojo.fx.chain&lt;br /&gt;
&lt;br /&gt;
                // ... and launch the animation&lt;br /&gt;
                anim.play();                &lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The list of the discs to be turned over has been made available by our server side code in &amp;quot;notif.args.turnedOver&amp;quot; (see previous paragraph). We loop through all these discs, and create a complex animation using dojo.Animation for each of them. The complete documentation on dojo animations [http://dojotoolkit.org/documentation/tutorials/1.6/animation/ can be found here].&lt;br /&gt;
&lt;br /&gt;
In few words: we create a chain of 4 animations to make the disc fade out, fade in, fade out again, and fade in again. At the end of the second fade out, we change the color of the disc. Finally, we launch the animation with &amp;quot;play()&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
And Also the notification to update the scores:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
notif_newScores: function( notif )&lt;br /&gt;
        {&lt;br /&gt;
            for( var player_id in notif.args.scores )&lt;br /&gt;
            {&lt;br /&gt;
                var newScore = notif.args.scores[ player_id ];&lt;br /&gt;
                this.scoreCtrl[ player_id ].toValue( newScore );&lt;br /&gt;
            }&lt;br /&gt;
        },&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11477</id>
		<title>Create a game in BGA Studio: Complete Walkthrough</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11477"/>
		<updated>2022-01-19T14:27:17Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Hook version control system */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This document is not a tutorial, but step by step instructions on how to build your own first game adaptation using BGA Studio framework.&lt;br /&gt;
&lt;br /&gt;
Before you read this material, you must:&lt;br /&gt;
* Read the overall presentations of the BGA [[Studio]].&lt;br /&gt;
* Some-what know the languages used by BGA Studio: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
* Create a game using one of the available tutorials. Don&#039;t bother with a new game if you have not completed at least one of the tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck or have questions about this page post on [https://forum.boardgamearena.com/viewforum.php?f=12 BGA Developers forum].&lt;br /&gt;
If you&#039;re uncomfortable posting on the public forum you can send messages directly to developers who post answers on that forum but NOT the BGA admins.&lt;br /&gt;
If you find typos in this wiki - fix it.&lt;br /&gt;
&lt;br /&gt;
== Select a First Game ==&lt;br /&gt;
&lt;br /&gt;
For your first &#039;&#039;&#039;real&#039;&#039;&#039; game you must either&lt;br /&gt;
* Select a game from [https://en.studio.boardgamearena.com/licensing Available Licenses]&lt;br /&gt;
* Or from the Public Domain&lt;br /&gt;
&lt;br /&gt;
But what if the game you want is not there? If you are able to successfully publish your first game, you would gain the trust of the BGA admins and they will be happy to assist you in obtaining a license for a game you really want to do or you can request a license yourself. You can read more about game licenses on [[BGA Game licenses]] page.&lt;br /&gt;
&lt;br /&gt;
Once you selected the game but before creating a new project, please take a few seconds to check that someone is not already developing this game. If it is the case, maybe you can propose to join the project?&lt;br /&gt;
&lt;br /&gt;
[http://en.studio.boardgamearena.com/#!projects Check the list of current projects]&lt;br /&gt;
&lt;br /&gt;
Even if you see a few projects with name of the game they may not be active. There are a lot of abandoned game projects. If it&#039;s not clear by the status, post to Developers forum asking if anybody is actively working on the project or send a message to the developers listed for the abandoned projects, and at the same time ask admins on the same forum post to send you graphics for that game if they have them (there a button on [https://en.studio.boardgamearena.com/licensing Available Licenses] page to request graphics, but it will just send an email).&lt;br /&gt;
&lt;br /&gt;
If your goal was to fix bugs in an existing project, first try to locate it on Studio, projects developed by BGA admins are not in the Studio. Then get read only access to the project and you can create your own as a copy of the existing one. Contact existing project admin about getting write access to the original project or if they are willing to take your patches - apply them.&lt;br /&gt;
&lt;br /&gt;
If you want to take over an existing project first ask on the forum to see if project is abandoned, then get read only access (via project list) and see if this worth using it, if it has no code or graphics just start from the scratch, don&#039;t worry about project name it can be renamed later.&lt;br /&gt;
&lt;br /&gt;
== Create a project ==&lt;br /&gt;
&lt;br /&gt;
If you have not already, you have to create a project in BGA Studio for this game. If the original game name is taken use gamenameYOURINITIALS&lt;br /&gt;
template, i.e.&amp;quot;heartsla&amp;quot;. Don&#039;t worry too much about the name, if game would be good enough to be publish it will be renamed to original name. &lt;br /&gt;
&lt;br /&gt;
Find and start the game in turn based mode, make sure it works.&lt;br /&gt;
&lt;br /&gt;
Second, modify the text in .tpl file, reload the page in the browser and make sure your ftp sync works as expected.&lt;br /&gt;
Note: if you have not setup [http://en.doc.boardgamearena.com/Tools_and_tips_of_BGA_Studio#File_Sync FTP auto-sync] yet, do it now, manually copying files is a no-starter.&lt;br /&gt;
&lt;br /&gt;
Update your project status in [http://en.studio.boardgamearena.com/#!studio Control Panel &amp;gt; Manage games] page, you can say &amp;quot;development started&amp;quot; or &amp;quot;waiting for license&amp;quot; or &amp;quot;waiting for graphics&amp;quot; or combination of those.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Development Tools ==&lt;br /&gt;
&lt;br /&gt;
At some point you need to setup your development environment which consist of multiple tools, such as&lt;br /&gt;
* Editor or IDE&lt;br /&gt;
* Browser with dev tools&lt;br /&gt;
* File sync tools&lt;br /&gt;
* BGA Web tools&lt;br /&gt;
* Image manipulation tools&lt;br /&gt;
* Version control tools&lt;br /&gt;
&lt;br /&gt;
Please scan though articles from [[Studio#BGA_Studio_user_guide]] especially related to debugging and tools, there is a lot of useful info there.&lt;br /&gt;
&lt;br /&gt;
== Hook version control system ==&lt;br /&gt;
&lt;br /&gt;
If it&#039;s a real game, I would commit the code to version control right at start. You are going to find yourself in the situation when the game does not even start anymore and there is no way of debugging it unless you have a way to revert. That is where version control becomes very handy.&lt;br /&gt;
If you don&#039;t know what I am talking about then at least back-up your files after each of major steps. Starting now.&lt;br /&gt;
You can also create a project on github, but make sure &#039;&#039;&#039;you don&#039;t commit original publisher graphics files&#039;&#039;&#039; and &#039;&#039;&#039;you don&#039;t include a file with your sftp password&#039;&#039;&#039; (github is automatically crawled for passwords by hackers; a hacking attempt occurred on BGA studio for this reason in June 2020).&lt;br /&gt;
You can (and should) also commit your modification periodically via Studio Control Panel.&lt;br /&gt;
&lt;br /&gt;
== Obtain game graphics ==&lt;br /&gt;
&lt;br /&gt;
If you developing a game from Available Licenses games, ask the admins to send you graphics by contacting studio@boardgamearena.com. While that request is being processed (it can take time, as it often requires some back and forth  between the admins and the publishers) you can proceed to next step - project creation.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t get original graphics you go to &#039;&#039;&#039;Scavenger Hunt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you developing a public domain card game you can borrow standard cards from BGA generic assets, see [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Standard game pieces - meeples, cubes, dice can be found here as well [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Go to boardgamegeek.com find your game and obtain 3D game box image, 2D box image, and if you lucky they also sometime have boards and token scans in &amp;quot;Game Pieces&amp;quot; section of Images&lt;br /&gt;
* If that fail google &amp;quot;boardgame &amp;lt;name&amp;gt;&amp;quot; and check Images section&lt;br /&gt;
* Get the rules PDF as well, there tools that allows you to extract graphics from PDF, which usually good for meeples, cubes and such (can use pdfimages command line tool)&lt;br /&gt;
&lt;br /&gt;
Once you get the graphics one way or another you have to massage it to fit in the BGA criteria, which usually involves&lt;br /&gt;
* If publisher sends graphics in one token/card per file mode, you have to stitch them in sprite and scale down&lt;br /&gt;
* For non square tiles and game pieces you need transparency&lt;br /&gt;
* Usually you chop off scoring &amp;quot;ring&amp;quot; around the board of the game since scoring track not needed for online adaptation&lt;br /&gt;
&lt;br /&gt;
More details about graphics requirements can be found here [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
[[File:Rrr_search.png]]&lt;br /&gt;
&lt;br /&gt;
== Obtain game documentation ==&lt;br /&gt;
&lt;br /&gt;
Also at this time obtain a electronic copy of rules, such as PDF (English version). &lt;br /&gt;
&lt;br /&gt;
Also grab any other documents you may find on boardgamegeek such as FAQ, additional Reference books, and user created assistant documents, such&lt;br /&gt;
as cheat-sheets (may be easier to get a data from these then trying to scrub pdf). You create and place them in the doc/ folder of the project then&lt;br /&gt;
exclude them from version control. There is also a misc/ folder now but it will hold up to 1 Mb of data files which would be checked in, so rules pdf&#039;s may not fit there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Update game infos and box graphics ==&lt;br /&gt;
&lt;br /&gt;
Even it does not nothing yet start with making sure game looks descent in the game selector, meaning it has nice box graphics and information is correct. &lt;br /&gt;
&lt;br /&gt;
For that we need to edit [[Game_meta-information: gameinfos.inc.php|gameinfos.inc.php]].&lt;br /&gt;
What you would do for real game you would go to http://boardgamegeek.com find the game and use the information from web-site to fill the gameinfos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step is to replace game_box.png with proper images, usually you can find all images including publisher logo on boardgamegeek website.&lt;br /&gt;
&lt;br /&gt;
Details about images can be found here: [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
Now important step. You have to LOAD these files in studio website through control panel. So go to Control Panel -&amp;gt; Manager Games -&amp;gt; YOURPROJECT&lt;br /&gt;
and press Reload for &#039;Reload game informations&#039; and &#039;Reload game box image&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Gamepanel_sharedcode.png]]&lt;br /&gt;
&lt;br /&gt;
Now try to start the game again. If you some-how introduced a syntax error in gameinfos file it may not actually work (game won&#039;t start).&lt;br /&gt;
Always use &amp;quot;Express Start&amp;quot; button to start the game. You should see a standard state prompt from template. You should see X players on the right, testdude0 .. testdudeX-1.&lt;br /&gt;
To switch between them press the red arrow button near their names, it will open another tab. This way you don&#039;t need to login and logout from multiple accounts!&lt;br /&gt;
&lt;br /&gt;
== Fix source copyright ==&lt;br /&gt;
&lt;br /&gt;
Now since you have your own project, you want put your name in the copyright header, so replace&lt;br /&gt;
&lt;br /&gt;
  © &amp;lt;Your name here&amp;gt; &amp;lt;Your email address here&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
  © John Snow &amp;lt;jsnow@gameofthrones.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well not exactly this but whatever your real name is. For all files in project directory, its about 10 files. Make sure project still starts after that :)&lt;br /&gt;
&lt;br /&gt;
== Reduce the Rules ==&lt;br /&gt;
&lt;br /&gt;
Programming a game will take a lot more time than you may think. Most of the projects in the studio are abandoned because of lack of patience or skill.&lt;br /&gt;
To keep sane, start the game with *reduced* rules and try to complete that first.&lt;br /&gt;
&lt;br /&gt;
* If it has any expansions - do not even attempt to deal with them, not even - &amp;quot;I will just add graphics for them now and not use&amp;quot; - waste of time if you don&#039;t complete basic&lt;br /&gt;
* If it has advanced rules - start with basic rules only, i.e. &amp;quot;beginner game&amp;quot;&lt;br /&gt;
* If it has special rules for 2 player vs 4, start with most basic form (i.e. 4), restrict to 4 players &lt;br /&gt;
* If it has 50 unique cards of 2 each - start with 2 unique cards with 25 each (just to keep it moving)&lt;br /&gt;
* Any sort of rules that you think can be removed and not included in base - set aside for now &lt;br /&gt;
* Ignore any sort of cool animations - dice rolling, card flipping, choo-choo sounds of the trains - all this fluff can be added later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Game Elements ==&lt;br /&gt;
Technically game elements are already designed by board game designer but your job is to map it to program space.&lt;br /&gt;
Each physical piece (card, token, cube) will leave footprints all over the code (unfortunatly in multiple disconnected places).&lt;br /&gt;
To prepare the game you need to sort out these elements, i.e. categorize. I usually have to the following categorization (in object oriented view):&lt;br /&gt;
* Instance - all individual pieces are instances, i.e. two red cubes are two instances of &#039;red cube&#039; type (class)&lt;br /&gt;
* Type - element type which distinctly represents that element in appearence (i.e. red cube is different type than blue cube)&lt;br /&gt;
* Super Type - one of more common types that similar properties (i.e. red OR cube)&lt;br /&gt;
* Player color - supertype specific for player color (sometimes there is no colors but like player 1 - but is conceptually the same, I use color because its easier to track)&lt;br /&gt;
&lt;br /&gt;
Personally I like to encode my elements in string using reverse dns notation listing all the properties above, i.e.&lt;br /&gt;
  meeple_ff0000_7 - this is instance #7 of type meeple_ff0000 (red meeple)&lt;br /&gt;
Or&lt;br /&gt;
  card_yellow_magic_2 - this is instance #2 of yellow card (in this case yellow is color of deck not related to player color) that can do magic&lt;br /&gt;
&lt;br /&gt;
So every game element would be in the&lt;br /&gt;
&lt;br /&gt;
1. Database - instances. The db record would be something like &lt;br /&gt;
  key|location|state&lt;br /&gt;
  meeple_ff0000_7|slot_action_2|1&lt;br /&gt;
  meeple_ff0000_2|tableau_ff0000|0&lt;br /&gt;
2. Material file - types and supertypes, we never need repeating info here, so never list individual instances but only types or supertypes, in this case we don&#039;t really need to define red meeple vs blue meeple&lt;br /&gt;
  &#039;meeple&#039;=&amp;gt;{&#039;name&#039;=&amp;gt;totranslate(&#039;Meeple&#039;)}&lt;br /&gt;
3. Client (js, css, tpl, etc) - instances and types. For example my meeple will be like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;meeple_ff0000_7&amp;quot; class=&amp;quot;meeple meeple_ff0000&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
with .css something like&lt;br /&gt;
  .meeple { background-image: url(img/tokens.png); width: 2em; height: 2em;}&lt;br /&gt;
  .meeple_ff0000 {background-position: 20% 0%;}&lt;br /&gt;
4. Game php - setup and logic. During setup you have to generate all the pieces and place them in right positions. Also sometimes you need to reference elements to code the logic (I usually try to encode all rules in material file as much as possible)&lt;br /&gt;
&lt;br /&gt;
For complex card games I think it is the best to keep all these info and rules in spreadsheet and generate other files such as material.inc.php.&lt;br /&gt;
See more info below about design of the individual layers.&lt;br /&gt;
&lt;br /&gt;
== Create Initial Layout and Game Graphics ==&lt;br /&gt;
&lt;br /&gt;
Mentally it is easier to start with game layout and graphics pieces. Even when nothing is working its give you moral satisfaction!&lt;br /&gt;
&lt;br /&gt;
There are a few ways how the html could have been generated. You could have started with nothing and generate&lt;br /&gt;
it all by javascript, or you could have started with complete game markup in html and make javascript just hide and move pieces around. BGA framework also provides a third way, which is mix of both, plus a template engine to generate HTML using PHP. The only thing that is really annoying about the template engine is that you cannot put any translatable strings in the template (which means any visible text at all). If you are using the template approach all strings have to extracted as variables and injected through PHP (.view.php). This page explains the template engine in great detail:[[Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl|Template Engine]].&lt;br /&gt;
&lt;br /&gt;
The other disadvantage of the template engine is you cannot run and debug it locally, in the beginning of development it&#039;s a lot faster run off local pages, &lt;br /&gt;
you can do it with some trickery described here [[Tools_and_tips_of_BGA_Studio#Speed_up_CSS_development_and_layout|Tools and Tips for BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
During this step you have to decide what technical solutions you will be using, such as&lt;br /&gt;
* Use inline positioning of all moving pieces, controlled by JS. There are a few classes that already exist in Studio to help with that (see [[Studio#Game_interface_.28Client_side.29|Game Interface - Client Side]]). OR use html/css layout engine to position pieces (my personal choice).&lt;br /&gt;
* Use BGA template engine OR create all ui elements by JS OR manually write or generate complete html markup. The game usually contain 200-300 pieces, it seems wrong but actually its faster to type all of this up in html/css when trying write than debug code for page generator.&lt;br /&gt;
Static HTML markup also means you have to use players color or abstracted player number (such as red is 1, blue is 2) not player id&#039;s anywhere in JS, since player id is dynamic by nature.&lt;br /&gt;
&lt;br /&gt;
Start by creating and mapping all games assets, best way is probably to open rule book on &amp;quot;boardgame contents&amp;quot; page and go through every piece. Every pieces of boardgame would have its &amp;quot;print&amp;quot; in multiple files in your game:&lt;br /&gt;
* Some sort if &amp;quot;div&amp;quot; in html, where id of element match id of element in database (easiest way)&lt;br /&gt;
* Css for the element (either unique or for class), usually with background propery refering to part of sprite image&lt;br /&gt;
* Entry in material.inc.php referring to static properties of the element, i.e. name, tooltip, rules, etc&lt;br /&gt;
* Entry in .tpl file to represent static or initial location on the table OR creation template&lt;br /&gt;
&lt;br /&gt;
Here are some specific examples:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create entry in .tpl file for the board, it will be static entry as we never need to create this dynamically&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;board&amp;quot; class=&amp;quot;board shadow board4p&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create entry in .css file for this board and other board variants (in example below we have 4 ppl board whcih is diffrent than 2 ppl board)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.board {&lt;br /&gt;
	position: relative;&lt;br /&gt;
	width: 980px;&lt;br /&gt;
	height: 433px;&lt;br /&gt;
	margin-bottom: 5px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.board4p {&lt;br /&gt;
	background-image: url(img/board4p.jpg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That would be pretty much it for the board itself, as it does not really need a tooltip so we don&#039;t need entry in material.inc.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board Slots&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are interactive areas on the board, usually illustrated as such. In most cases you can get away with rectangular shapes, but sometimes you have to create circle or oval shapes (and in really advanced case would be some svg paths). For slots you can do the following:&lt;br /&gt;
&lt;br /&gt;
Entry in material.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;token_types = array(&lt;br /&gt;
...&lt;br /&gt;
&#039;slot_action_2&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;type&#039; =&amp;gt; &#039;slot_action&#039;,&lt;br /&gt;
  &#039;name&#039; =&amp;gt; clienttranslate(&amp;quot;2 Gray Track Advancements&amp;quot;),&lt;br /&gt;
  &#039;tooltip&#039; =&amp;gt; clienttranslate(&amp;quot;This action gives you two advancements of gray track. You cannot use this action if you cannot complete all advancements.&amp;quot;),&lt;br /&gt;
  &#039;o&#039;=&amp;gt;&amp;quot;1,0,0,gg&amp;quot;, // automatic rules&lt;br /&gt;
),&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in template inside the &amp;quot;board&amp;quot; div&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;slot_action_2&amp;quot; class=&amp;quot;slot_action_2 slot_action slot_w_1 slot&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in .css with absolute position within the board (its actually better to use percentage - would be easier to scale later)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.slot_action_2 {&lt;br /&gt;
	top: 83px;&lt;br /&gt;
	left: 37px;&lt;br /&gt;
}&lt;br /&gt;
.slot_action {&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	width: 46px;&lt;br /&gt;
	height: 26px;&lt;br /&gt;
	padding: 9px 7px 6px 4px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Meeples&#039;&#039;&#039; - also cards, tokens, other mobile stuff&lt;br /&gt;
&lt;br /&gt;
In CSS these guys will use &amp;quot;sprite&amp;quot; images with transparency, so it will look like this this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	background-image: url(img/tokens.png);&lt;br /&gt;
	width: 25px;&lt;br /&gt;
	height: 25px;&lt;br /&gt;
}&lt;br /&gt;
.meeple_ff0000 { /* red */&lt;br /&gt;
	background-position: 14% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As for creation you can either generate them using template (where whole thing wrapped in template block and {COLOR} replace with all possible colors in .view.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_1&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_2&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can declare a template js var in .tpl file &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    var jstpl_mepple = &#039;&amp;lt;div id=&amp;quot;meeple_${color}_${num}&amp;quot; class=&amp;quot;meeple meeple_${color} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;; // this is in .tpl file at the bottom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and create in js, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 var tokenDiv = this.format_block(&#039;jstpl_mepple&#039;, {&lt;br /&gt;
                                &amp;quot;color&amp;quot; : color,&lt;br /&gt;
                                &amp;quot;num&amp;quot; : i&lt;br /&gt;
                            }); // this in js code somewhere before placing it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you dealing with cards and decks, there are pre-build components that can generate stuff for you.&lt;br /&gt;
&lt;br /&gt;
When do you create dom element matching game element?&lt;br /&gt;
* If you have static layout you create it in .tpl file and its always there, but during initial setup or during notification it moved in proper spot (including &amp;quot;removed from the game&amp;quot; spot)&lt;br /&gt;
* If you dynamically generated pieces you create the element during notification, and sometimes during animation. Also don&#039;t forgot to hook event listener to it if its interactive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One of the greatest parts about the web is all client side code can be viewed in your browser, so if you wondering how something is done in another BGA game just load the page and spy on it! In Chrome that would be right click and &amp;quot;Inspect Element&amp;quot;. That would immediately show html of the given element alongside with css used for it (on the right). Another great way to learn is you can add yourself to any BGA project as read only from the project page!&lt;br /&gt;
&lt;br /&gt;
So at the end of this stage you should complete the following (keeping in mind reduced rules/material for first iteration):&lt;br /&gt;
* Create a layout of the game, with positioning of main board, player areas, zones, other supporting areas, etc&lt;br /&gt;
* Create css and html snippets for all game pieces: boards, tokens, meeples, etc. Place them all in initial template (even if they&#039;re not supposed to be visible at start). I.e. create fake player&#039;s hand with cards, put meeples on the board&lt;br /&gt;
* Hook layout to number of players and colors picked by the game and test with multiple players&lt;br /&gt;
* Figure out what you want to display in mini-player boards and hook it up&lt;br /&gt;
* Create material.inc.php and populate with initial values (names, tooltips, rules) for all relevant game elements or classes of elements&lt;br /&gt;
&lt;br /&gt;
If at this time you don&#039;t have graphics yet create pieces with just CSS, you can use shape, background color and object text using css ::after construct to fake the pieces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Injected_text.png]]&lt;br /&gt;
&lt;br /&gt;
== Hook Input and Animation ==&lt;br /&gt;
&lt;br /&gt;
This step can be done before or after some of the server steps, or you go in iterations switching back and forward until you get it done, up to you.&lt;br /&gt;
&lt;br /&gt;
At this time you want to hook clicking on pieces and buttons and provide some reaction, such of moving a piece. The handler code will be replaced later by the server hook, but at the beginning you want your game to be alive as early as possible. &lt;br /&gt;
&lt;br /&gt;
Usually all pieces will be hooked to onclick during JS &amp;quot;setup&amp;quot; method, in addition if you create elements during server notification they have to be hooked up at that time.&lt;br /&gt;
&lt;br /&gt;
You can play with animation effects you want put in place, in general all the pieces that move in real game should be moving, such as meeples, resources tokens/cubes, cards, vp tokens. &lt;br /&gt;
Regular piece animation is provided by BGA framework, but if you use html layout positioning not inline positioning you have to remove absolute positions (inline position styling) after each move. The set of functions for relative position token animation can found in https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js &lt;br /&gt;
&lt;br /&gt;
Also its a good idea to give player a visual cues on what game elements are clickable now, usually it will be a style, such as &amp;quot;active_slot&amp;quot;, with visual effect of white dashed outline (outline is better then border, because border changes will make piece slightly move since it changes the size) or box-shadow (i.e. neon glow)&lt;br /&gt;
&lt;br /&gt;
If you read [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] you know that you should not get carried away with animation, you are creating a board game not a video game... That also applies to sound effects (in general, you should not use any sounds effects beside already provided by framework).&lt;br /&gt;
&lt;br /&gt;
See [[Game_interface_logic:_yourgamename.js#Players_input|Player&#039;s Input]] and [[Game_interface_logic:_yourgamename.js#Access_and_manipulate_the_DOM|Animation and DOM Manipulation]] for JS reference.&lt;br /&gt;
&lt;br /&gt;
== Create Database Schema ==&lt;br /&gt;
&lt;br /&gt;
At some point you have to design your game database. Do it sooner then later since it would be harder to change it later, since some&lt;br /&gt;
code decisions would be based on that.&lt;br /&gt;
&lt;br /&gt;
If you have grid-based abstract game use template from reversi, if you have a card game use template from hearts (the cards one also commented out in generated template for your project). The cards database goes with php class called [[Deck]].&lt;br /&gt;
&lt;br /&gt;
In general make it as simple as possible. &lt;br /&gt;
Think about it, your game has 300 pieces (likely less). Using database to store this amount of data is like shooting a mosquito with a tank.&lt;br /&gt;
Anything more complex then one table with 5 columns or two tables will only going to make it harder to develop and not improve performance.&lt;br /&gt;
You can forget about normalising and any fancy stuff you learn about databases in school. String field for a primary key would be as fast as integer when we talking about this size of data. So don&#039;t over-optimize with trying to have integers field that have state based on bitmask!&lt;br /&gt;
&lt;br /&gt;
Also remember that static (non dynamic) information about the game does not need to be stored in the database, that all include everything that does not change, i.e&lt;br /&gt;
all token/card properties such as name, tooltips, &amp;quot;strength&amp;quot;, color, etc. This is stored in material.inc.php and server has access to it from anywhere, as well as client&lt;br /&gt;
if you send it with getAllDatas(). The only reason store some of it in database if it can affect your queries (i.e. type of token).&lt;br /&gt;
&lt;br /&gt;
Usually design process will contain the following steps:&lt;br /&gt;
* Design game model - model that represent your game in progress, such as at any given step you can restore the game from that model&lt;br /&gt;
* Mapping - now map real game to that model&lt;br /&gt;
* Encoding - now represent this model in database and material file with reasonable amount of fields&lt;br /&gt;
&lt;br /&gt;
Example: &#039;&#039;&#039;The card game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but as part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in your database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position itself usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what info changes and what info is static, static info is always candidate for material file or html&lt;br /&gt;
* For dynamic stuff we should try to reduce amount of fields we need, i.e. we need a field for card, so its one, we need to know what zone cards belong to, its 2, and we have possible few other fields, but if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face  down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
You can also use cards database schema and [[Deck]] implementation for most purposes (even you not dealing with cards).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another Example: &#039;&#039;&#039;The euro game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based &lt;br /&gt;
games can be in most case represented by (string: token_key, string: location, int: state), example of such database schema can be found here:&lt;br /&gt;
[https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php tokens.php].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See [[Game database model: dbmodel.sql]] for details about editing the file.&lt;br /&gt;
&lt;br /&gt;
Note: the simpler the database is the less debugging of db issues you have to deal with including database migration. The tokens database above - if you use it you never have to worry about migration because you don&#039;t need extra tables in 95% of the games.&lt;br /&gt;
Here are some example of how real games are mapped to such database:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chess&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
- chess is grid base game and normally you would use positional columns, but just for the sake of argument, the chess game will look like this&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_white&lt;br /&gt;
|f3&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|P_black_2&lt;br /&gt;
|c6&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|K_black&lt;br /&gt;
|e8&lt;br /&gt;
|1&lt;br /&gt;
|}&lt;br /&gt;
And the state in this case indicated that kind was moved for example (which means castling cannot be performed)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Classic card game&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Lets pretend we need 2 decks for that game&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_spades_1&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_2&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|2 /* position */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_1&lt;br /&gt;
|tableau_common&lt;br /&gt;
|1 /* face down */&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Eminent Domain (card game)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|card_tech_23&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|1 /* face up */&lt;br /&gt;
|-&lt;br /&gt;
|reource_s_22 /* silicon */&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|2 /*  production state */&lt;br /&gt;
|-&lt;br /&gt;
|fighter_F_1&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also look at other games that use Tokens database and access layer: Nippon, Dungeon Petz, Lewis &amp;amp; Clark, Battleship, Russian Railroads, Khronos&lt;br /&gt;
&lt;br /&gt;
== Implement Game Setup ==&lt;br /&gt;
&lt;br /&gt;
Once you have your database schema you can do a proper game setup. Usually you open rulebook on the &amp;quot;Game Setup&amp;quot; page&lt;br /&gt;
and implement these step by step populating the database (using db access API).&lt;br /&gt;
Game initialization is performed in php method setupNewGame, this method is called once when game table is created.&lt;br /&gt;
Game notifications cannot be sent during this time.&lt;br /&gt;
&lt;br /&gt;
== Implement One time game model synchronisation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now at any point in the game we need to make sure that database information can be reflected back in UI, so we fix getAllDatas function&lt;br /&gt;
to return all possible data we need to reconstruct the game. The template for getAllDatas already taking care of player info, but you &lt;br /&gt;
have to alter it to return all other data from database visible to the &amp;quot;current&amp;quot; player.&lt;br /&gt;
&lt;br /&gt;
After that on the client side we should display this data, so in your .js file in setup function (which is the receiver of getAllDatas) you add calls that handle data send by server, usually by calling animation function such as &amp;quot;placeToken&amp;quot; or &amp;quot;placeCard&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Create State Machine ==&lt;br /&gt;
&lt;br /&gt;
Now you need to create a game state machine. &lt;br /&gt;
&lt;br /&gt;
The state handling spread across 4 files, so you have to make sure all the pieces are connected together.&lt;br /&gt;
The state machine states.inc.php defines all the states, and function handlers on php side in a form of string,&lt;br /&gt;
and if any of these functions are not implemented it would be very hard to debug because it will break in random places.&lt;br /&gt;
&lt;br /&gt;
Please first watch this again [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine  BGA game state machine]&lt;br /&gt;
and then please read [[Your game state machine: states.inc.php]].&lt;br /&gt;
&lt;br /&gt;
Now the state machine should be relatively simple. If you find yourself with machine with more than 20 states its probably not the way to go.&lt;br /&gt;
Not all the player interactions need separate states, a lot of things can be implemented directly on client, i.e. if your player need to select&lt;br /&gt;
a reward token, which offers choice of resource, instead of two states on server just have one state on server and possible few states on client (client side states)&lt;br /&gt;
to collect this info.&lt;br /&gt;
&lt;br /&gt;
== Handle Turn Order ==&lt;br /&gt;
&lt;br /&gt;
If your game goes in clockwise order in natural sitting position nothing really needed you just use standard API and you are good. However if position is complecated&lt;br /&gt;
it may require some trickery.&lt;br /&gt;
&lt;br /&gt;
Usually turn order is done by &amp;quot;game state&amp;quot; (see state machine above). Basically it would be two choices:&lt;br /&gt;
* Turn order depends on game situation (such as we take player with highest number of red cubes)&lt;br /&gt;
* Turn order is custom and assign on previos step - i.e. we not playing in clockwise order anymore. In this case you either need to extend player table with new order info (CANNOT use player_no column) or use order markers that come with game (i.e. marker_ff0000 on position_1). In this we can build player array in right order and pick next player based on previous player using existing helper function such as $this-&amp;gt;createNextPlayerTable($player_ids)&lt;br /&gt;
&lt;br /&gt;
== Implement Notification handling ==&lt;br /&gt;
&lt;br /&gt;
Now to implement things for real we have hook UI actions to ajax calls, and process notifications send by server.&lt;br /&gt;
So previously we hooked onclick js handler right to client animation, in real game its a two&lt;br /&gt;
step operation. When user clicks on something, client sends an ajax call to server, server processes it and updates database, server sends&lt;br /&gt;
notification in response, client hooks animations to server notification. See [[Game_interface_logic:_yourgamename.js#Notifications|JS Notifications]].&lt;br /&gt;
&lt;br /&gt;
Exception to this is client states, if you need to process two step user interaction such as select meeple, place meeple, you may want &lt;br /&gt;
to avoid sending data to server until step is complete (which may involve direct client side animation). See [[BGA_Studio_Cookbook#Multi_Step_Interactions:_Select_Worker.2FPlace_Worker_-_Using_Selection|Multi-Step Interactions]]&lt;br /&gt;
&lt;br /&gt;
Part of the sending notifications would be to update player&#039;s scoring, BGA uses standard control for score (on JS side), see [[Game_interface_logic:_yourgamename.js#Update_players_score|Update Player&#039;s Score]].&lt;br /&gt;
&lt;br /&gt;
In BGA there is only two ways interact with the server (officially)&lt;br /&gt;
* Initial data dump - when JS client starts it gets all current data via setup() method&lt;br /&gt;
* Game actions - ajaxcall from client, it returns error or ok (not data), then server send butch of notifications to client&lt;br /&gt;
&lt;br /&gt;
Note current ajaxcall is super vebosy and prone to errors, I suggest to use helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
				if (!args) args = []; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
				&lt;br /&gt;
				args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
&lt;br /&gt;
				if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
					this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
						this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                                handler); // this is real result handler - it called both on success and error, its is optional param - you rarely need it&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you insert a single action you have to update multiples files:&lt;br /&gt;
* in ggg.js add ajaxcall, i.e. something like &lt;br /&gt;
  this.addActionButton(&#039;pass&#039;,_(&#039;Pass&#039;),()=&amp;gt;this.ajaxcallwrapper(&#039;pass&#039;));&lt;br /&gt;
* in states.php - add action &#039;pass&#039; to list of possible actions&lt;br /&gt;
  &#039;possibleactions&#039; =&amp;gt; [&#039;pass&#039;,&#039;playCard&#039;]&lt;br /&gt;
* in action.php - add action hander, see https://en.doc.boardgamearena.com/Players_actions:_yourgamename.action.php&lt;br /&gt;
* in game.php - add action hander, there you must do the following&lt;br /&gt;
** call checkAction to validate the action&lt;br /&gt;
** possible do more game specific check to validate what player doing is legal (even its not possible from your js side - player can cheat - not allow that)&lt;br /&gt;
** do some database maniplations, using access api&lt;br /&gt;
** send notifications - this is the &amp;quot;reply&amp;quot; for action&lt;br /&gt;
** transition to new state (it very rare that  user will remain in the same state, except for multi-active states)&lt;br /&gt;
* back to ggg.js add notification subsciption and notification handler (two separate things)&lt;br /&gt;
&lt;br /&gt;
== Wrap Up ==&lt;br /&gt;
&lt;br /&gt;
* Implement game progression (getGameProgression() in php)&lt;br /&gt;
* Implement Zombie turn  (zombieTurn() in php)&lt;br /&gt;
* Define and implemented some meaningful statistics for your game (i.e. total points, point from source A, B, C...)&lt;br /&gt;
* The games logs should explain what happened if player was not looking&lt;br /&gt;
* You need to implemented tiebreaking (using aux score field) and updated tiebreaker description in meta-data&lt;br /&gt;
* Make sure all UI strings are marked for translation&lt;br /&gt;
* UI elements which are images (i.e. tokens, cards) should have tooltips&lt;br /&gt;
&lt;br /&gt;
== Alpha ==&lt;br /&gt;
When you think you game is completely working there is still bunch of stuff you have to do/check before telling admin that game is ready, please go though this [[Pre-release checklist]].&lt;br /&gt;
&lt;br /&gt;
If you think its completely ready, let admin know (studio@boardgamearena.com) and it they will push it to alpha.&lt;br /&gt;
&lt;br /&gt;
Finally, visit the game page for your alpha game (https://boardgamearena.com/gamepanel?game=…) to add the following information if you can:&lt;br /&gt;
* Links to the rules (in multiple languages if available).&lt;br /&gt;
* Links to teaching videos.&lt;br /&gt;
* In the &amp;quot;On the web&amp;quot; section, links to:&lt;br /&gt;
** The official website for the game (if there is one).&lt;br /&gt;
** The BoardGameGeek page for the game.&lt;br /&gt;
* Consider writing a summary of the rules.&lt;br /&gt;
&lt;br /&gt;
== Level Up ==&lt;br /&gt;
&lt;br /&gt;
When you successfully created a basic game and you want more, it&#039;s time to make it fancy!&lt;br /&gt;
&lt;br /&gt;
* Add game externtions and variants using gameoptions file&lt;br /&gt;
* Add user preferences for customizations&lt;br /&gt;
* Use theming! That involves replacing hardwood background, changing tooltips, using different sounds, different fonts, changing state prompt and logs&lt;br /&gt;
* You can use fancy scoring board at the end of game instead of default nothing&lt;br /&gt;
* And finally super cool dice rolling, card flipping and victory points evaporating effects&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11476</id>
		<title>Create a game in BGA Studio: Complete Walkthrough</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11476"/>
		<updated>2022-01-19T14:25:24Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Select a First Game */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This document is not a tutorial, but step by step instructions on how to build your own first game adaptation using BGA Studio framework.&lt;br /&gt;
&lt;br /&gt;
Before you read this material, you must:&lt;br /&gt;
* Read the overall presentations of the BGA [[Studio]].&lt;br /&gt;
* Some-what know the languages used by BGA Studio: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
* Create a game using one of the available tutorials. Don&#039;t bother with a new game if you have not completed at least one of the tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck or have questions about this page post on [https://forum.boardgamearena.com/viewforum.php?f=12 BGA Developers forum].&lt;br /&gt;
If you&#039;re uncomfortable posting on the public forum you can send messages directly to developers who post answers on that forum but NOT the BGA admins.&lt;br /&gt;
If you find typos in this wiki - fix it.&lt;br /&gt;
&lt;br /&gt;
== Select a First Game ==&lt;br /&gt;
&lt;br /&gt;
For your first &#039;&#039;&#039;real&#039;&#039;&#039; game you must either&lt;br /&gt;
* Select a game from [https://en.studio.boardgamearena.com/licensing Available Licenses]&lt;br /&gt;
* Or from the Public Domain&lt;br /&gt;
&lt;br /&gt;
But what if the game you want is not there? If you are able to successfully publish your first game, you would gain the trust of the BGA admins and they will be happy to assist you in obtaining a license for a game you really want to do or you can request a license yourself. You can read more about game licenses on [[BGA Game licenses]] page.&lt;br /&gt;
&lt;br /&gt;
Once you selected the game but before creating a new project, please take a few seconds to check that someone is not already developing this game. If it is the case, maybe you can propose to join the project?&lt;br /&gt;
&lt;br /&gt;
[http://en.studio.boardgamearena.com/#!projects Check the list of current projects]&lt;br /&gt;
&lt;br /&gt;
Even if you see a few projects with name of the game they may not be active. There are a lot of abandoned game projects. If it&#039;s not clear by the status, post to Developers forum asking if anybody is actively working on the project or send a message to the developers listed for the abandoned projects, and at the same time ask admins on the same forum post to send you graphics for that game if they have them (there a button on [https://en.studio.boardgamearena.com/licensing Available Licenses] page to request graphics, but it will just send an email).&lt;br /&gt;
&lt;br /&gt;
If your goal was to fix bugs in an existing project, first try to locate it on Studio, projects developed by BGA admins are not in the Studio. Then get read only access to the project and you can create your own as a copy of the existing one. Contact existing project admin about getting write access to the original project or if they are willing to take your patches - apply them.&lt;br /&gt;
&lt;br /&gt;
If you want to take over an existing project first ask on the forum to see if project is abandoned, then get read only access (via project list) and see if this worth using it, if it has no code or graphics just start from the scratch, don&#039;t worry about project name it can be renamed later.&lt;br /&gt;
&lt;br /&gt;
== Create a project ==&lt;br /&gt;
&lt;br /&gt;
If you have not already, you have to create a project in BGA Studio for this game. If the original game name is taken use gamenameYOURINITIALS&lt;br /&gt;
template, i.e.&amp;quot;heartsla&amp;quot;. Don&#039;t worry too much about the name, if game would be good enough to be publish it will be renamed to original name. &lt;br /&gt;
&lt;br /&gt;
Find and start the game in turn based mode, make sure it works.&lt;br /&gt;
&lt;br /&gt;
Second, modify the text in .tpl file, reload the page in the browser and make sure your ftp sync works as expected.&lt;br /&gt;
Note: if you have not setup [http://en.doc.boardgamearena.com/Tools_and_tips_of_BGA_Studio#File_Sync FTP auto-sync] yet, do it now, manually copying files is a no-starter.&lt;br /&gt;
&lt;br /&gt;
Update your project status in [http://en.studio.boardgamearena.com/#!studio Control Panel &amp;gt; Manage games] page, you can say &amp;quot;development started&amp;quot; or &amp;quot;waiting for license&amp;quot; or &amp;quot;waiting for graphics&amp;quot; or combination of those.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Development Tools ==&lt;br /&gt;
&lt;br /&gt;
At some point you need to setup your development environment which consist of multiple tools, such as&lt;br /&gt;
* Editor or IDE&lt;br /&gt;
* Browser with dev tools&lt;br /&gt;
* File sync tools&lt;br /&gt;
* BGA Web tools&lt;br /&gt;
* Image manipulation tools&lt;br /&gt;
* Version control tools&lt;br /&gt;
&lt;br /&gt;
Please scan though articles from [[Studio#BGA_Studio_user_guide]] especially related to debugging and tools, there is a lot of useful info there.&lt;br /&gt;
&lt;br /&gt;
== Hook version control system ==&lt;br /&gt;
&lt;br /&gt;
If its a real game I would commit the code to version control right at start. You going to find yourself in the situation&lt;br /&gt;
when game does not even start anymore and no way of debugging it unless you have a way to revert. That is where version control becomes very handy.&lt;br /&gt;
If you don&#039;t know what I am talking about then at least back-up your files after each of major steps. Starting now.&lt;br /&gt;
You can also create a project on github, but make sure &#039;&#039;&#039;you don&#039;t commit original publisher graphics files&#039;&#039;&#039; and &#039;&#039;&#039;you don&#039;t include a file with your sftp password&#039;&#039;&#039; (github is automatically crawled for passwords by hackers; a hacking attempt occurred on BGA studio for this reason in June 2020).&lt;br /&gt;
You can (and should) also commit your modification periodically via studio&#039;s control panel.&lt;br /&gt;
&lt;br /&gt;
== Obtain game graphics ==&lt;br /&gt;
&lt;br /&gt;
If you developing a game from Available Licenses games, ask the admins to send you graphics by contacting studio@boardgamearena.com. While that request is being processed (it can take time, as it often requires some back and forth  between the admins and the publishers) you can proceed to next step - project creation.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t get original graphics you go to &#039;&#039;&#039;Scavenger Hunt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you developing a public domain card game you can borrow standard cards from BGA generic assets, see [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Standard game pieces - meeples, cubes, dice can be found here as well [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Go to boardgamegeek.com find your game and obtain 3D game box image, 2D box image, and if you lucky they also sometime have boards and token scans in &amp;quot;Game Pieces&amp;quot; section of Images&lt;br /&gt;
* If that fail google &amp;quot;boardgame &amp;lt;name&amp;gt;&amp;quot; and check Images section&lt;br /&gt;
* Get the rules PDF as well, there tools that allows you to extract graphics from PDF, which usually good for meeples, cubes and such (can use pdfimages command line tool)&lt;br /&gt;
&lt;br /&gt;
Once you get the graphics one way or another you have to massage it to fit in the BGA criteria, which usually involves&lt;br /&gt;
* If publisher sends graphics in one token/card per file mode, you have to stitch them in sprite and scale down&lt;br /&gt;
* For non square tiles and game pieces you need transparency&lt;br /&gt;
* Usually you chop off scoring &amp;quot;ring&amp;quot; around the board of the game since scoring track not needed for online adaptation&lt;br /&gt;
&lt;br /&gt;
More details about graphics requirements can be found here [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
[[File:Rrr_search.png]]&lt;br /&gt;
&lt;br /&gt;
== Obtain game documentation ==&lt;br /&gt;
&lt;br /&gt;
Also at this time obtain a electronic copy of rules, such as PDF (English version). &lt;br /&gt;
&lt;br /&gt;
Also grab any other documents you may find on boardgamegeek such as FAQ, additional Reference books, and user created assistant documents, such&lt;br /&gt;
as cheat-sheets (may be easier to get a data from these then trying to scrub pdf). You create and place them in the doc/ folder of the project then&lt;br /&gt;
exclude them from version control. There is also a misc/ folder now but it will hold up to 1 Mb of data files which would be checked in, so rules pdf&#039;s may not fit there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Update game infos and box graphics ==&lt;br /&gt;
&lt;br /&gt;
Even it does not nothing yet start with making sure game looks descent in the game selector, meaning it has nice box graphics and information is correct. &lt;br /&gt;
&lt;br /&gt;
For that we need to edit [[Game_meta-information: gameinfos.inc.php|gameinfos.inc.php]].&lt;br /&gt;
What you would do for real game you would go to http://boardgamegeek.com find the game and use the information from web-site to fill the gameinfos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step is to replace game_box.png with proper images, usually you can find all images including publisher logo on boardgamegeek website.&lt;br /&gt;
&lt;br /&gt;
Details about images can be found here: [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
Now important step. You have to LOAD these files in studio website through control panel. So go to Control Panel -&amp;gt; Manager Games -&amp;gt; YOURPROJECT&lt;br /&gt;
and press Reload for &#039;Reload game informations&#039; and &#039;Reload game box image&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Gamepanel_sharedcode.png]]&lt;br /&gt;
&lt;br /&gt;
Now try to start the game again. If you some-how introduced a syntax error in gameinfos file it may not actually work (game won&#039;t start).&lt;br /&gt;
Always use &amp;quot;Express Start&amp;quot; button to start the game. You should see a standard state prompt from template. You should see X players on the right, testdude0 .. testdudeX-1.&lt;br /&gt;
To switch between them press the red arrow button near their names, it will open another tab. This way you don&#039;t need to login and logout from multiple accounts!&lt;br /&gt;
&lt;br /&gt;
== Fix source copyright ==&lt;br /&gt;
&lt;br /&gt;
Now since you have your own project, you want put your name in the copyright header, so replace&lt;br /&gt;
&lt;br /&gt;
  © &amp;lt;Your name here&amp;gt; &amp;lt;Your email address here&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
  © John Snow &amp;lt;jsnow@gameofthrones.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well not exactly this but whatever your real name is. For all files in project directory, its about 10 files. Make sure project still starts after that :)&lt;br /&gt;
&lt;br /&gt;
== Reduce the Rules ==&lt;br /&gt;
&lt;br /&gt;
Programming a game will take a lot more time than you may think. Most of the projects in the studio are abandoned because of lack of patience or skill.&lt;br /&gt;
To keep sane, start the game with *reduced* rules and try to complete that first.&lt;br /&gt;
&lt;br /&gt;
* If it has any expansions - do not even attempt to deal with them, not even - &amp;quot;I will just add graphics for them now and not use&amp;quot; - waste of time if you don&#039;t complete basic&lt;br /&gt;
* If it has advanced rules - start with basic rules only, i.e. &amp;quot;beginner game&amp;quot;&lt;br /&gt;
* If it has special rules for 2 player vs 4, start with most basic form (i.e. 4), restrict to 4 players &lt;br /&gt;
* If it has 50 unique cards of 2 each - start with 2 unique cards with 25 each (just to keep it moving)&lt;br /&gt;
* Any sort of rules that you think can be removed and not included in base - set aside for now &lt;br /&gt;
* Ignore any sort of cool animations - dice rolling, card flipping, choo-choo sounds of the trains - all this fluff can be added later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Game Elements ==&lt;br /&gt;
Technically game elements are already designed by board game designer but your job is to map it to program space.&lt;br /&gt;
Each physical piece (card, token, cube) will leave footprints all over the code (unfortunatly in multiple disconnected places).&lt;br /&gt;
To prepare the game you need to sort out these elements, i.e. categorize. I usually have to the following categorization (in object oriented view):&lt;br /&gt;
* Instance - all individual pieces are instances, i.e. two red cubes are two instances of &#039;red cube&#039; type (class)&lt;br /&gt;
* Type - element type which distinctly represents that element in appearence (i.e. red cube is different type than blue cube)&lt;br /&gt;
* Super Type - one of more common types that similar properties (i.e. red OR cube)&lt;br /&gt;
* Player color - supertype specific for player color (sometimes there is no colors but like player 1 - but is conceptually the same, I use color because its easier to track)&lt;br /&gt;
&lt;br /&gt;
Personally I like to encode my elements in string using reverse dns notation listing all the properties above, i.e.&lt;br /&gt;
  meeple_ff0000_7 - this is instance #7 of type meeple_ff0000 (red meeple)&lt;br /&gt;
Or&lt;br /&gt;
  card_yellow_magic_2 - this is instance #2 of yellow card (in this case yellow is color of deck not related to player color) that can do magic&lt;br /&gt;
&lt;br /&gt;
So every game element would be in the&lt;br /&gt;
&lt;br /&gt;
1. Database - instances. The db record would be something like &lt;br /&gt;
  key|location|state&lt;br /&gt;
  meeple_ff0000_7|slot_action_2|1&lt;br /&gt;
  meeple_ff0000_2|tableau_ff0000|0&lt;br /&gt;
2. Material file - types and supertypes, we never need repeating info here, so never list individual instances but only types or supertypes, in this case we don&#039;t really need to define red meeple vs blue meeple&lt;br /&gt;
  &#039;meeple&#039;=&amp;gt;{&#039;name&#039;=&amp;gt;totranslate(&#039;Meeple&#039;)}&lt;br /&gt;
3. Client (js, css, tpl, etc) - instances and types. For example my meeple will be like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;meeple_ff0000_7&amp;quot; class=&amp;quot;meeple meeple_ff0000&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
with .css something like&lt;br /&gt;
  .meeple { background-image: url(img/tokens.png); width: 2em; height: 2em;}&lt;br /&gt;
  .meeple_ff0000 {background-position: 20% 0%;}&lt;br /&gt;
4. Game php - setup and logic. During setup you have to generate all the pieces and place them in right positions. Also sometimes you need to reference elements to code the logic (I usually try to encode all rules in material file as much as possible)&lt;br /&gt;
&lt;br /&gt;
For complex card games I think it is the best to keep all these info and rules in spreadsheet and generate other files such as material.inc.php.&lt;br /&gt;
See more info below about design of the individual layers.&lt;br /&gt;
&lt;br /&gt;
== Create Initial Layout and Game Graphics ==&lt;br /&gt;
&lt;br /&gt;
Mentally it is easier to start with game layout and graphics pieces. Even when nothing is working its give you moral satisfaction!&lt;br /&gt;
&lt;br /&gt;
There are a few ways how the html could have been generated. You could have started with nothing and generate&lt;br /&gt;
it all by javascript, or you could have started with complete game markup in html and make javascript just hide and move pieces around. BGA framework also provides a third way, which is mix of both, plus a template engine to generate HTML using PHP. The only thing that is really annoying about the template engine is that you cannot put any translatable strings in the template (which means any visible text at all). If you are using the template approach all strings have to extracted as variables and injected through PHP (.view.php). This page explains the template engine in great detail:[[Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl|Template Engine]].&lt;br /&gt;
&lt;br /&gt;
The other disadvantage of the template engine is you cannot run and debug it locally, in the beginning of development it&#039;s a lot faster run off local pages, &lt;br /&gt;
you can do it with some trickery described here [[Tools_and_tips_of_BGA_Studio#Speed_up_CSS_development_and_layout|Tools and Tips for BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
During this step you have to decide what technical solutions you will be using, such as&lt;br /&gt;
* Use inline positioning of all moving pieces, controlled by JS. There are a few classes that already exist in Studio to help with that (see [[Studio#Game_interface_.28Client_side.29|Game Interface - Client Side]]). OR use html/css layout engine to position pieces (my personal choice).&lt;br /&gt;
* Use BGA template engine OR create all ui elements by JS OR manually write or generate complete html markup. The game usually contain 200-300 pieces, it seems wrong but actually its faster to type all of this up in html/css when trying write than debug code for page generator.&lt;br /&gt;
Static HTML markup also means you have to use players color or abstracted player number (such as red is 1, blue is 2) not player id&#039;s anywhere in JS, since player id is dynamic by nature.&lt;br /&gt;
&lt;br /&gt;
Start by creating and mapping all games assets, best way is probably to open rule book on &amp;quot;boardgame contents&amp;quot; page and go through every piece. Every pieces of boardgame would have its &amp;quot;print&amp;quot; in multiple files in your game:&lt;br /&gt;
* Some sort if &amp;quot;div&amp;quot; in html, where id of element match id of element in database (easiest way)&lt;br /&gt;
* Css for the element (either unique or for class), usually with background propery refering to part of sprite image&lt;br /&gt;
* Entry in material.inc.php referring to static properties of the element, i.e. name, tooltip, rules, etc&lt;br /&gt;
* Entry in .tpl file to represent static or initial location on the table OR creation template&lt;br /&gt;
&lt;br /&gt;
Here are some specific examples:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create entry in .tpl file for the board, it will be static entry as we never need to create this dynamically&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;board&amp;quot; class=&amp;quot;board shadow board4p&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create entry in .css file for this board and other board variants (in example below we have 4 ppl board whcih is diffrent than 2 ppl board)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.board {&lt;br /&gt;
	position: relative;&lt;br /&gt;
	width: 980px;&lt;br /&gt;
	height: 433px;&lt;br /&gt;
	margin-bottom: 5px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.board4p {&lt;br /&gt;
	background-image: url(img/board4p.jpg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That would be pretty much it for the board itself, as it does not really need a tooltip so we don&#039;t need entry in material.inc.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board Slots&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are interactive areas on the board, usually illustrated as such. In most cases you can get away with rectangular shapes, but sometimes you have to create circle or oval shapes (and in really advanced case would be some svg paths). For slots you can do the following:&lt;br /&gt;
&lt;br /&gt;
Entry in material.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;token_types = array(&lt;br /&gt;
...&lt;br /&gt;
&#039;slot_action_2&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;type&#039; =&amp;gt; &#039;slot_action&#039;,&lt;br /&gt;
  &#039;name&#039; =&amp;gt; clienttranslate(&amp;quot;2 Gray Track Advancements&amp;quot;),&lt;br /&gt;
  &#039;tooltip&#039; =&amp;gt; clienttranslate(&amp;quot;This action gives you two advancements of gray track. You cannot use this action if you cannot complete all advancements.&amp;quot;),&lt;br /&gt;
  &#039;o&#039;=&amp;gt;&amp;quot;1,0,0,gg&amp;quot;, // automatic rules&lt;br /&gt;
),&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in template inside the &amp;quot;board&amp;quot; div&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;slot_action_2&amp;quot; class=&amp;quot;slot_action_2 slot_action slot_w_1 slot&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in .css with absolute position within the board (its actually better to use percentage - would be easier to scale later)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.slot_action_2 {&lt;br /&gt;
	top: 83px;&lt;br /&gt;
	left: 37px;&lt;br /&gt;
}&lt;br /&gt;
.slot_action {&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	width: 46px;&lt;br /&gt;
	height: 26px;&lt;br /&gt;
	padding: 9px 7px 6px 4px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Meeples&#039;&#039;&#039; - also cards, tokens, other mobile stuff&lt;br /&gt;
&lt;br /&gt;
In CSS these guys will use &amp;quot;sprite&amp;quot; images with transparency, so it will look like this this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	background-image: url(img/tokens.png);&lt;br /&gt;
	width: 25px;&lt;br /&gt;
	height: 25px;&lt;br /&gt;
}&lt;br /&gt;
.meeple_ff0000 { /* red */&lt;br /&gt;
	background-position: 14% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As for creation you can either generate them using template (where whole thing wrapped in template block and {COLOR} replace with all possible colors in .view.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_1&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_2&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can declare a template js var in .tpl file &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    var jstpl_mepple = &#039;&amp;lt;div id=&amp;quot;meeple_${color}_${num}&amp;quot; class=&amp;quot;meeple meeple_${color} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;; // this is in .tpl file at the bottom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and create in js, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 var tokenDiv = this.format_block(&#039;jstpl_mepple&#039;, {&lt;br /&gt;
                                &amp;quot;color&amp;quot; : color,&lt;br /&gt;
                                &amp;quot;num&amp;quot; : i&lt;br /&gt;
                            }); // this in js code somewhere before placing it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you dealing with cards and decks, there are pre-build components that can generate stuff for you.&lt;br /&gt;
&lt;br /&gt;
When do you create dom element matching game element?&lt;br /&gt;
* If you have static layout you create it in .tpl file and its always there, but during initial setup or during notification it moved in proper spot (including &amp;quot;removed from the game&amp;quot; spot)&lt;br /&gt;
* If you dynamically generated pieces you create the element during notification, and sometimes during animation. Also don&#039;t forgot to hook event listener to it if its interactive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One of the greatest parts about the web is all client side code can be viewed in your browser, so if you wondering how something is done in another BGA game just load the page and spy on it! In Chrome that would be right click and &amp;quot;Inspect Element&amp;quot;. That would immediately show html of the given element alongside with css used for it (on the right). Another great way to learn is you can add yourself to any BGA project as read only from the project page!&lt;br /&gt;
&lt;br /&gt;
So at the end of this stage you should complete the following (keeping in mind reduced rules/material for first iteration):&lt;br /&gt;
* Create a layout of the game, with positioning of main board, player areas, zones, other supporting areas, etc&lt;br /&gt;
* Create css and html snippets for all game pieces: boards, tokens, meeples, etc. Place them all in initial template (even if they&#039;re not supposed to be visible at start). I.e. create fake player&#039;s hand with cards, put meeples on the board&lt;br /&gt;
* Hook layout to number of players and colors picked by the game and test with multiple players&lt;br /&gt;
* Figure out what you want to display in mini-player boards and hook it up&lt;br /&gt;
* Create material.inc.php and populate with initial values (names, tooltips, rules) for all relevant game elements or classes of elements&lt;br /&gt;
&lt;br /&gt;
If at this time you don&#039;t have graphics yet create pieces with just CSS, you can use shape, background color and object text using css ::after construct to fake the pieces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Injected_text.png]]&lt;br /&gt;
&lt;br /&gt;
== Hook Input and Animation ==&lt;br /&gt;
&lt;br /&gt;
This step can be done before or after some of the server steps, or you go in iterations switching back and forward until you get it done, up to you.&lt;br /&gt;
&lt;br /&gt;
At this time you want to hook clicking on pieces and buttons and provide some reaction, such of moving a piece. The handler code will be replaced later by the server hook, but at the beginning you want your game to be alive as early as possible. &lt;br /&gt;
&lt;br /&gt;
Usually all pieces will be hooked to onclick during JS &amp;quot;setup&amp;quot; method, in addition if you create elements during server notification they have to be hooked up at that time.&lt;br /&gt;
&lt;br /&gt;
You can play with animation effects you want put in place, in general all the pieces that move in real game should be moving, such as meeples, resources tokens/cubes, cards, vp tokens. &lt;br /&gt;
Regular piece animation is provided by BGA framework, but if you use html layout positioning not inline positioning you have to remove absolute positions (inline position styling) after each move. The set of functions for relative position token animation can found in https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js &lt;br /&gt;
&lt;br /&gt;
Also its a good idea to give player a visual cues on what game elements are clickable now, usually it will be a style, such as &amp;quot;active_slot&amp;quot;, with visual effect of white dashed outline (outline is better then border, because border changes will make piece slightly move since it changes the size) or box-shadow (i.e. neon glow)&lt;br /&gt;
&lt;br /&gt;
If you read [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] you know that you should not get carried away with animation, you are creating a board game not a video game... That also applies to sound effects (in general, you should not use any sounds effects beside already provided by framework).&lt;br /&gt;
&lt;br /&gt;
See [[Game_interface_logic:_yourgamename.js#Players_input|Player&#039;s Input]] and [[Game_interface_logic:_yourgamename.js#Access_and_manipulate_the_DOM|Animation and DOM Manipulation]] for JS reference.&lt;br /&gt;
&lt;br /&gt;
== Create Database Schema ==&lt;br /&gt;
&lt;br /&gt;
At some point you have to design your game database. Do it sooner then later since it would be harder to change it later, since some&lt;br /&gt;
code decisions would be based on that.&lt;br /&gt;
&lt;br /&gt;
If you have grid-based abstract game use template from reversi, if you have a card game use template from hearts (the cards one also commented out in generated template for your project). The cards database goes with php class called [[Deck]].&lt;br /&gt;
&lt;br /&gt;
In general make it as simple as possible. &lt;br /&gt;
Think about it, your game has 300 pieces (likely less). Using database to store this amount of data is like shooting a mosquito with a tank.&lt;br /&gt;
Anything more complex then one table with 5 columns or two tables will only going to make it harder to develop and not improve performance.&lt;br /&gt;
You can forget about normalising and any fancy stuff you learn about databases in school. String field for a primary key would be as fast as integer when we talking about this size of data. So don&#039;t over-optimize with trying to have integers field that have state based on bitmask!&lt;br /&gt;
&lt;br /&gt;
Also remember that static (non dynamic) information about the game does not need to be stored in the database, that all include everything that does not change, i.e&lt;br /&gt;
all token/card properties such as name, tooltips, &amp;quot;strength&amp;quot;, color, etc. This is stored in material.inc.php and server has access to it from anywhere, as well as client&lt;br /&gt;
if you send it with getAllDatas(). The only reason store some of it in database if it can affect your queries (i.e. type of token).&lt;br /&gt;
&lt;br /&gt;
Usually design process will contain the following steps:&lt;br /&gt;
* Design game model - model that represent your game in progress, such as at any given step you can restore the game from that model&lt;br /&gt;
* Mapping - now map real game to that model&lt;br /&gt;
* Encoding - now represent this model in database and material file with reasonable amount of fields&lt;br /&gt;
&lt;br /&gt;
Example: &#039;&#039;&#039;The card game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but as part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in your database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position itself usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what info changes and what info is static, static info is always candidate for material file or html&lt;br /&gt;
* For dynamic stuff we should try to reduce amount of fields we need, i.e. we need a field for card, so its one, we need to know what zone cards belong to, its 2, and we have possible few other fields, but if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face  down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
You can also use cards database schema and [[Deck]] implementation for most purposes (even you not dealing with cards).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another Example: &#039;&#039;&#039;The euro game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based &lt;br /&gt;
games can be in most case represented by (string: token_key, string: location, int: state), example of such database schema can be found here:&lt;br /&gt;
[https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php tokens.php].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See [[Game database model: dbmodel.sql]] for details about editing the file.&lt;br /&gt;
&lt;br /&gt;
Note: the simpler the database is the less debugging of db issues you have to deal with including database migration. The tokens database above - if you use it you never have to worry about migration because you don&#039;t need extra tables in 95% of the games.&lt;br /&gt;
Here are some example of how real games are mapped to such database:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chess&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
- chess is grid base game and normally you would use positional columns, but just for the sake of argument, the chess game will look like this&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_white&lt;br /&gt;
|f3&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|P_black_2&lt;br /&gt;
|c6&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|K_black&lt;br /&gt;
|e8&lt;br /&gt;
|1&lt;br /&gt;
|}&lt;br /&gt;
And the state in this case indicated that kind was moved for example (which means castling cannot be performed)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Classic card game&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Lets pretend we need 2 decks for that game&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_spades_1&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_2&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|2 /* position */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_1&lt;br /&gt;
|tableau_common&lt;br /&gt;
|1 /* face down */&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Eminent Domain (card game)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|card_tech_23&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|1 /* face up */&lt;br /&gt;
|-&lt;br /&gt;
|reource_s_22 /* silicon */&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|2 /*  production state */&lt;br /&gt;
|-&lt;br /&gt;
|fighter_F_1&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also look at other games that use Tokens database and access layer: Nippon, Dungeon Petz, Lewis &amp;amp; Clark, Battleship, Russian Railroads, Khronos&lt;br /&gt;
&lt;br /&gt;
== Implement Game Setup ==&lt;br /&gt;
&lt;br /&gt;
Once you have your database schema you can do a proper game setup. Usually you open rulebook on the &amp;quot;Game Setup&amp;quot; page&lt;br /&gt;
and implement these step by step populating the database (using db access API).&lt;br /&gt;
Game initialization is performed in php method setupNewGame, this method is called once when game table is created.&lt;br /&gt;
Game notifications cannot be sent during this time.&lt;br /&gt;
&lt;br /&gt;
== Implement One time game model synchronisation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now at any point in the game we need to make sure that database information can be reflected back in UI, so we fix getAllDatas function&lt;br /&gt;
to return all possible data we need to reconstruct the game. The template for getAllDatas already taking care of player info, but you &lt;br /&gt;
have to alter it to return all other data from database visible to the &amp;quot;current&amp;quot; player.&lt;br /&gt;
&lt;br /&gt;
After that on the client side we should display this data, so in your .js file in setup function (which is the receiver of getAllDatas) you add calls that handle data send by server, usually by calling animation function such as &amp;quot;placeToken&amp;quot; or &amp;quot;placeCard&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Create State Machine ==&lt;br /&gt;
&lt;br /&gt;
Now you need to create a game state machine. &lt;br /&gt;
&lt;br /&gt;
The state handling spread across 4 files, so you have to make sure all the pieces are connected together.&lt;br /&gt;
The state machine states.inc.php defines all the states, and function handlers on php side in a form of string,&lt;br /&gt;
and if any of these functions are not implemented it would be very hard to debug because it will break in random places.&lt;br /&gt;
&lt;br /&gt;
Please first watch this again [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine  BGA game state machine]&lt;br /&gt;
and then please read [[Your game state machine: states.inc.php]].&lt;br /&gt;
&lt;br /&gt;
Now the state machine should be relatively simple. If you find yourself with machine with more than 20 states its probably not the way to go.&lt;br /&gt;
Not all the player interactions need separate states, a lot of things can be implemented directly on client, i.e. if your player need to select&lt;br /&gt;
a reward token, which offers choice of resource, instead of two states on server just have one state on server and possible few states on client (client side states)&lt;br /&gt;
to collect this info.&lt;br /&gt;
&lt;br /&gt;
== Handle Turn Order ==&lt;br /&gt;
&lt;br /&gt;
If your game goes in clockwise order in natural sitting position nothing really needed you just use standard API and you are good. However if position is complecated&lt;br /&gt;
it may require some trickery.&lt;br /&gt;
&lt;br /&gt;
Usually turn order is done by &amp;quot;game state&amp;quot; (see state machine above). Basically it would be two choices:&lt;br /&gt;
* Turn order depends on game situation (such as we take player with highest number of red cubes)&lt;br /&gt;
* Turn order is custom and assign on previos step - i.e. we not playing in clockwise order anymore. In this case you either need to extend player table with new order info (CANNOT use player_no column) or use order markers that come with game (i.e. marker_ff0000 on position_1). In this we can build player array in right order and pick next player based on previous player using existing helper function such as $this-&amp;gt;createNextPlayerTable($player_ids)&lt;br /&gt;
&lt;br /&gt;
== Implement Notification handling ==&lt;br /&gt;
&lt;br /&gt;
Now to implement things for real we have hook UI actions to ajax calls, and process notifications send by server.&lt;br /&gt;
So previously we hooked onclick js handler right to client animation, in real game its a two&lt;br /&gt;
step operation. When user clicks on something, client sends an ajax call to server, server processes it and updates database, server sends&lt;br /&gt;
notification in response, client hooks animations to server notification. See [[Game_interface_logic:_yourgamename.js#Notifications|JS Notifications]].&lt;br /&gt;
&lt;br /&gt;
Exception to this is client states, if you need to process two step user interaction such as select meeple, place meeple, you may want &lt;br /&gt;
to avoid sending data to server until step is complete (which may involve direct client side animation). See [[BGA_Studio_Cookbook#Multi_Step_Interactions:_Select_Worker.2FPlace_Worker_-_Using_Selection|Multi-Step Interactions]]&lt;br /&gt;
&lt;br /&gt;
Part of the sending notifications would be to update player&#039;s scoring, BGA uses standard control for score (on JS side), see [[Game_interface_logic:_yourgamename.js#Update_players_score|Update Player&#039;s Score]].&lt;br /&gt;
&lt;br /&gt;
In BGA there is only two ways interact with the server (officially)&lt;br /&gt;
* Initial data dump - when JS client starts it gets all current data via setup() method&lt;br /&gt;
* Game actions - ajaxcall from client, it returns error or ok (not data), then server send butch of notifications to client&lt;br /&gt;
&lt;br /&gt;
Note current ajaxcall is super vebosy and prone to errors, I suggest to use helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
				if (!args) args = []; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
				&lt;br /&gt;
				args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
&lt;br /&gt;
				if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
					this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
						this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                                handler); // this is real result handler - it called both on success and error, its is optional param - you rarely need it&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you insert a single action you have to update multiples files:&lt;br /&gt;
* in ggg.js add ajaxcall, i.e. something like &lt;br /&gt;
  this.addActionButton(&#039;pass&#039;,_(&#039;Pass&#039;),()=&amp;gt;this.ajaxcallwrapper(&#039;pass&#039;));&lt;br /&gt;
* in states.php - add action &#039;pass&#039; to list of possible actions&lt;br /&gt;
  &#039;possibleactions&#039; =&amp;gt; [&#039;pass&#039;,&#039;playCard&#039;]&lt;br /&gt;
* in action.php - add action hander, see https://en.doc.boardgamearena.com/Players_actions:_yourgamename.action.php&lt;br /&gt;
* in game.php - add action hander, there you must do the following&lt;br /&gt;
** call checkAction to validate the action&lt;br /&gt;
** possible do more game specific check to validate what player doing is legal (even its not possible from your js side - player can cheat - not allow that)&lt;br /&gt;
** do some database maniplations, using access api&lt;br /&gt;
** send notifications - this is the &amp;quot;reply&amp;quot; for action&lt;br /&gt;
** transition to new state (it very rare that  user will remain in the same state, except for multi-active states)&lt;br /&gt;
* back to ggg.js add notification subsciption and notification handler (two separate things)&lt;br /&gt;
&lt;br /&gt;
== Wrap Up ==&lt;br /&gt;
&lt;br /&gt;
* Implement game progression (getGameProgression() in php)&lt;br /&gt;
* Implement Zombie turn  (zombieTurn() in php)&lt;br /&gt;
* Define and implemented some meaningful statistics for your game (i.e. total points, point from source A, B, C...)&lt;br /&gt;
* The games logs should explain what happened if player was not looking&lt;br /&gt;
* You need to implemented tiebreaking (using aux score field) and updated tiebreaker description in meta-data&lt;br /&gt;
* Make sure all UI strings are marked for translation&lt;br /&gt;
* UI elements which are images (i.e. tokens, cards) should have tooltips&lt;br /&gt;
&lt;br /&gt;
== Alpha ==&lt;br /&gt;
When you think you game is completely working there is still bunch of stuff you have to do/check before telling admin that game is ready, please go though this [[Pre-release checklist]].&lt;br /&gt;
&lt;br /&gt;
If you think its completely ready, let admin know (studio@boardgamearena.com) and it they will push it to alpha.&lt;br /&gt;
&lt;br /&gt;
Finally, visit the game page for your alpha game (https://boardgamearena.com/gamepanel?game=…) to add the following information if you can:&lt;br /&gt;
* Links to the rules (in multiple languages if available).&lt;br /&gt;
* Links to teaching videos.&lt;br /&gt;
* In the &amp;quot;On the web&amp;quot; section, links to:&lt;br /&gt;
** The official website for the game (if there is one).&lt;br /&gt;
** The BoardGameGeek page for the game.&lt;br /&gt;
* Consider writing a summary of the rules.&lt;br /&gt;
&lt;br /&gt;
== Level Up ==&lt;br /&gt;
&lt;br /&gt;
When you successfully created a basic game and you want more, it&#039;s time to make it fancy!&lt;br /&gt;
&lt;br /&gt;
* Add game externtions and variants using gameoptions file&lt;br /&gt;
* Add user preferences for customizations&lt;br /&gt;
* Use theming! That involves replacing hardwood background, changing tooltips, using different sounds, different fonts, changing state prompt and logs&lt;br /&gt;
* You can use fancy scoring board at the end of game instead of default nothing&lt;br /&gt;
* And finally super cool dice rolling, card flipping and victory points evaporating effects&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=First_steps_with_BGA_Studio&amp;diff=11471</id>
		<title>First steps with BGA Studio</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=First_steps_with_BGA_Studio&amp;diff=11471"/>
		<updated>2022-01-19T09:30:11Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Let&amp;#039;s code! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Connect to the BGA Studio website ==&lt;br /&gt;
&lt;br /&gt;
Go to BGA Studio website:&lt;br /&gt;
http://studio.boardgamearena.com&lt;br /&gt;
&lt;br /&gt;
Choose one of your 10 accounts (ex: myusername0, password was sent in welcome email), and login into the website - as you would do for Board Game Arena.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have account see [[How to join BGA developer team?]]&lt;br /&gt;
&lt;br /&gt;
== Create a new game project ==&lt;br /&gt;
&lt;br /&gt;
You can do most of the projects-related operations from &amp;quot;Control Panel / Manage games&amp;quot;. In particular, you can create a new project automatically from there.&lt;br /&gt;
&lt;br /&gt;
Your first &amp;quot;game&amp;quot; should be one of the tutorials, so your project name should be something like &amp;quot;tutorialbob&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
At this stage it is too early to create a real game but if you really don&#039;t want to start until you have a game in mind, check [[Create a game in BGA Studio: Complete Walkthrough]]&lt;br /&gt;
section &amp;quot;Select a First Game&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For reference top bar studio links&lt;br /&gt;
* AVAILABLE LICENSES - list of all available licenses (not public domain) -  http://en.studio.boardgamearena.com/#!licensing&lt;br /&gt;
* STUDIO PROJECTS - list of all registered studio projects - http://en.studio.boardgamearena.com/#!projects &lt;br /&gt;
* CONTROL PANEL - manage projects - http://en.studio.boardgamearena.com/#!controlpanel&lt;br /&gt;
&lt;br /&gt;
== Connect to your SFTP folder == &lt;br /&gt;
&lt;br /&gt;
From the initial email from the Studio you get:&lt;br /&gt;
* the name of the SFTP server to connect to&lt;br /&gt;
* your SFTP login and password&lt;br /&gt;
&lt;br /&gt;
Using this information:&lt;br /&gt;
# Connect to the SFTP server using your SFTP login and password, through your favourite SFTP client software (such as [http://winscp.net/ WinSCP], see [[Tools_and_tips_of_BGA_Studio#File_Sync_on_Windows|File Sync]])&lt;br /&gt;
# Check that your remote home folder contains one folder for each of the three example games (reversi, hearts, gomoku). If you have already created a new game project, one additional folder should be in your &amp;quot;home&amp;quot; folder.&lt;br /&gt;
# Note: You have to setup AUTOMATED sync between your folder and remote folder, manually ftp&#039;ing files would be no-starter. For WinSCP you can do this from the file menu (Commands-&amp;gt;Keep remote directories up to Date...)&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s code! ==&lt;br /&gt;
&lt;br /&gt;
Now, you can try to launch a new game on BGA Studio from the &amp;quot;Play now&amp;quot; menu entry, as you would do on Board Game Arena website.&lt;br /&gt;
&lt;br /&gt;
# To launch your game from Studio go to Studio -&amp;gt; Control Panel -&amp;gt; Manage games -&amp;gt; &amp;lt;your_game&amp;gt; -&amp;gt; &amp;lt;your_game_page&amp;gt; -&amp;gt; Play now&lt;br /&gt;
# Use the &#039;I want between X and X&#039; players to tick down the maximum players number to the minimum&lt;br /&gt;
# Click &#039;Express start&#039;: your game launches with the maximum number of players specified. It shows an empty canvas: in the game zone you just have a sentence &#039;This is your game interface. You can edit this HTML in your &amp;quot;.tpl&amp;quot; file.&#039;. If you don&#039;t see Express start button make sure you are in Manual mode for game creation.&lt;br /&gt;
# Switch to your SFTP home folder, go into your game folder. Edit the game_game.tpl file, and change this sentence to &#039;Hey, this is my first game!&#039;, then save.&lt;br /&gt;
# Go back to your browser and refresh, check that the game zone has updated.&lt;br /&gt;
# Click the red arrow next to a test account&#039;s name in the player panel to view the game from that player&#039;s account &amp;lt;br/&amp;gt;[[File:Change_active_player.jpg]]&lt;br /&gt;
# From the Player page or Table page click on the link &amp;quot;You are playing &amp;lt;name of game&amp;gt; (realtime)&amp;quot; (or click on the &#039;Gear&#039; icon on the top right) and choose &#039;Express STOP&#039;. The game ends automatically and you are brought back to the table screen for this ended game.&lt;br /&gt;
# Switch to your game folder, go into the img folder and overwrite your game_box.png file with another image.&lt;br /&gt;
# Go back to your browser, &#039;&#039;&#039;empty your browser cache&#039;&#039;&#039;, then refresh the page, and check that the game box image has been updated.&lt;br /&gt;
&lt;br /&gt;
Then you can modify the provided skeleton and begin to develop your game :)&lt;br /&gt;
&lt;br /&gt;
== Commit your changes ==&lt;br /&gt;
&lt;br /&gt;
Committing uploads your changes on BGA&#039;s [http://en.wikipedia.org/wiki/Revision_control revision control] system. This is an extra assurance not to lose your code, and to have the possibility to get a previous version of your code if you need to backtrack. It also helps us to follow your progress (we get an email when you commit). So you should commit from time to time, when you hit some landmark in your development.&lt;br /&gt;
&lt;br /&gt;
You can automatically commit your sources in the repository from &amp;quot;Control Panel / Manage Games / Your game / Commit my modifications now&amp;quot;. Then:&lt;br /&gt;
&lt;br /&gt;
# Enter your commit comment (such as &#039;My first commit&#039;) then hit the &#039;Submit&#039; button;&lt;br /&gt;
# Check the log for errors, it should end with the following lines:&lt;br /&gt;
&lt;br /&gt;
  Transmitting file data .&lt;br /&gt;
  Committed revision #revision number#.&lt;br /&gt;
  HAL says: done.&lt;br /&gt;
&lt;br /&gt;
NOTE: committing the code is currently not working until admin commits it manually the first time. Even if it does you cannot automatically deal with this version control system except for committing. Therefore its recommended to use another means of storing the code in version control system, such as local git repo or github, see [[Tools_and_tips_of_BGA_Studio#Version_Control|Version Control]]&lt;br /&gt;
&lt;br /&gt;
== That&#039;s all! ==&lt;br /&gt;
&lt;br /&gt;
Now you know about the basics of updating your game on BGA Studio and testing your changes.&lt;br /&gt;
&lt;br /&gt;
Now you can select one of the tutorials to play with and start coding.&lt;br /&gt;
&lt;br /&gt;
For links to tutorials and ALL studio documentation see [[Studio]].&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=First_steps_with_BGA_Studio&amp;diff=11470</id>
		<title>First steps with BGA Studio</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=First_steps_with_BGA_Studio&amp;diff=11470"/>
		<updated>2022-01-19T09:02:07Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Let&amp;#039;s code! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Connect to the BGA Studio website ==&lt;br /&gt;
&lt;br /&gt;
Go to BGA Studio website:&lt;br /&gt;
http://studio.boardgamearena.com&lt;br /&gt;
&lt;br /&gt;
Choose one of your 10 accounts (ex: myusername0, password was sent in welcome email), and login into the website - as you would do for Board Game Arena.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have account see [[How to join BGA developer team?]]&lt;br /&gt;
&lt;br /&gt;
== Create a new game project ==&lt;br /&gt;
&lt;br /&gt;
You can do most of the projects-related operations from &amp;quot;Control Panel / Manage games&amp;quot;. In particular, you can create a new project automatically from there.&lt;br /&gt;
&lt;br /&gt;
Your first &amp;quot;game&amp;quot; should be one of the tutorials, so your project name should be something like &amp;quot;tutorialbob&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
At this stage it is too early to create a real game but if you really don&#039;t want to start until you have a game in mind, check [[Create a game in BGA Studio: Complete Walkthrough]]&lt;br /&gt;
section &amp;quot;Select a First Game&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For reference top bar studio links&lt;br /&gt;
* AVAILABLE LICENSES - list of all available licenses (not public domain) -  http://en.studio.boardgamearena.com/#!licensing&lt;br /&gt;
* STUDIO PROJECTS - list of all registered studio projects - http://en.studio.boardgamearena.com/#!projects &lt;br /&gt;
* CONTROL PANEL - manage projects - http://en.studio.boardgamearena.com/#!controlpanel&lt;br /&gt;
&lt;br /&gt;
== Connect to your SFTP folder == &lt;br /&gt;
&lt;br /&gt;
From the initial email from the Studio you get:&lt;br /&gt;
* the name of the SFTP server to connect to&lt;br /&gt;
* your SFTP login and password&lt;br /&gt;
&lt;br /&gt;
Using this information:&lt;br /&gt;
# Connect to the SFTP server using your SFTP login and password, through your favourite SFTP client software (such as [http://winscp.net/ WinSCP], see [[Tools_and_tips_of_BGA_Studio#File_Sync_on_Windows|File Sync]])&lt;br /&gt;
# Check that your remote home folder contains one folder for each of the three example games (reversi, hearts, gomoku). If you have already created a new game project, one additional folder should be in your &amp;quot;home&amp;quot; folder.&lt;br /&gt;
# Note: You have to setup AUTOMATED sync between your folder and remote folder, manually ftp&#039;ing files would be no-starter. For WinSCP you can do this from the file menu (Commands-&amp;gt;Keep remote directories up to Date...)&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s code! ==&lt;br /&gt;
&lt;br /&gt;
Now, you can try to launch a new game on BGA Studio from the &amp;quot;Play now&amp;quot; menu entry, as you would do on Board Game Arena website.&lt;br /&gt;
&lt;br /&gt;
# To launch your game from studio go to studio control panel -&amp;gt; manage games -&amp;gt; &amp;lt;your_game&amp;gt; -&amp;gt; &amp;lt;your_game_page&amp;gt; -&amp;gt; Play now&lt;br /&gt;
# Use the &#039;I want between X and X&#039; players to tick down the maximum players number to the minimum&lt;br /&gt;
# Click &#039;Express start&#039;: your game launches with the maximum number of players specified. It shows an empty canvas: in the game zone you just have a sentence &#039;This is your game interface. You can edit this HTML in your &amp;quot;.tpl&amp;quot; file.&#039;. If you don&#039;t see Express start button make sure you are in Manual mode for game creation.&lt;br /&gt;
# Switch to your SFTP home folder, go into your game folder. Edit the game_game.tpl file, and change this sentence to &#039;Hey, this is my first game!&#039;, then save.&lt;br /&gt;
# Go back to your browser and refresh, check that the game zone has updated.&lt;br /&gt;
# Click the red arrow next to a test account&#039;s name in the player panel to view the game from that player&#039;s account &amp;lt;br/&amp;gt;[[File:Change_active_player.jpg]]&lt;br /&gt;
# From the Player page or Table page click on the link &amp;quot;You are playing &amp;lt;name of game&amp;gt; (realtime)&amp;quot; (or click on the &#039;Gear&#039; icon on the top right) and choose &#039;Express STOP&#039;. The game ends automatically and you are brought back to the table screen for this ended game.&lt;br /&gt;
# Switch to your game folder, go into the img folder and overwrite your game_box.png file with another image.&lt;br /&gt;
# Go back to your browser, &#039;&#039;&#039;empty your browser cache&#039;&#039;&#039;, then refresh the page, and check that the game box image has been updated.&lt;br /&gt;
&lt;br /&gt;
Then you can modify the provided skeleton and begin to develop your game :)&lt;br /&gt;
&lt;br /&gt;
== Commit your changes ==&lt;br /&gt;
&lt;br /&gt;
Committing uploads your changes on BGA&#039;s [http://en.wikipedia.org/wiki/Revision_control revision control] system. This is an extra assurance not to lose your code, and to have the possibility to get a previous version of your code if you need to backtrack. It also helps us to follow your progress (we get an email when you commit). So you should commit from time to time, when you hit some landmark in your development.&lt;br /&gt;
&lt;br /&gt;
You can automatically commit your sources in the repository from &amp;quot;Control Panel / Manage Games / Your game / Commit my modifications now&amp;quot;. Then:&lt;br /&gt;
&lt;br /&gt;
# Enter your commit comment (such as &#039;My first commit&#039;) then hit the &#039;Submit&#039; button;&lt;br /&gt;
# Check the log for errors, it should end with the following lines:&lt;br /&gt;
&lt;br /&gt;
  Transmitting file data .&lt;br /&gt;
  Committed revision #revision number#.&lt;br /&gt;
  HAL says: done.&lt;br /&gt;
&lt;br /&gt;
NOTE: committing the code is currently not working until admin commits it manually the first time. Even if it does you cannot automatically deal with this version control system except for committing. Therefore its recommended to use another means of storing the code in version control system, such as local git repo or github, see [[Tools_and_tips_of_BGA_Studio#Version_Control|Version Control]]&lt;br /&gt;
&lt;br /&gt;
== That&#039;s all! ==&lt;br /&gt;
&lt;br /&gt;
Now you know about the basics of updating your game on BGA Studio and testing your changes.&lt;br /&gt;
&lt;br /&gt;
Now you can select one of the tutorials to play with and start coding.&lt;br /&gt;
&lt;br /&gt;
For links to tutorials and ALL studio documentation see [[Studio]].&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Gamehelptutorialpezzin&amp;diff=11469</id>
		<title>Gamehelptutorialpezzin</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Gamehelptutorialpezzin&amp;diff=11469"/>
		<updated>2022-01-19T08:56:45Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: Created page with &amp;quot;Ciao, this is my tutorial page.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ciao, this is my tutorial page.&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Game_database_model:_dbmodel.sql&amp;diff=11467</id>
		<title>Game database model: dbmodel.sql</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Game_database_model:_dbmodel.sql&amp;diff=11467"/>
		<updated>2022-01-18T22:36:54Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* PHP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
In this file you specify the database schema of your game.&lt;br /&gt;
&lt;br /&gt;
This file contains SQL queries that will be executed during the creation of your game table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; you can&#039;t change the database schema during the game.&lt;br /&gt;
&lt;br /&gt;
== Create your schema ==&lt;br /&gt;
&lt;br /&gt;
To build this file, we recommend you to build the tables you need with the PhpMyAdmin tool (see BGA user guide), and then to export them and to copy/paste the content inside this file.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; you must not use for a column the same name as for the table, as the framework replay function relies on regexp substitution to save/restore a previous state in a clone table with another name.&lt;br /&gt;
&lt;br /&gt;
Example: Deck component, see [[Deck]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example: Euro Game. See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rules you should follow:&lt;br /&gt;
&lt;br /&gt;
* Do not overcomplicate, you are dealing with games with 50-500 pieces!&lt;br /&gt;
** If you have 5 tables for a card game with 30 cards - it is overkill&lt;br /&gt;
* Database should only be storing dynamic data, all static data should be stored in material.php.inc&lt;br /&gt;
** Example: if you have cards that have power, color and special abilities. In the database you only need to store the card type, all the other properties should not be there. Only exception being if it changes during the game.&lt;br /&gt;
* Columns should be permanent, independent of game data, i.e. location, type, position, row, etc&lt;br /&gt;
** Example: do not create columns like Counry1, Country2, Country3, ...&lt;br /&gt;
* Do not store translatable string in the database, use integer number of &amp;quot;ident&amp;quot; to access properties&lt;br /&gt;
** I.e. card type should be &amp;quot;22&amp;quot; or &amp;quot;bob_cat&amp;quot;, instead of &amp;quot;Bob&#039;s cat&amp;quot;&lt;br /&gt;
* Create separate module in php to handle all database queries, do a lot of type checking to prevent SQL injections&lt;br /&gt;
&lt;br /&gt;
Example of method handling database query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    // Set token state&lt;br /&gt;
    function setTokenState($token_key, $state) {&lt;br /&gt;
        self::checkState($state); // ensure state is number&lt;br /&gt;
        self::checkKey($token_key); // ensure key is alphanum&lt;br /&gt;
        $sql = &amp;quot;UPDATE &amp;quot; . $this-&amp;gt;table;&lt;br /&gt;
        $sql .= &amp;quot; SET token_state=&#039;$state&#039;&amp;quot;;&lt;br /&gt;
        $sql .= &amp;quot; WHERE token_key=&#039;$token_key&#039;&amp;quot;; // don&#039;t need to escape anymore since we checked key before&lt;br /&gt;
        self::DbQuery($sql);&lt;br /&gt;
        return $state;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Default tables ==&lt;br /&gt;
&lt;br /&gt;
By default, BGA creates 4 tables for your game: &#039;&#039;&#039;global&#039;&#039;&#039;, &#039;&#039;&#039;stats&#039;&#039;&#039;, &#039;&#039;&#039;gamelog&#039;&#039;&#039;, and &#039;&#039;&#039;player&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You &#039;&#039;&#039;MUST NOT MODIFY&#039;&#039;&#039; the schemas of the &#039;&#039;&#039;global&#039;&#039;&#039;, &#039;&#039;&#039;stats&#039;&#039;&#039; or &#039;&#039;&#039;gamelog&#039;&#039;&#039; tables (and you must not access them directly with SQL queries in your PHP code).&lt;br /&gt;
&lt;br /&gt;
=== The &#039;&#039;&#039;player&#039;&#039;&#039; table ===&lt;br /&gt;
&lt;br /&gt;
You may add columns to the &#039;&#039;&#039;player&#039;&#039;&#039; table. This is very practical to add simple values associated with players. &#039;&#039;&#039;NB:&#039;&#039;&#039; you must not alter existing columns created by the framework.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE `player` ADD `player_reserve_size` SMALLINT UNSIGNED NOT NULL DEFAULT &#039;7&#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The commonly used columns of default &amp;quot;player&amp;quot; table are:&lt;br /&gt;
* &amp;lt;strong&amp;gt;player_no&amp;lt;/strong&amp;gt;: the index of player in natural playing order (starting with 1)&lt;br /&gt;
* &amp;lt;strong&amp;gt;player_id&amp;lt;/strong&amp;gt; (int)&lt;br /&gt;
* &amp;lt;strong&amp;gt;player_name&amp;lt;/strong&amp;gt;: (note: it is better to access this data with getActivePlayerName() or loadPlayersBasicInfos() methods)&lt;br /&gt;
* &amp;lt;strong&amp;gt;player_score&amp;lt;/strong&amp;gt;: the current score of the player (displayed in the player panel). You must update this field to update player&#039;s scores.&lt;br /&gt;
* &amp;lt;strong&amp;gt;player_score_aux&amp;lt;/strong&amp;gt;: the secondary score, used as a tie breaker. You must update this field according to tie breaking rules of the game (see also: [[Main_game_logic:_yourgamename.game.php#Manage_player_scores_and_Tie_breaker|Manage_player_scores_and_Tie_breaker]])&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;player_table_order&amp;lt;/strong&amp;gt;: gives an indication of the rank of the player by order of arrival in the lobby (starting with 1). It is not the same as player_no (which is the player order &amp;lt;u&amp;gt;within&amp;lt;/u&amp;gt; the game). player_table_order is useful for setting custom teams if desired in a game option (for instance, 1st-2nd vs 3rd-4th).&amp;lt;br/&amp;gt;&amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; player_table_order &#039;&#039;only exists during game initialization&#039;&#039; (in the &#039;&#039;&#039;setupNewGame&#039;&#039;&#039; function). It is not added as a column in the &#039;&#039;&#039;players&#039;&#039;&#039; Db table.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt;&amp;lt;u&amp;gt;CAUTION:&amp;lt;/u&amp;gt;&amp;lt;/strong&amp;gt; &#039;&#039;&#039;player_table_order&#039;&#039;&#039; is not guaranteed to be equal to the rank of the player in the table. For example, in a 4-player game, if the table was full but the 3rd player leaves before the game starts, the 4th player becomes 3rd on this table &amp;lt;u&amp;gt;but&amp;lt;/u&amp;gt; their player_table_no is still equal to 4! If another player then joins, their player_table_no will then be 5...&amp;lt;br /&amp;gt;Thus, it is essential to normalize these values first in the game setup if you wish to use them to prevent bugs at game launch. For example, if the set of player_table_order are &amp;lt;player A&amp;gt;: 3, &amp;lt;player B&amp;gt;: 2, &amp;lt;player C&amp;gt;: 5, &amp;lt;player D&amp;gt;: 7, you see that you can&#039;t read that values as ranks directly, but you can still deduce that &amp;lt;player B&amp;gt; was 1st on the table, then &amp;lt;player A&amp;gt; then &amp;lt;player C&amp;gt; then &amp;lt;player D&amp;gt;&amp;amp;nbsp;&amp;amp;#128521;&lt;br /&gt;
&lt;br /&gt;
See [https://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Assigning_Player_Order Assigning Player Order] in the &#039;&#039;&#039;BGA Studio Cookbook&#039;&#039;&#039; for an example.&lt;br /&gt;
&lt;br /&gt;
== CREATE TABLES ==&lt;br /&gt;
you can create tables, using engine InnoDB&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `hands` &lt;br /&gt;
(&lt;br /&gt;
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, &lt;br /&gt;
`player_id` TINYINT(1) NOT NULL,&lt;br /&gt;
`1` BOOL NOT NULL DEFAULT 1,	&lt;br /&gt;
`2` BOOL NOT NULL DEFAULT 1,	&lt;br /&gt;
`3` BOOL NOT NULL DEFAULT 1,	&lt;br /&gt;
`4` BOOL NOT NULL DEFAULT 1,	&lt;br /&gt;
`5` BOOL NOT NULL DEFAULT 1,		&lt;br /&gt;
`6` BOOL NOT NULL DEFAULT 1,	&lt;br /&gt;
`7` BOOL NOT NULL DEFAULT 1,	&lt;br /&gt;
PRIMARY KEY (`id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: if you put comments, you cannot do it in the same line as code.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
`3` BOOL NOT NULL DEFAULT 1, --  activated or not&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will also comment out `3` BOOL, and that code will not be executed.&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
Database initialization should be in function setupNewGame() in &#039;gamename.game.php&#039;.&lt;br /&gt;
&lt;br /&gt;
Database schema migration should be in function upgradeTableDb(), see below.&lt;br /&gt;
&lt;br /&gt;
Warning: all CREATE/ALTER tables and view should be in dbmodel.sql. Do not call these queries from php to avoid implicit commits https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html&lt;br /&gt;
which will cause issues. The only time you can do such queries from php is in the upgradeTableDb method.&lt;br /&gt;
&lt;br /&gt;
== Errors Log ==&lt;br /&gt;
To trace Database creation check the logs that you can access in /admin/studio.&lt;br /&gt;
&lt;br /&gt;
== Post-release database modification ==&lt;br /&gt;
If you want to modify your database schema after the first release of your game in production, you should implement upgradeTableDb method, see [[Post-release phase#Updating the database schema|Updating the database schema after release]]&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11466</id>
		<title>Create a game in BGA Studio: Complete Walkthrough</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11466"/>
		<updated>2022-01-18T22:35:40Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Level Up */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This document is not a tutorial, but step by step instructions on how to build your own first game adaptation using BGA Studio framework.&lt;br /&gt;
&lt;br /&gt;
Before you read this material, you must:&lt;br /&gt;
* Read the overall presentations of the BGA [[Studio]].&lt;br /&gt;
* Some-what know the languages used by BGA Studio: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
* Create a game using one of the available tutorials. Don&#039;t bother with a new game if you have not completed at least one of the tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck or have questions about this page post on [https://forum.boardgamearena.com/viewforum.php?f=12 BGA Developers forum].&lt;br /&gt;
If you&#039;re uncomfortable posting on the public forum you can send messages directly to developers who post answers on that forum but NOT the BGA admins.&lt;br /&gt;
If you find typos in this wiki - fix it.&lt;br /&gt;
&lt;br /&gt;
== Select a First Game ==&lt;br /&gt;
&lt;br /&gt;
For your first &#039;&#039;&#039;real&#039;&#039;&#039; game you must either&lt;br /&gt;
* Select a game from [https://en.studio.boardgamearena.com/licensing Available Licenses]&lt;br /&gt;
* Or from the Public Domain&lt;br /&gt;
&lt;br /&gt;
But what if the game you want is not there? If you are able to successfully publish your first game, you would gain the trust of the BGA admins and they will be happy to assist you in obtaining a license for a game you really want to do or you can request a license yourself. You can read more about game licenses on [[BGA Game licenses]] page.&lt;br /&gt;
&lt;br /&gt;
Once you selected the game but before creating a new project, please take a few seconds to check that someone is not already developing this game. If it is the case, maybe you can propose to join the project?&lt;br /&gt;
&lt;br /&gt;
[http://en.studio.boardgamearena.com/#!projects Check the list of current projects]&lt;br /&gt;
&lt;br /&gt;
Even if you see a few projects with name of the game they may not be active. There are a lot of abandoned game projects. If it&#039;s not clear by the status, post to Developers forum asking if anybody actively working on the project or send a message to developers listed for the abandoned projects, and at the same time ask admins on the same forum post to send you graphics for that game if they have them (there a button on [https://en.studio.boardgamearena.com/licensing Available Licenses] page to request graphics, but it will just send email).&lt;br /&gt;
&lt;br /&gt;
If your goal was to fix bugs in an existing project, first try to locate on studio, projects developed by bga admins are not in the studio. Then get read only access to the project and you can create your own as a copy of the existing one. Contact existing project admin about getting write access to the original project or if they willing to take your patches - apply them.&lt;br /&gt;
&lt;br /&gt;
If you want to take over an existing project first ask on forum to see if project is abandoned, then get read only access (via project list) and see if this worth using it, if it has no code or graphics just start from the scratch, don&#039;t worry about project name it can be renamed later.&lt;br /&gt;
&lt;br /&gt;
== Create a project ==&lt;br /&gt;
&lt;br /&gt;
If you have not already, you have to create a project in BGA Studio for this game. If the original game name is taken use gamenameYOURINITIALS&lt;br /&gt;
template, i.e.&amp;quot;heartsla&amp;quot;. Don&#039;t worry too much about the name, if game would be good enough to be publish it will be renamed to original name. &lt;br /&gt;
&lt;br /&gt;
Find and start the game in turn based mode, make sure it works.&lt;br /&gt;
&lt;br /&gt;
Second, modify the text in .tpl file, reload the page in the browser and make sure your ftp sync works as expected.&lt;br /&gt;
Note: if you have not setup [http://en.doc.boardgamearena.com/Tools_and_tips_of_BGA_Studio#File_Sync FTP auto-sync] yet, do it now, manually copying files is a no-starter.&lt;br /&gt;
&lt;br /&gt;
Update your project status in [http://en.studio.boardgamearena.com/#!studio Control Panel &amp;gt; Manage games] page, you can say &amp;quot;development started&amp;quot; or &amp;quot;waiting for license&amp;quot; or &amp;quot;waiting for graphics&amp;quot; or combination of those.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Development Tools ==&lt;br /&gt;
&lt;br /&gt;
At some point you need to setup your development environment which consist of multiple tools, such as&lt;br /&gt;
* Editor or IDE&lt;br /&gt;
* Browser with dev tools&lt;br /&gt;
* File sync tools&lt;br /&gt;
* BGA Web tools&lt;br /&gt;
* Image manipulation tools&lt;br /&gt;
* Version control tools&lt;br /&gt;
&lt;br /&gt;
Please scan though articles from [[Studio#BGA_Studio_user_guide]] especially related to debugging and tools, there is a lot of useful info there.&lt;br /&gt;
&lt;br /&gt;
== Hook version control system ==&lt;br /&gt;
&lt;br /&gt;
If its a real game I would commit the code to version control right at start. You going to find yourself in the situation&lt;br /&gt;
when game does not even start anymore and no way of debugging it unless you have a way to revert. That is where version control becomes very handy.&lt;br /&gt;
If you don&#039;t know what I am talking about then at least back-up your files after each of major steps. Starting now.&lt;br /&gt;
You can also create a project on github, but make sure &#039;&#039;&#039;you don&#039;t commit original publisher graphics files&#039;&#039;&#039; and &#039;&#039;&#039;you don&#039;t include a file with your sftp password&#039;&#039;&#039; (github is automatically crawled for passwords by hackers; a hacking attempt occurred on BGA studio for this reason in June 2020).&lt;br /&gt;
You can (and should) also commit your modification periodically via studio&#039;s control panel.&lt;br /&gt;
&lt;br /&gt;
== Obtain game graphics ==&lt;br /&gt;
&lt;br /&gt;
If you developing a game from Available Licenses games, ask the admins to send you graphics by contacting studio@boardgamearena.com. While that request is being processed (it can take time, as it often requires some back and forth  between the admins and the publishers) you can proceed to next step - project creation.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t get original graphics you go to &#039;&#039;&#039;Scavenger Hunt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you developing a public domain card game you can borrow standard cards from BGA generic assets, see [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Standard game pieces - meeples, cubes, dice can be found here as well [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Go to boardgamegeek.com find your game and obtain 3D game box image, 2D box image, and if you lucky they also sometime have boards and token scans in &amp;quot;Game Pieces&amp;quot; section of Images&lt;br /&gt;
* If that fail google &amp;quot;boardgame &amp;lt;name&amp;gt;&amp;quot; and check Images section&lt;br /&gt;
* Get the rules PDF as well, there tools that allows you to extract graphics from PDF, which usually good for meeples, cubes and such (can use pdfimages command line tool)&lt;br /&gt;
&lt;br /&gt;
Once you get the graphics one way or another you have to massage it to fit in the BGA criteria, which usually involves&lt;br /&gt;
* If publisher sends graphics in one token/card per file mode, you have to stitch them in sprite and scale down&lt;br /&gt;
* For non square tiles and game pieces you need transparency&lt;br /&gt;
* Usually you chop off scoring &amp;quot;ring&amp;quot; around the board of the game since scoring track not needed for online adaptation&lt;br /&gt;
&lt;br /&gt;
More details about graphics requirements can be found here [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
[[File:Rrr_search.png]]&lt;br /&gt;
&lt;br /&gt;
== Obtain game documentation ==&lt;br /&gt;
&lt;br /&gt;
Also at this time obtain a electronic copy of rules, such as PDF (English version). &lt;br /&gt;
&lt;br /&gt;
Also grab any other documents you may find on boardgamegeek such as FAQ, additional Reference books, and user created assistant documents, such&lt;br /&gt;
as cheat-sheets (may be easier to get a data from these then trying to scrub pdf). You create and place them in the doc/ folder of the project then&lt;br /&gt;
exclude them from version control. There is also a misc/ folder now but it will hold up to 1 Mb of data files which would be checked in, so rules pdf&#039;s may not fit there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Update game infos and box graphics ==&lt;br /&gt;
&lt;br /&gt;
Even it does not nothing yet start with making sure game looks descent in the game selector, meaning it has nice box graphics and information is correct. &lt;br /&gt;
&lt;br /&gt;
For that we need to edit [[Game_meta-information: gameinfos.inc.php|gameinfos.inc.php]].&lt;br /&gt;
What you would do for real game you would go to http://boardgamegeek.com find the game and use the information from web-site to fill the gameinfos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step is to replace game_box.png with proper images, usually you can find all images including publisher logo on boardgamegeek website.&lt;br /&gt;
&lt;br /&gt;
Details about images can be found here: [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
Now important step. You have to LOAD these files in studio website through control panel. So go to Control Panel -&amp;gt; Manager Games -&amp;gt; YOURPROJECT&lt;br /&gt;
and press Reload for &#039;Reload game informations&#039; and &#039;Reload game box image&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Gamepanel_sharedcode.png]]&lt;br /&gt;
&lt;br /&gt;
Now try to start the game again. If you some-how introduced a syntax error in gameinfos file it may not actually work (game won&#039;t start).&lt;br /&gt;
Always use &amp;quot;Express Start&amp;quot; button to start the game. You should see a standard state prompt from template. You should see X players on the right, testdude0 .. testdudeX-1.&lt;br /&gt;
To switch between them press the red arrow button near their names, it will open another tab. This way you don&#039;t need to login and logout from multiple accounts!&lt;br /&gt;
&lt;br /&gt;
== Fix source copyright ==&lt;br /&gt;
&lt;br /&gt;
Now since you have your own project, you want put your name in the copyright header, so replace&lt;br /&gt;
&lt;br /&gt;
  © &amp;lt;Your name here&amp;gt; &amp;lt;Your email address here&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
  © John Snow &amp;lt;jsnow@gameofthrones.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well not exactly this but whatever your real name is. For all files in project directory, its about 10 files. Make sure project still starts after that :)&lt;br /&gt;
&lt;br /&gt;
== Reduce the Rules ==&lt;br /&gt;
&lt;br /&gt;
Programming a game will take a lot more time than you may think. Most of the projects in the studio are abandoned because of lack of patience or skill.&lt;br /&gt;
To keep sane, start the game with *reduced* rules and try to complete that first.&lt;br /&gt;
&lt;br /&gt;
* If it has any expansions - do not even attempt to deal with them, not even - &amp;quot;I will just add graphics for them now and not use&amp;quot; - waste of time if you don&#039;t complete basic&lt;br /&gt;
* If it has advanced rules - start with basic rules only, i.e. &amp;quot;beginner game&amp;quot;&lt;br /&gt;
* If it has special rules for 2 player vs 4, start with most basic form (i.e. 4), restrict to 4 players &lt;br /&gt;
* If it has 50 unique cards of 2 each - start with 2 unique cards with 25 each (just to keep it moving)&lt;br /&gt;
* Any sort of rules that you think can be removed and not included in base - set aside for now &lt;br /&gt;
* Ignore any sort of cool animations - dice rolling, card flipping, choo-choo sounds of the trains - all this fluff can be added later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Game Elements ==&lt;br /&gt;
Technically game elements are already designed by board game designer but your job is to map it to program space.&lt;br /&gt;
Each physical piece (card, token, cube) will leave footprints all over the code (unfortunatly in multiple disconnected places).&lt;br /&gt;
To prepare the game you need to sort out these elements, i.e. categorize. I usually have to the following categorization (in object oriented view):&lt;br /&gt;
* Instance - all individual pieces are instances, i.e. two red cubes are two instances of &#039;red cube&#039; type (class)&lt;br /&gt;
* Type - element type which distinctly represents that element in appearence (i.e. red cube is different type than blue cube)&lt;br /&gt;
* Super Type - one of more common types that similar properties (i.e. red OR cube)&lt;br /&gt;
* Player color - supertype specific for player color (sometimes there is no colors but like player 1 - but is conceptually the same, I use color because its easier to track)&lt;br /&gt;
&lt;br /&gt;
Personally I like to encode my elements in string using reverse dns notation listing all the properties above, i.e.&lt;br /&gt;
  meeple_ff0000_7 - this is instance #7 of type meeple_ff0000 (red meeple)&lt;br /&gt;
Or&lt;br /&gt;
  card_yellow_magic_2 - this is instance #2 of yellow card (in this case yellow is color of deck not related to player color) that can do magic&lt;br /&gt;
&lt;br /&gt;
So every game element would be in the&lt;br /&gt;
&lt;br /&gt;
1. Database - instances. The db record would be something like &lt;br /&gt;
  key|location|state&lt;br /&gt;
  meeple_ff0000_7|slot_action_2|1&lt;br /&gt;
  meeple_ff0000_2|tableau_ff0000|0&lt;br /&gt;
2. Material file - types and supertypes, we never need repeating info here, so never list individual instances but only types or supertypes, in this case we don&#039;t really need to define red meeple vs blue meeple&lt;br /&gt;
  &#039;meeple&#039;=&amp;gt;{&#039;name&#039;=&amp;gt;totranslate(&#039;Meeple&#039;)}&lt;br /&gt;
3. Client (js, css, tpl, etc) - instances and types. For example my meeple will be like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;meeple_ff0000_7&amp;quot; class=&amp;quot;meeple meeple_ff0000&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
with .css something like&lt;br /&gt;
  .meeple { background-image: url(img/tokens.png); width: 2em; height: 2em;}&lt;br /&gt;
  .meeple_ff0000 {background-position: 20% 0%;}&lt;br /&gt;
4. Game php - setup and logic. During setup you have to generate all the pieces and place them in right positions. Also sometimes you need to reference elements to code the logic (I usually try to encode all rules in material file as much as possible)&lt;br /&gt;
&lt;br /&gt;
For complex card games I think it is the best to keep all these info and rules in spreadsheet and generate other files such as material.inc.php.&lt;br /&gt;
See more info below about design of the individual layers.&lt;br /&gt;
&lt;br /&gt;
== Create Initial Layout and Game Graphics ==&lt;br /&gt;
&lt;br /&gt;
Mentally it is easier to start with game layout and graphics pieces. Even when nothing is working its give you moral satisfaction!&lt;br /&gt;
&lt;br /&gt;
There are a few ways how the html could have been generated. You could have started with nothing and generate&lt;br /&gt;
it all by javascript, or you could have started with complete game markup in html and make javascript just hide and move pieces around. BGA framework also provides a third way, which is mix of both, plus a template engine to generate HTML using PHP. The only thing that is really annoying about the template engine is that you cannot put any translatable strings in the template (which means any visible text at all). If you are using the template approach all strings have to extracted as variables and injected through PHP (.view.php). This page explains the template engine in great detail:[[Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl|Template Engine]].&lt;br /&gt;
&lt;br /&gt;
The other disadvantage of the template engine is you cannot run and debug it locally, in the beginning of development it&#039;s a lot faster run off local pages, &lt;br /&gt;
you can do it with some trickery described here [[Tools_and_tips_of_BGA_Studio#Speed_up_CSS_development_and_layout|Tools and Tips for BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
During this step you have to decide what technical solutions you will be using, such as&lt;br /&gt;
* Use inline positioning of all moving pieces, controlled by JS. There are a few classes that already exist in Studio to help with that (see [[Studio#Game_interface_.28Client_side.29|Game Interface - Client Side]]). OR use html/css layout engine to position pieces (my personal choice).&lt;br /&gt;
* Use BGA template engine OR create all ui elements by JS OR manually write or generate complete html markup. The game usually contain 200-300 pieces, it seems wrong but actually its faster to type all of this up in html/css when trying write than debug code for page generator.&lt;br /&gt;
Static HTML markup also means you have to use players color or abstracted player number (such as red is 1, blue is 2) not player id&#039;s anywhere in JS, since player id is dynamic by nature.&lt;br /&gt;
&lt;br /&gt;
Start by creating and mapping all games assets, best way is probably to open rule book on &amp;quot;boardgame contents&amp;quot; page and go through every piece. Every pieces of boardgame would have its &amp;quot;print&amp;quot; in multiple files in your game:&lt;br /&gt;
* Some sort if &amp;quot;div&amp;quot; in html, where id of element match id of element in database (easiest way)&lt;br /&gt;
* Css for the element (either unique or for class), usually with background propery refering to part of sprite image&lt;br /&gt;
* Entry in material.inc.php referring to static properties of the element, i.e. name, tooltip, rules, etc&lt;br /&gt;
* Entry in .tpl file to represent static or initial location on the table OR creation template&lt;br /&gt;
&lt;br /&gt;
Here are some specific examples:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create entry in .tpl file for the board, it will be static entry as we never need to create this dynamically&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;board&amp;quot; class=&amp;quot;board shadow board4p&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create entry in .css file for this board and other board variants (in example below we have 4 ppl board whcih is diffrent than 2 ppl board)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.board {&lt;br /&gt;
	position: relative;&lt;br /&gt;
	width: 980px;&lt;br /&gt;
	height: 433px;&lt;br /&gt;
	margin-bottom: 5px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.board4p {&lt;br /&gt;
	background-image: url(img/board4p.jpg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That would be pretty much it for the board itself, as it does not really need a tooltip so we don&#039;t need entry in material.inc.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board Slots&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are interactive areas on the board, usually illustrated as such. In most cases you can get away with rectangular shapes, but sometimes you have to create circle or oval shapes (and in really advanced case would be some svg paths). For slots you can do the following:&lt;br /&gt;
&lt;br /&gt;
Entry in material.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;token_types = array(&lt;br /&gt;
...&lt;br /&gt;
&#039;slot_action_2&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;type&#039; =&amp;gt; &#039;slot_action&#039;,&lt;br /&gt;
  &#039;name&#039; =&amp;gt; clienttranslate(&amp;quot;2 Gray Track Advancements&amp;quot;),&lt;br /&gt;
  &#039;tooltip&#039; =&amp;gt; clienttranslate(&amp;quot;This action gives you two advancements of gray track. You cannot use this action if you cannot complete all advancements.&amp;quot;),&lt;br /&gt;
  &#039;o&#039;=&amp;gt;&amp;quot;1,0,0,gg&amp;quot;, // automatic rules&lt;br /&gt;
),&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in template inside the &amp;quot;board&amp;quot; div&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;slot_action_2&amp;quot; class=&amp;quot;slot_action_2 slot_action slot_w_1 slot&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in .css with absolute position within the board (its actually better to use percentage - would be easier to scale later)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.slot_action_2 {&lt;br /&gt;
	top: 83px;&lt;br /&gt;
	left: 37px;&lt;br /&gt;
}&lt;br /&gt;
.slot_action {&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	width: 46px;&lt;br /&gt;
	height: 26px;&lt;br /&gt;
	padding: 9px 7px 6px 4px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Meeples&#039;&#039;&#039; - also cards, tokens, other mobile stuff&lt;br /&gt;
&lt;br /&gt;
In CSS these guys will use &amp;quot;sprite&amp;quot; images with transparency, so it will look like this this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	background-image: url(img/tokens.png);&lt;br /&gt;
	width: 25px;&lt;br /&gt;
	height: 25px;&lt;br /&gt;
}&lt;br /&gt;
.meeple_ff0000 { /* red */&lt;br /&gt;
	background-position: 14% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As for creation you can either generate them using template (where whole thing wrapped in template block and {COLOR} replace with all possible colors in .view.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_1&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_2&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can declare a template js var in .tpl file &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    var jstpl_mepple = &#039;&amp;lt;div id=&amp;quot;meeple_${color}_${num}&amp;quot; class=&amp;quot;meeple meeple_${color} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;; // this is in .tpl file at the bottom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and create in js, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 var tokenDiv = this.format_block(&#039;jstpl_mepple&#039;, {&lt;br /&gt;
                                &amp;quot;color&amp;quot; : color,&lt;br /&gt;
                                &amp;quot;num&amp;quot; : i&lt;br /&gt;
                            }); // this in js code somewhere before placing it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you dealing with cards and decks, there are pre-build components that can generate stuff for you.&lt;br /&gt;
&lt;br /&gt;
When do you create dom element matching game element?&lt;br /&gt;
* If you have static layout you create it in .tpl file and its always there, but during initial setup or during notification it moved in proper spot (including &amp;quot;removed from the game&amp;quot; spot)&lt;br /&gt;
* If you dynamically generated pieces you create the element during notification, and sometimes during animation. Also don&#039;t forgot to hook event listener to it if its interactive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One of the greatest parts about the web is all client side code can be viewed in your browser, so if you wondering how something is done in another BGA game just load the page and spy on it! In Chrome that would be right click and &amp;quot;Inspect Element&amp;quot;. That would immediately show html of the given element alongside with css used for it (on the right). Another great way to learn is you can add yourself to any BGA project as read only from the project page!&lt;br /&gt;
&lt;br /&gt;
So at the end of this stage you should complete the following (keeping in mind reduced rules/material for first iteration):&lt;br /&gt;
* Create a layout of the game, with positioning of main board, player areas, zones, other supporting areas, etc&lt;br /&gt;
* Create css and html snippets for all game pieces: boards, tokens, meeples, etc. Place them all in initial template (even if they&#039;re not supposed to be visible at start). I.e. create fake player&#039;s hand with cards, put meeples on the board&lt;br /&gt;
* Hook layout to number of players and colors picked by the game and test with multiple players&lt;br /&gt;
* Figure out what you want to display in mini-player boards and hook it up&lt;br /&gt;
* Create material.inc.php and populate with initial values (names, tooltips, rules) for all relevant game elements or classes of elements&lt;br /&gt;
&lt;br /&gt;
If at this time you don&#039;t have graphics yet create pieces with just CSS, you can use shape, background color and object text using css ::after construct to fake the pieces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Injected_text.png]]&lt;br /&gt;
&lt;br /&gt;
== Hook Input and Animation ==&lt;br /&gt;
&lt;br /&gt;
This step can be done before or after some of the server steps, or you go in iterations switching back and forward until you get it done, up to you.&lt;br /&gt;
&lt;br /&gt;
At this time you want to hook clicking on pieces and buttons and provide some reaction, such of moving a piece. The handler code will be replaced later by the server hook, but at the beginning you want your game to be alive as early as possible. &lt;br /&gt;
&lt;br /&gt;
Usually all pieces will be hooked to onclick during JS &amp;quot;setup&amp;quot; method, in addition if you create elements during server notification they have to be hooked up at that time.&lt;br /&gt;
&lt;br /&gt;
You can play with animation effects you want put in place, in general all the pieces that move in real game should be moving, such as meeples, resources tokens/cubes, cards, vp tokens. &lt;br /&gt;
Regular piece animation is provided by BGA framework, but if you use html layout positioning not inline positioning you have to remove absolute positions (inline position styling) after each move. The set of functions for relative position token animation can found in https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js &lt;br /&gt;
&lt;br /&gt;
Also its a good idea to give player a visual cues on what game elements are clickable now, usually it will be a style, such as &amp;quot;active_slot&amp;quot;, with visual effect of white dashed outline (outline is better then border, because border changes will make piece slightly move since it changes the size) or box-shadow (i.e. neon glow)&lt;br /&gt;
&lt;br /&gt;
If you read [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] you know that you should not get carried away with animation, you are creating a board game not a video game... That also applies to sound effects (in general, you should not use any sounds effects beside already provided by framework).&lt;br /&gt;
&lt;br /&gt;
See [[Game_interface_logic:_yourgamename.js#Players_input|Player&#039;s Input]] and [[Game_interface_logic:_yourgamename.js#Access_and_manipulate_the_DOM|Animation and DOM Manipulation]] for JS reference.&lt;br /&gt;
&lt;br /&gt;
== Create Database Schema ==&lt;br /&gt;
&lt;br /&gt;
At some point you have to design your game database. Do it sooner then later since it would be harder to change it later, since some&lt;br /&gt;
code decisions would be based on that.&lt;br /&gt;
&lt;br /&gt;
If you have grid-based abstract game use template from reversi, if you have a card game use template from hearts (the cards one also commented out in generated template for your project). The cards database goes with php class called [[Deck]].&lt;br /&gt;
&lt;br /&gt;
In general make it as simple as possible. &lt;br /&gt;
Think about it, your game has 300 pieces (likely less). Using database to store this amount of data is like shooting a mosquito with a tank.&lt;br /&gt;
Anything more complex then one table with 5 columns or two tables will only going to make it harder to develop and not improve performance.&lt;br /&gt;
You can forget about normalising and any fancy stuff you learn about databases in school. String field for a primary key would be as fast as integer when we talking about this size of data. So don&#039;t over-optimize with trying to have integers field that have state based on bitmask!&lt;br /&gt;
&lt;br /&gt;
Also remember that static (non dynamic) information about the game does not need to be stored in the database, that all include everything that does not change, i.e&lt;br /&gt;
all token/card properties such as name, tooltips, &amp;quot;strength&amp;quot;, color, etc. This is stored in material.inc.php and server has access to it from anywhere, as well as client&lt;br /&gt;
if you send it with getAllDatas(). The only reason store some of it in database if it can affect your queries (i.e. type of token).&lt;br /&gt;
&lt;br /&gt;
Usually design process will contain the following steps:&lt;br /&gt;
* Design game model - model that represent your game in progress, such as at any given step you can restore the game from that model&lt;br /&gt;
* Mapping - now map real game to that model&lt;br /&gt;
* Encoding - now represent this model in database and material file with reasonable amount of fields&lt;br /&gt;
&lt;br /&gt;
Example: &#039;&#039;&#039;The card game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but as part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in your database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position itself usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what info changes and what info is static, static info is always candidate for material file or html&lt;br /&gt;
* For dynamic stuff we should try to reduce amount of fields we need, i.e. we need a field for card, so its one, we need to know what zone cards belong to, its 2, and we have possible few other fields, but if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face  down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
You can also use cards database schema and [[Deck]] implementation for most purposes (even you not dealing with cards).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another Example: &#039;&#039;&#039;The euro game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based &lt;br /&gt;
games can be in most case represented by (string: token_key, string: location, int: state), example of such database schema can be found here:&lt;br /&gt;
[https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php tokens.php].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See [[Game database model: dbmodel.sql]] for details about editing the file.&lt;br /&gt;
&lt;br /&gt;
Note: the simpler the database is the less debugging of db issues you have to deal with including database migration. The tokens database above - if you use it you never have to worry about migration because you don&#039;t need extra tables in 95% of the games.&lt;br /&gt;
Here are some example of how real games are mapped to such database:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chess&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
- chess is grid base game and normally you would use positional columns, but just for the sake of argument, the chess game will look like this&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_white&lt;br /&gt;
|f3&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|P_black_2&lt;br /&gt;
|c6&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|K_black&lt;br /&gt;
|e8&lt;br /&gt;
|1&lt;br /&gt;
|}&lt;br /&gt;
And the state in this case indicated that kind was moved for example (which means castling cannot be performed)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Classic card game&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Lets pretend we need 2 decks for that game&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_spades_1&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_2&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|2 /* position */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_1&lt;br /&gt;
|tableau_common&lt;br /&gt;
|1 /* face down */&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Eminent Domain (card game)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|card_tech_23&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|1 /* face up */&lt;br /&gt;
|-&lt;br /&gt;
|reource_s_22 /* silicon */&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|2 /*  production state */&lt;br /&gt;
|-&lt;br /&gt;
|fighter_F_1&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also look at other games that use Tokens database and access layer: Nippon, Dungeon Petz, Lewis &amp;amp; Clark, Battleship, Russian Railroads, Khronos&lt;br /&gt;
&lt;br /&gt;
== Implement Game Setup ==&lt;br /&gt;
&lt;br /&gt;
Once you have your database schema you can do a proper game setup. Usually you open rulebook on the &amp;quot;Game Setup&amp;quot; page&lt;br /&gt;
and implement these step by step populating the database (using db access API).&lt;br /&gt;
Game initialization is performed in php method setupNewGame, this method is called once when game table is created.&lt;br /&gt;
Game notifications cannot be sent during this time.&lt;br /&gt;
&lt;br /&gt;
== Implement One time game model synchronisation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now at any point in the game we need to make sure that database information can be reflected back in UI, so we fix getAllDatas function&lt;br /&gt;
to return all possible data we need to reconstruct the game. The template for getAllDatas already taking care of player info, but you &lt;br /&gt;
have to alter it to return all other data from database visible to the &amp;quot;current&amp;quot; player.&lt;br /&gt;
&lt;br /&gt;
After that on the client side we should display this data, so in your .js file in setup function (which is the receiver of getAllDatas) you add calls that handle data send by server, usually by calling animation function such as &amp;quot;placeToken&amp;quot; or &amp;quot;placeCard&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Create State Machine ==&lt;br /&gt;
&lt;br /&gt;
Now you need to create a game state machine. &lt;br /&gt;
&lt;br /&gt;
The state handling spread across 4 files, so you have to make sure all the pieces are connected together.&lt;br /&gt;
The state machine states.inc.php defines all the states, and function handlers on php side in a form of string,&lt;br /&gt;
and if any of these functions are not implemented it would be very hard to debug because it will break in random places.&lt;br /&gt;
&lt;br /&gt;
Please first watch this again [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine  BGA game state machine]&lt;br /&gt;
and then please read [[Your game state machine: states.inc.php]].&lt;br /&gt;
&lt;br /&gt;
Now the state machine should be relatively simple. If you find yourself with machine with more than 20 states its probably not the way to go.&lt;br /&gt;
Not all the player interactions need separate states, a lot of things can be implemented directly on client, i.e. if your player need to select&lt;br /&gt;
a reward token, which offers choice of resource, instead of two states on server just have one state on server and possible few states on client (client side states)&lt;br /&gt;
to collect this info.&lt;br /&gt;
&lt;br /&gt;
== Handle Turn Order ==&lt;br /&gt;
&lt;br /&gt;
If your game goes in clockwise order in natural sitting position nothing really needed you just use standard API and you are good. However if position is complecated&lt;br /&gt;
it may require some trickery.&lt;br /&gt;
&lt;br /&gt;
Usually turn order is done by &amp;quot;game state&amp;quot; (see state machine above). Basically it would be two choices:&lt;br /&gt;
* Turn order depends on game situation (such as we take player with highest number of red cubes)&lt;br /&gt;
* Turn order is custom and assign on previos step - i.e. we not playing in clockwise order anymore. In this case you either need to extend player table with new order info (CANNOT use player_no column) or use order markers that come with game (i.e. marker_ff0000 on position_1). In this we can build player array in right order and pick next player based on previous player using existing helper function such as $this-&amp;gt;createNextPlayerTable($player_ids)&lt;br /&gt;
&lt;br /&gt;
== Implement Notification handling ==&lt;br /&gt;
&lt;br /&gt;
Now to implement things for real we have hook UI actions to ajax calls, and process notifications send by server.&lt;br /&gt;
So previously we hooked onclick js handler right to client animation, in real game its a two&lt;br /&gt;
step operation. When user clicks on something, client sends an ajax call to server, server processes it and updates database, server sends&lt;br /&gt;
notification in response, client hooks animations to server notification. See [[Game_interface_logic:_yourgamename.js#Notifications|JS Notifications]].&lt;br /&gt;
&lt;br /&gt;
Exception to this is client states, if you need to process two step user interaction such as select meeple, place meeple, you may want &lt;br /&gt;
to avoid sending data to server until step is complete (which may involve direct client side animation). See [[BGA_Studio_Cookbook#Multi_Step_Interactions:_Select_Worker.2FPlace_Worker_-_Using_Selection|Multi-Step Interactions]]&lt;br /&gt;
&lt;br /&gt;
Part of the sending notifications would be to update player&#039;s scoring, BGA uses standard control for score (on JS side), see [[Game_interface_logic:_yourgamename.js#Update_players_score|Update Player&#039;s Score]].&lt;br /&gt;
&lt;br /&gt;
In BGA there is only two ways interact with the server (officially)&lt;br /&gt;
* Initial data dump - when JS client starts it gets all current data via setup() method&lt;br /&gt;
* Game actions - ajaxcall from client, it returns error or ok (not data), then server send butch of notifications to client&lt;br /&gt;
&lt;br /&gt;
Note current ajaxcall is super vebosy and prone to errors, I suggest to use helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
				if (!args) args = []; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
				&lt;br /&gt;
				args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
&lt;br /&gt;
				if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
					this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
						this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                                handler); // this is real result handler - it called both on success and error, its is optional param - you rarely need it&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you insert a single action you have to update multiples files:&lt;br /&gt;
* in ggg.js add ajaxcall, i.e. something like &lt;br /&gt;
  this.addActionButton(&#039;pass&#039;,_(&#039;Pass&#039;),()=&amp;gt;this.ajaxcallwrapper(&#039;pass&#039;));&lt;br /&gt;
* in states.php - add action &#039;pass&#039; to list of possible actions&lt;br /&gt;
  &#039;possibleactions&#039; =&amp;gt; [&#039;pass&#039;,&#039;playCard&#039;]&lt;br /&gt;
* in action.php - add action hander, see https://en.doc.boardgamearena.com/Players_actions:_yourgamename.action.php&lt;br /&gt;
* in game.php - add action hander, there you must do the following&lt;br /&gt;
** call checkAction to validate the action&lt;br /&gt;
** possible do more game specific check to validate what player doing is legal (even its not possible from your js side - player can cheat - not allow that)&lt;br /&gt;
** do some database maniplations, using access api&lt;br /&gt;
** send notifications - this is the &amp;quot;reply&amp;quot; for action&lt;br /&gt;
** transition to new state (it very rare that  user will remain in the same state, except for multi-active states)&lt;br /&gt;
* back to ggg.js add notification subsciption and notification handler (two separate things)&lt;br /&gt;
&lt;br /&gt;
== Wrap Up ==&lt;br /&gt;
&lt;br /&gt;
* Implement game progression (getGameProgression() in php)&lt;br /&gt;
* Implement Zombie turn  (zombieTurn() in php)&lt;br /&gt;
* Define and implemented some meaningful statistics for your game (i.e. total points, point from source A, B, C...)&lt;br /&gt;
* The games logs should explain what happened if player was not looking&lt;br /&gt;
* You need to implemented tiebreaking (using aux score field) and updated tiebreaker description in meta-data&lt;br /&gt;
* Make sure all UI strings are marked for translation&lt;br /&gt;
* UI elements which are images (i.e. tokens, cards) should have tooltips&lt;br /&gt;
&lt;br /&gt;
== Alpha ==&lt;br /&gt;
When you think you game is completely working there is still bunch of stuff you have to do/check before telling admin that game is ready, please go though this [[Pre-release checklist]].&lt;br /&gt;
&lt;br /&gt;
If you think its completely ready, let admin know (studio@boardgamearena.com) and it they will push it to alpha.&lt;br /&gt;
&lt;br /&gt;
Finally, visit the game page for your alpha game (https://boardgamearena.com/gamepanel?game=…) to add the following information if you can:&lt;br /&gt;
* Links to the rules (in multiple languages if available).&lt;br /&gt;
* Links to teaching videos.&lt;br /&gt;
* In the &amp;quot;On the web&amp;quot; section, links to:&lt;br /&gt;
** The official website for the game (if there is one).&lt;br /&gt;
** The BoardGameGeek page for the game.&lt;br /&gt;
* Consider writing a summary of the rules.&lt;br /&gt;
&lt;br /&gt;
== Level Up ==&lt;br /&gt;
&lt;br /&gt;
When you successfully created a basic game and you want more, it&#039;s time to make it fancy!&lt;br /&gt;
&lt;br /&gt;
* Add game externtions and variants using gameoptions file&lt;br /&gt;
* Add user preferences for customizations&lt;br /&gt;
* Use theming! That involves replacing hardwood background, changing tooltips, using different sounds, different fonts, changing state prompt and logs&lt;br /&gt;
* You can use fancy scoring board at the end of game instead of default nothing&lt;br /&gt;
* And finally super cool dice rolling, card flipping and victory points evaporating effects&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11465</id>
		<title>Create a game in BGA Studio: Complete Walkthrough</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11465"/>
		<updated>2022-01-18T22:35:15Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Wrap Up */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This document is not a tutorial, but step by step instructions on how to build your own first game adaptation using BGA Studio framework.&lt;br /&gt;
&lt;br /&gt;
Before you read this material, you must:&lt;br /&gt;
* Read the overall presentations of the BGA [[Studio]].&lt;br /&gt;
* Some-what know the languages used by BGA Studio: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
* Create a game using one of the available tutorials. Don&#039;t bother with a new game if you have not completed at least one of the tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck or have questions about this page post on [https://forum.boardgamearena.com/viewforum.php?f=12 BGA Developers forum].&lt;br /&gt;
If you&#039;re uncomfortable posting on the public forum you can send messages directly to developers who post answers on that forum but NOT the BGA admins.&lt;br /&gt;
If you find typos in this wiki - fix it.&lt;br /&gt;
&lt;br /&gt;
== Select a First Game ==&lt;br /&gt;
&lt;br /&gt;
For your first &#039;&#039;&#039;real&#039;&#039;&#039; game you must either&lt;br /&gt;
* Select a game from [https://en.studio.boardgamearena.com/licensing Available Licenses]&lt;br /&gt;
* Or from the Public Domain&lt;br /&gt;
&lt;br /&gt;
But what if the game you want is not there? If you are able to successfully publish your first game, you would gain the trust of the BGA admins and they will be happy to assist you in obtaining a license for a game you really want to do or you can request a license yourself. You can read more about game licenses on [[BGA Game licenses]] page.&lt;br /&gt;
&lt;br /&gt;
Once you selected the game but before creating a new project, please take a few seconds to check that someone is not already developing this game. If it is the case, maybe you can propose to join the project?&lt;br /&gt;
&lt;br /&gt;
[http://en.studio.boardgamearena.com/#!projects Check the list of current projects]&lt;br /&gt;
&lt;br /&gt;
Even if you see a few projects with name of the game they may not be active. There are a lot of abandoned game projects. If it&#039;s not clear by the status, post to Developers forum asking if anybody actively working on the project or send a message to developers listed for the abandoned projects, and at the same time ask admins on the same forum post to send you graphics for that game if they have them (there a button on [https://en.studio.boardgamearena.com/licensing Available Licenses] page to request graphics, but it will just send email).&lt;br /&gt;
&lt;br /&gt;
If your goal was to fix bugs in an existing project, first try to locate on studio, projects developed by bga admins are not in the studio. Then get read only access to the project and you can create your own as a copy of the existing one. Contact existing project admin about getting write access to the original project or if they willing to take your patches - apply them.&lt;br /&gt;
&lt;br /&gt;
If you want to take over an existing project first ask on forum to see if project is abandoned, then get read only access (via project list) and see if this worth using it, if it has no code or graphics just start from the scratch, don&#039;t worry about project name it can be renamed later.&lt;br /&gt;
&lt;br /&gt;
== Create a project ==&lt;br /&gt;
&lt;br /&gt;
If you have not already, you have to create a project in BGA Studio for this game. If the original game name is taken use gamenameYOURINITIALS&lt;br /&gt;
template, i.e.&amp;quot;heartsla&amp;quot;. Don&#039;t worry too much about the name, if game would be good enough to be publish it will be renamed to original name. &lt;br /&gt;
&lt;br /&gt;
Find and start the game in turn based mode, make sure it works.&lt;br /&gt;
&lt;br /&gt;
Second, modify the text in .tpl file, reload the page in the browser and make sure your ftp sync works as expected.&lt;br /&gt;
Note: if you have not setup [http://en.doc.boardgamearena.com/Tools_and_tips_of_BGA_Studio#File_Sync FTP auto-sync] yet, do it now, manually copying files is a no-starter.&lt;br /&gt;
&lt;br /&gt;
Update your project status in [http://en.studio.boardgamearena.com/#!studio Control Panel &amp;gt; Manage games] page, you can say &amp;quot;development started&amp;quot; or &amp;quot;waiting for license&amp;quot; or &amp;quot;waiting for graphics&amp;quot; or combination of those.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Development Tools ==&lt;br /&gt;
&lt;br /&gt;
At some point you need to setup your development environment which consist of multiple tools, such as&lt;br /&gt;
* Editor or IDE&lt;br /&gt;
* Browser with dev tools&lt;br /&gt;
* File sync tools&lt;br /&gt;
* BGA Web tools&lt;br /&gt;
* Image manipulation tools&lt;br /&gt;
* Version control tools&lt;br /&gt;
&lt;br /&gt;
Please scan though articles from [[Studio#BGA_Studio_user_guide]] especially related to debugging and tools, there is a lot of useful info there.&lt;br /&gt;
&lt;br /&gt;
== Hook version control system ==&lt;br /&gt;
&lt;br /&gt;
If its a real game I would commit the code to version control right at start. You going to find yourself in the situation&lt;br /&gt;
when game does not even start anymore and no way of debugging it unless you have a way to revert. That is where version control becomes very handy.&lt;br /&gt;
If you don&#039;t know what I am talking about then at least back-up your files after each of major steps. Starting now.&lt;br /&gt;
You can also create a project on github, but make sure &#039;&#039;&#039;you don&#039;t commit original publisher graphics files&#039;&#039;&#039; and &#039;&#039;&#039;you don&#039;t include a file with your sftp password&#039;&#039;&#039; (github is automatically crawled for passwords by hackers; a hacking attempt occurred on BGA studio for this reason in June 2020).&lt;br /&gt;
You can (and should) also commit your modification periodically via studio&#039;s control panel.&lt;br /&gt;
&lt;br /&gt;
== Obtain game graphics ==&lt;br /&gt;
&lt;br /&gt;
If you developing a game from Available Licenses games, ask the admins to send you graphics by contacting studio@boardgamearena.com. While that request is being processed (it can take time, as it often requires some back and forth  between the admins and the publishers) you can proceed to next step - project creation.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t get original graphics you go to &#039;&#039;&#039;Scavenger Hunt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you developing a public domain card game you can borrow standard cards from BGA generic assets, see [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Standard game pieces - meeples, cubes, dice can be found here as well [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Go to boardgamegeek.com find your game and obtain 3D game box image, 2D box image, and if you lucky they also sometime have boards and token scans in &amp;quot;Game Pieces&amp;quot; section of Images&lt;br /&gt;
* If that fail google &amp;quot;boardgame &amp;lt;name&amp;gt;&amp;quot; and check Images section&lt;br /&gt;
* Get the rules PDF as well, there tools that allows you to extract graphics from PDF, which usually good for meeples, cubes and such (can use pdfimages command line tool)&lt;br /&gt;
&lt;br /&gt;
Once you get the graphics one way or another you have to massage it to fit in the BGA criteria, which usually involves&lt;br /&gt;
* If publisher sends graphics in one token/card per file mode, you have to stitch them in sprite and scale down&lt;br /&gt;
* For non square tiles and game pieces you need transparency&lt;br /&gt;
* Usually you chop off scoring &amp;quot;ring&amp;quot; around the board of the game since scoring track not needed for online adaptation&lt;br /&gt;
&lt;br /&gt;
More details about graphics requirements can be found here [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
[[File:Rrr_search.png]]&lt;br /&gt;
&lt;br /&gt;
== Obtain game documentation ==&lt;br /&gt;
&lt;br /&gt;
Also at this time obtain a electronic copy of rules, such as PDF (English version). &lt;br /&gt;
&lt;br /&gt;
Also grab any other documents you may find on boardgamegeek such as FAQ, additional Reference books, and user created assistant documents, such&lt;br /&gt;
as cheat-sheets (may be easier to get a data from these then trying to scrub pdf). You create and place them in the doc/ folder of the project then&lt;br /&gt;
exclude them from version control. There is also a misc/ folder now but it will hold up to 1 Mb of data files which would be checked in, so rules pdf&#039;s may not fit there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Update game infos and box graphics ==&lt;br /&gt;
&lt;br /&gt;
Even it does not nothing yet start with making sure game looks descent in the game selector, meaning it has nice box graphics and information is correct. &lt;br /&gt;
&lt;br /&gt;
For that we need to edit [[Game_meta-information: gameinfos.inc.php|gameinfos.inc.php]].&lt;br /&gt;
What you would do for real game you would go to http://boardgamegeek.com find the game and use the information from web-site to fill the gameinfos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step is to replace game_box.png with proper images, usually you can find all images including publisher logo on boardgamegeek website.&lt;br /&gt;
&lt;br /&gt;
Details about images can be found here: [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
Now important step. You have to LOAD these files in studio website through control panel. So go to Control Panel -&amp;gt; Manager Games -&amp;gt; YOURPROJECT&lt;br /&gt;
and press Reload for &#039;Reload game informations&#039; and &#039;Reload game box image&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Gamepanel_sharedcode.png]]&lt;br /&gt;
&lt;br /&gt;
Now try to start the game again. If you some-how introduced a syntax error in gameinfos file it may not actually work (game won&#039;t start).&lt;br /&gt;
Always use &amp;quot;Express Start&amp;quot; button to start the game. You should see a standard state prompt from template. You should see X players on the right, testdude0 .. testdudeX-1.&lt;br /&gt;
To switch between them press the red arrow button near their names, it will open another tab. This way you don&#039;t need to login and logout from multiple accounts!&lt;br /&gt;
&lt;br /&gt;
== Fix source copyright ==&lt;br /&gt;
&lt;br /&gt;
Now since you have your own project, you want put your name in the copyright header, so replace&lt;br /&gt;
&lt;br /&gt;
  © &amp;lt;Your name here&amp;gt; &amp;lt;Your email address here&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
  © John Snow &amp;lt;jsnow@gameofthrones.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well not exactly this but whatever your real name is. For all files in project directory, its about 10 files. Make sure project still starts after that :)&lt;br /&gt;
&lt;br /&gt;
== Reduce the Rules ==&lt;br /&gt;
&lt;br /&gt;
Programming a game will take a lot more time than you may think. Most of the projects in the studio are abandoned because of lack of patience or skill.&lt;br /&gt;
To keep sane, start the game with *reduced* rules and try to complete that first.&lt;br /&gt;
&lt;br /&gt;
* If it has any expansions - do not even attempt to deal with them, not even - &amp;quot;I will just add graphics for them now and not use&amp;quot; - waste of time if you don&#039;t complete basic&lt;br /&gt;
* If it has advanced rules - start with basic rules only, i.e. &amp;quot;beginner game&amp;quot;&lt;br /&gt;
* If it has special rules for 2 player vs 4, start with most basic form (i.e. 4), restrict to 4 players &lt;br /&gt;
* If it has 50 unique cards of 2 each - start with 2 unique cards with 25 each (just to keep it moving)&lt;br /&gt;
* Any sort of rules that you think can be removed and not included in base - set aside for now &lt;br /&gt;
* Ignore any sort of cool animations - dice rolling, card flipping, choo-choo sounds of the trains - all this fluff can be added later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Game Elements ==&lt;br /&gt;
Technically game elements are already designed by board game designer but your job is to map it to program space.&lt;br /&gt;
Each physical piece (card, token, cube) will leave footprints all over the code (unfortunatly in multiple disconnected places).&lt;br /&gt;
To prepare the game you need to sort out these elements, i.e. categorize. I usually have to the following categorization (in object oriented view):&lt;br /&gt;
* Instance - all individual pieces are instances, i.e. two red cubes are two instances of &#039;red cube&#039; type (class)&lt;br /&gt;
* Type - element type which distinctly represents that element in appearence (i.e. red cube is different type than blue cube)&lt;br /&gt;
* Super Type - one of more common types that similar properties (i.e. red OR cube)&lt;br /&gt;
* Player color - supertype specific for player color (sometimes there is no colors but like player 1 - but is conceptually the same, I use color because its easier to track)&lt;br /&gt;
&lt;br /&gt;
Personally I like to encode my elements in string using reverse dns notation listing all the properties above, i.e.&lt;br /&gt;
  meeple_ff0000_7 - this is instance #7 of type meeple_ff0000 (red meeple)&lt;br /&gt;
Or&lt;br /&gt;
  card_yellow_magic_2 - this is instance #2 of yellow card (in this case yellow is color of deck not related to player color) that can do magic&lt;br /&gt;
&lt;br /&gt;
So every game element would be in the&lt;br /&gt;
&lt;br /&gt;
1. Database - instances. The db record would be something like &lt;br /&gt;
  key|location|state&lt;br /&gt;
  meeple_ff0000_7|slot_action_2|1&lt;br /&gt;
  meeple_ff0000_2|tableau_ff0000|0&lt;br /&gt;
2. Material file - types and supertypes, we never need repeating info here, so never list individual instances but only types or supertypes, in this case we don&#039;t really need to define red meeple vs blue meeple&lt;br /&gt;
  &#039;meeple&#039;=&amp;gt;{&#039;name&#039;=&amp;gt;totranslate(&#039;Meeple&#039;)}&lt;br /&gt;
3. Client (js, css, tpl, etc) - instances and types. For example my meeple will be like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;meeple_ff0000_7&amp;quot; class=&amp;quot;meeple meeple_ff0000&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
with .css something like&lt;br /&gt;
  .meeple { background-image: url(img/tokens.png); width: 2em; height: 2em;}&lt;br /&gt;
  .meeple_ff0000 {background-position: 20% 0%;}&lt;br /&gt;
4. Game php - setup and logic. During setup you have to generate all the pieces and place them in right positions. Also sometimes you need to reference elements to code the logic (I usually try to encode all rules in material file as much as possible)&lt;br /&gt;
&lt;br /&gt;
For complex card games I think it is the best to keep all these info and rules in spreadsheet and generate other files such as material.inc.php.&lt;br /&gt;
See more info below about design of the individual layers.&lt;br /&gt;
&lt;br /&gt;
== Create Initial Layout and Game Graphics ==&lt;br /&gt;
&lt;br /&gt;
Mentally it is easier to start with game layout and graphics pieces. Even when nothing is working its give you moral satisfaction!&lt;br /&gt;
&lt;br /&gt;
There are a few ways how the html could have been generated. You could have started with nothing and generate&lt;br /&gt;
it all by javascript, or you could have started with complete game markup in html and make javascript just hide and move pieces around. BGA framework also provides a third way, which is mix of both, plus a template engine to generate HTML using PHP. The only thing that is really annoying about the template engine is that you cannot put any translatable strings in the template (which means any visible text at all). If you are using the template approach all strings have to extracted as variables and injected through PHP (.view.php). This page explains the template engine in great detail:[[Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl|Template Engine]].&lt;br /&gt;
&lt;br /&gt;
The other disadvantage of the template engine is you cannot run and debug it locally, in the beginning of development it&#039;s a lot faster run off local pages, &lt;br /&gt;
you can do it with some trickery described here [[Tools_and_tips_of_BGA_Studio#Speed_up_CSS_development_and_layout|Tools and Tips for BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
During this step you have to decide what technical solutions you will be using, such as&lt;br /&gt;
* Use inline positioning of all moving pieces, controlled by JS. There are a few classes that already exist in Studio to help with that (see [[Studio#Game_interface_.28Client_side.29|Game Interface - Client Side]]). OR use html/css layout engine to position pieces (my personal choice).&lt;br /&gt;
* Use BGA template engine OR create all ui elements by JS OR manually write or generate complete html markup. The game usually contain 200-300 pieces, it seems wrong but actually its faster to type all of this up in html/css when trying write than debug code for page generator.&lt;br /&gt;
Static HTML markup also means you have to use players color or abstracted player number (such as red is 1, blue is 2) not player id&#039;s anywhere in JS, since player id is dynamic by nature.&lt;br /&gt;
&lt;br /&gt;
Start by creating and mapping all games assets, best way is probably to open rule book on &amp;quot;boardgame contents&amp;quot; page and go through every piece. Every pieces of boardgame would have its &amp;quot;print&amp;quot; in multiple files in your game:&lt;br /&gt;
* Some sort if &amp;quot;div&amp;quot; in html, where id of element match id of element in database (easiest way)&lt;br /&gt;
* Css for the element (either unique or for class), usually with background propery refering to part of sprite image&lt;br /&gt;
* Entry in material.inc.php referring to static properties of the element, i.e. name, tooltip, rules, etc&lt;br /&gt;
* Entry in .tpl file to represent static or initial location on the table OR creation template&lt;br /&gt;
&lt;br /&gt;
Here are some specific examples:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create entry in .tpl file for the board, it will be static entry as we never need to create this dynamically&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;board&amp;quot; class=&amp;quot;board shadow board4p&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create entry in .css file for this board and other board variants (in example below we have 4 ppl board whcih is diffrent than 2 ppl board)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.board {&lt;br /&gt;
	position: relative;&lt;br /&gt;
	width: 980px;&lt;br /&gt;
	height: 433px;&lt;br /&gt;
	margin-bottom: 5px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.board4p {&lt;br /&gt;
	background-image: url(img/board4p.jpg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That would be pretty much it for the board itself, as it does not really need a tooltip so we don&#039;t need entry in material.inc.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board Slots&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are interactive areas on the board, usually illustrated as such. In most cases you can get away with rectangular shapes, but sometimes you have to create circle or oval shapes (and in really advanced case would be some svg paths). For slots you can do the following:&lt;br /&gt;
&lt;br /&gt;
Entry in material.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;token_types = array(&lt;br /&gt;
...&lt;br /&gt;
&#039;slot_action_2&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;type&#039; =&amp;gt; &#039;slot_action&#039;,&lt;br /&gt;
  &#039;name&#039; =&amp;gt; clienttranslate(&amp;quot;2 Gray Track Advancements&amp;quot;),&lt;br /&gt;
  &#039;tooltip&#039; =&amp;gt; clienttranslate(&amp;quot;This action gives you two advancements of gray track. You cannot use this action if you cannot complete all advancements.&amp;quot;),&lt;br /&gt;
  &#039;o&#039;=&amp;gt;&amp;quot;1,0,0,gg&amp;quot;, // automatic rules&lt;br /&gt;
),&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in template inside the &amp;quot;board&amp;quot; div&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;slot_action_2&amp;quot; class=&amp;quot;slot_action_2 slot_action slot_w_1 slot&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in .css with absolute position within the board (its actually better to use percentage - would be easier to scale later)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.slot_action_2 {&lt;br /&gt;
	top: 83px;&lt;br /&gt;
	left: 37px;&lt;br /&gt;
}&lt;br /&gt;
.slot_action {&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	width: 46px;&lt;br /&gt;
	height: 26px;&lt;br /&gt;
	padding: 9px 7px 6px 4px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Meeples&#039;&#039;&#039; - also cards, tokens, other mobile stuff&lt;br /&gt;
&lt;br /&gt;
In CSS these guys will use &amp;quot;sprite&amp;quot; images with transparency, so it will look like this this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	background-image: url(img/tokens.png);&lt;br /&gt;
	width: 25px;&lt;br /&gt;
	height: 25px;&lt;br /&gt;
}&lt;br /&gt;
.meeple_ff0000 { /* red */&lt;br /&gt;
	background-position: 14% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As for creation you can either generate them using template (where whole thing wrapped in template block and {COLOR} replace with all possible colors in .view.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_1&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_2&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can declare a template js var in .tpl file &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    var jstpl_mepple = &#039;&amp;lt;div id=&amp;quot;meeple_${color}_${num}&amp;quot; class=&amp;quot;meeple meeple_${color} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;; // this is in .tpl file at the bottom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and create in js, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 var tokenDiv = this.format_block(&#039;jstpl_mepple&#039;, {&lt;br /&gt;
                                &amp;quot;color&amp;quot; : color,&lt;br /&gt;
                                &amp;quot;num&amp;quot; : i&lt;br /&gt;
                            }); // this in js code somewhere before placing it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you dealing with cards and decks, there are pre-build components that can generate stuff for you.&lt;br /&gt;
&lt;br /&gt;
When do you create dom element matching game element?&lt;br /&gt;
* If you have static layout you create it in .tpl file and its always there, but during initial setup or during notification it moved in proper spot (including &amp;quot;removed from the game&amp;quot; spot)&lt;br /&gt;
* If you dynamically generated pieces you create the element during notification, and sometimes during animation. Also don&#039;t forgot to hook event listener to it if its interactive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One of the greatest parts about the web is all client side code can be viewed in your browser, so if you wondering how something is done in another BGA game just load the page and spy on it! In Chrome that would be right click and &amp;quot;Inspect Element&amp;quot;. That would immediately show html of the given element alongside with css used for it (on the right). Another great way to learn is you can add yourself to any BGA project as read only from the project page!&lt;br /&gt;
&lt;br /&gt;
So at the end of this stage you should complete the following (keeping in mind reduced rules/material for first iteration):&lt;br /&gt;
* Create a layout of the game, with positioning of main board, player areas, zones, other supporting areas, etc&lt;br /&gt;
* Create css and html snippets for all game pieces: boards, tokens, meeples, etc. Place them all in initial template (even if they&#039;re not supposed to be visible at start). I.e. create fake player&#039;s hand with cards, put meeples on the board&lt;br /&gt;
* Hook layout to number of players and colors picked by the game and test with multiple players&lt;br /&gt;
* Figure out what you want to display in mini-player boards and hook it up&lt;br /&gt;
* Create material.inc.php and populate with initial values (names, tooltips, rules) for all relevant game elements or classes of elements&lt;br /&gt;
&lt;br /&gt;
If at this time you don&#039;t have graphics yet create pieces with just CSS, you can use shape, background color and object text using css ::after construct to fake the pieces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Injected_text.png]]&lt;br /&gt;
&lt;br /&gt;
== Hook Input and Animation ==&lt;br /&gt;
&lt;br /&gt;
This step can be done before or after some of the server steps, or you go in iterations switching back and forward until you get it done, up to you.&lt;br /&gt;
&lt;br /&gt;
At this time you want to hook clicking on pieces and buttons and provide some reaction, such of moving a piece. The handler code will be replaced later by the server hook, but at the beginning you want your game to be alive as early as possible. &lt;br /&gt;
&lt;br /&gt;
Usually all pieces will be hooked to onclick during JS &amp;quot;setup&amp;quot; method, in addition if you create elements during server notification they have to be hooked up at that time.&lt;br /&gt;
&lt;br /&gt;
You can play with animation effects you want put in place, in general all the pieces that move in real game should be moving, such as meeples, resources tokens/cubes, cards, vp tokens. &lt;br /&gt;
Regular piece animation is provided by BGA framework, but if you use html layout positioning not inline positioning you have to remove absolute positions (inline position styling) after each move. The set of functions for relative position token animation can found in https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js &lt;br /&gt;
&lt;br /&gt;
Also its a good idea to give player a visual cues on what game elements are clickable now, usually it will be a style, such as &amp;quot;active_slot&amp;quot;, with visual effect of white dashed outline (outline is better then border, because border changes will make piece slightly move since it changes the size) or box-shadow (i.e. neon glow)&lt;br /&gt;
&lt;br /&gt;
If you read [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] you know that you should not get carried away with animation, you are creating a board game not a video game... That also applies to sound effects (in general, you should not use any sounds effects beside already provided by framework).&lt;br /&gt;
&lt;br /&gt;
See [[Game_interface_logic:_yourgamename.js#Players_input|Player&#039;s Input]] and [[Game_interface_logic:_yourgamename.js#Access_and_manipulate_the_DOM|Animation and DOM Manipulation]] for JS reference.&lt;br /&gt;
&lt;br /&gt;
== Create Database Schema ==&lt;br /&gt;
&lt;br /&gt;
At some point you have to design your game database. Do it sooner then later since it would be harder to change it later, since some&lt;br /&gt;
code decisions would be based on that.&lt;br /&gt;
&lt;br /&gt;
If you have grid-based abstract game use template from reversi, if you have a card game use template from hearts (the cards one also commented out in generated template for your project). The cards database goes with php class called [[Deck]].&lt;br /&gt;
&lt;br /&gt;
In general make it as simple as possible. &lt;br /&gt;
Think about it, your game has 300 pieces (likely less). Using database to store this amount of data is like shooting a mosquito with a tank.&lt;br /&gt;
Anything more complex then one table with 5 columns or two tables will only going to make it harder to develop and not improve performance.&lt;br /&gt;
You can forget about normalising and any fancy stuff you learn about databases in school. String field for a primary key would be as fast as integer when we talking about this size of data. So don&#039;t over-optimize with trying to have integers field that have state based on bitmask!&lt;br /&gt;
&lt;br /&gt;
Also remember that static (non dynamic) information about the game does not need to be stored in the database, that all include everything that does not change, i.e&lt;br /&gt;
all token/card properties such as name, tooltips, &amp;quot;strength&amp;quot;, color, etc. This is stored in material.inc.php and server has access to it from anywhere, as well as client&lt;br /&gt;
if you send it with getAllDatas(). The only reason store some of it in database if it can affect your queries (i.e. type of token).&lt;br /&gt;
&lt;br /&gt;
Usually design process will contain the following steps:&lt;br /&gt;
* Design game model - model that represent your game in progress, such as at any given step you can restore the game from that model&lt;br /&gt;
* Mapping - now map real game to that model&lt;br /&gt;
* Encoding - now represent this model in database and material file with reasonable amount of fields&lt;br /&gt;
&lt;br /&gt;
Example: &#039;&#039;&#039;The card game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but as part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in your database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position itself usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what info changes and what info is static, static info is always candidate for material file or html&lt;br /&gt;
* For dynamic stuff we should try to reduce amount of fields we need, i.e. we need a field for card, so its one, we need to know what zone cards belong to, its 2, and we have possible few other fields, but if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face  down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
You can also use cards database schema and [[Deck]] implementation for most purposes (even you not dealing with cards).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another Example: &#039;&#039;&#039;The euro game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based &lt;br /&gt;
games can be in most case represented by (string: token_key, string: location, int: state), example of such database schema can be found here:&lt;br /&gt;
[https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php tokens.php].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See [[Game database model: dbmodel.sql]] for details about editing the file.&lt;br /&gt;
&lt;br /&gt;
Note: the simpler the database is the less debugging of db issues you have to deal with including database migration. The tokens database above - if you use it you never have to worry about migration because you don&#039;t need extra tables in 95% of the games.&lt;br /&gt;
Here are some example of how real games are mapped to such database:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chess&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
- chess is grid base game and normally you would use positional columns, but just for the sake of argument, the chess game will look like this&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_white&lt;br /&gt;
|f3&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|P_black_2&lt;br /&gt;
|c6&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|K_black&lt;br /&gt;
|e8&lt;br /&gt;
|1&lt;br /&gt;
|}&lt;br /&gt;
And the state in this case indicated that kind was moved for example (which means castling cannot be performed)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Classic card game&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Lets pretend we need 2 decks for that game&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_spades_1&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_2&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|2 /* position */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_1&lt;br /&gt;
|tableau_common&lt;br /&gt;
|1 /* face down */&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Eminent Domain (card game)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|card_tech_23&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|1 /* face up */&lt;br /&gt;
|-&lt;br /&gt;
|reource_s_22 /* silicon */&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|2 /*  production state */&lt;br /&gt;
|-&lt;br /&gt;
|fighter_F_1&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also look at other games that use Tokens database and access layer: Nippon, Dungeon Petz, Lewis &amp;amp; Clark, Battleship, Russian Railroads, Khronos&lt;br /&gt;
&lt;br /&gt;
== Implement Game Setup ==&lt;br /&gt;
&lt;br /&gt;
Once you have your database schema you can do a proper game setup. Usually you open rulebook on the &amp;quot;Game Setup&amp;quot; page&lt;br /&gt;
and implement these step by step populating the database (using db access API).&lt;br /&gt;
Game initialization is performed in php method setupNewGame, this method is called once when game table is created.&lt;br /&gt;
Game notifications cannot be sent during this time.&lt;br /&gt;
&lt;br /&gt;
== Implement One time game model synchronisation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now at any point in the game we need to make sure that database information can be reflected back in UI, so we fix getAllDatas function&lt;br /&gt;
to return all possible data we need to reconstruct the game. The template for getAllDatas already taking care of player info, but you &lt;br /&gt;
have to alter it to return all other data from database visible to the &amp;quot;current&amp;quot; player.&lt;br /&gt;
&lt;br /&gt;
After that on the client side we should display this data, so in your .js file in setup function (which is the receiver of getAllDatas) you add calls that handle data send by server, usually by calling animation function such as &amp;quot;placeToken&amp;quot; or &amp;quot;placeCard&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Create State Machine ==&lt;br /&gt;
&lt;br /&gt;
Now you need to create a game state machine. &lt;br /&gt;
&lt;br /&gt;
The state handling spread across 4 files, so you have to make sure all the pieces are connected together.&lt;br /&gt;
The state machine states.inc.php defines all the states, and function handlers on php side in a form of string,&lt;br /&gt;
and if any of these functions are not implemented it would be very hard to debug because it will break in random places.&lt;br /&gt;
&lt;br /&gt;
Please first watch this again [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine  BGA game state machine]&lt;br /&gt;
and then please read [[Your game state machine: states.inc.php]].&lt;br /&gt;
&lt;br /&gt;
Now the state machine should be relatively simple. If you find yourself with machine with more than 20 states its probably not the way to go.&lt;br /&gt;
Not all the player interactions need separate states, a lot of things can be implemented directly on client, i.e. if your player need to select&lt;br /&gt;
a reward token, which offers choice of resource, instead of two states on server just have one state on server and possible few states on client (client side states)&lt;br /&gt;
to collect this info.&lt;br /&gt;
&lt;br /&gt;
== Handle Turn Order ==&lt;br /&gt;
&lt;br /&gt;
If your game goes in clockwise order in natural sitting position nothing really needed you just use standard API and you are good. However if position is complecated&lt;br /&gt;
it may require some trickery.&lt;br /&gt;
&lt;br /&gt;
Usually turn order is done by &amp;quot;game state&amp;quot; (see state machine above). Basically it would be two choices:&lt;br /&gt;
* Turn order depends on game situation (such as we take player with highest number of red cubes)&lt;br /&gt;
* Turn order is custom and assign on previos step - i.e. we not playing in clockwise order anymore. In this case you either need to extend player table with new order info (CANNOT use player_no column) or use order markers that come with game (i.e. marker_ff0000 on position_1). In this we can build player array in right order and pick next player based on previous player using existing helper function such as $this-&amp;gt;createNextPlayerTable($player_ids)&lt;br /&gt;
&lt;br /&gt;
== Implement Notification handling ==&lt;br /&gt;
&lt;br /&gt;
Now to implement things for real we have hook UI actions to ajax calls, and process notifications send by server.&lt;br /&gt;
So previously we hooked onclick js handler right to client animation, in real game its a two&lt;br /&gt;
step operation. When user clicks on something, client sends an ajax call to server, server processes it and updates database, server sends&lt;br /&gt;
notification in response, client hooks animations to server notification. See [[Game_interface_logic:_yourgamename.js#Notifications|JS Notifications]].&lt;br /&gt;
&lt;br /&gt;
Exception to this is client states, if you need to process two step user interaction such as select meeple, place meeple, you may want &lt;br /&gt;
to avoid sending data to server until step is complete (which may involve direct client side animation). See [[BGA_Studio_Cookbook#Multi_Step_Interactions:_Select_Worker.2FPlace_Worker_-_Using_Selection|Multi-Step Interactions]]&lt;br /&gt;
&lt;br /&gt;
Part of the sending notifications would be to update player&#039;s scoring, BGA uses standard control for score (on JS side), see [[Game_interface_logic:_yourgamename.js#Update_players_score|Update Player&#039;s Score]].&lt;br /&gt;
&lt;br /&gt;
In BGA there is only two ways interact with the server (officially)&lt;br /&gt;
* Initial data dump - when JS client starts it gets all current data via setup() method&lt;br /&gt;
* Game actions - ajaxcall from client, it returns error or ok (not data), then server send butch of notifications to client&lt;br /&gt;
&lt;br /&gt;
Note current ajaxcall is super vebosy and prone to errors, I suggest to use helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
				if (!args) args = []; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
				&lt;br /&gt;
				args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
&lt;br /&gt;
				if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
					this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
						this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                                handler); // this is real result handler - it called both on success and error, its is optional param - you rarely need it&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you insert a single action you have to update multiples files:&lt;br /&gt;
* in ggg.js add ajaxcall, i.e. something like &lt;br /&gt;
  this.addActionButton(&#039;pass&#039;,_(&#039;Pass&#039;),()=&amp;gt;this.ajaxcallwrapper(&#039;pass&#039;));&lt;br /&gt;
* in states.php - add action &#039;pass&#039; to list of possible actions&lt;br /&gt;
  &#039;possibleactions&#039; =&amp;gt; [&#039;pass&#039;,&#039;playCard&#039;]&lt;br /&gt;
* in action.php - add action hander, see https://en.doc.boardgamearena.com/Players_actions:_yourgamename.action.php&lt;br /&gt;
* in game.php - add action hander, there you must do the following&lt;br /&gt;
** call checkAction to validate the action&lt;br /&gt;
** possible do more game specific check to validate what player doing is legal (even its not possible from your js side - player can cheat - not allow that)&lt;br /&gt;
** do some database maniplations, using access api&lt;br /&gt;
** send notifications - this is the &amp;quot;reply&amp;quot; for action&lt;br /&gt;
** transition to new state (it very rare that  user will remain in the same state, except for multi-active states)&lt;br /&gt;
* back to ggg.js add notification subsciption and notification handler (two separate things)&lt;br /&gt;
&lt;br /&gt;
== Wrap Up ==&lt;br /&gt;
&lt;br /&gt;
* Implement game progression (getGameProgression() in php)&lt;br /&gt;
* Implement Zombie turn  (zombieTurn() in php)&lt;br /&gt;
* Define and implemented some meaningful statistics for your game (i.e. total points, point from source A, B, C...)&lt;br /&gt;
* The games logs should explain what happened if player was not looking&lt;br /&gt;
* You need to implemented tiebreaking (using aux score field) and updated tiebreaker description in meta-data&lt;br /&gt;
* Make sure all UI strings are marked for translation&lt;br /&gt;
* UI elements which are images (i.e. tokens, cards) should have tooltips&lt;br /&gt;
&lt;br /&gt;
== Alpha ==&lt;br /&gt;
When you think you game is completely working there is still bunch of stuff you have to do/check before telling admin that game is ready, please go though this [[Pre-release checklist]].&lt;br /&gt;
&lt;br /&gt;
If you think its completely ready, let admin know (studio@boardgamearena.com) and it they will push it to alpha.&lt;br /&gt;
&lt;br /&gt;
Finally, visit the game page for your alpha game (https://boardgamearena.com/gamepanel?game=…) to add the following information if you can:&lt;br /&gt;
* Links to the rules (in multiple languages if available).&lt;br /&gt;
* Links to teaching videos.&lt;br /&gt;
* In the &amp;quot;On the web&amp;quot; section, links to:&lt;br /&gt;
** The official website for the game (if there is one).&lt;br /&gt;
** The BoardGameGeek page for the game.&lt;br /&gt;
* Consider writing a summary of the rules.&lt;br /&gt;
&lt;br /&gt;
== Level Up ==&lt;br /&gt;
&lt;br /&gt;
When you successfully created a basic game and you want more, its time to make it fancy!&lt;br /&gt;
&lt;br /&gt;
* Add game externtions and variants using gameoptions file&lt;br /&gt;
* Add user preferences for customizations&lt;br /&gt;
* Use theming! That involves replacing hardwood background, changing tooltips, using different sounds, different fonts, changing state prompt and logs&lt;br /&gt;
* You can use fancy scoring board at the end of game instead of default nothing&lt;br /&gt;
* And finally super cool dice rolling, card flipping and victory points evaporating effects&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11464</id>
		<title>Create a game in BGA Studio: Complete Walkthrough</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11464"/>
		<updated>2022-01-18T22:33:49Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Create Initial Layout and Game Graphics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This document is not a tutorial, but step by step instructions on how to build your own first game adaptation using BGA Studio framework.&lt;br /&gt;
&lt;br /&gt;
Before you read this material, you must:&lt;br /&gt;
* Read the overall presentations of the BGA [[Studio]].&lt;br /&gt;
* Some-what know the languages used by BGA Studio: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
* Create a game using one of the available tutorials. Don&#039;t bother with a new game if you have not completed at least one of the tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck or have questions about this page post on [https://forum.boardgamearena.com/viewforum.php?f=12 BGA Developers forum].&lt;br /&gt;
If you&#039;re uncomfortable posting on the public forum you can send messages directly to developers who post answers on that forum but NOT the BGA admins.&lt;br /&gt;
If you find typos in this wiki - fix it.&lt;br /&gt;
&lt;br /&gt;
== Select a First Game ==&lt;br /&gt;
&lt;br /&gt;
For your first &#039;&#039;&#039;real&#039;&#039;&#039; game you must either&lt;br /&gt;
* Select a game from [https://en.studio.boardgamearena.com/licensing Available Licenses]&lt;br /&gt;
* Or from the Public Domain&lt;br /&gt;
&lt;br /&gt;
But what if the game you want is not there? If you are able to successfully publish your first game, you would gain the trust of the BGA admins and they will be happy to assist you in obtaining a license for a game you really want to do or you can request a license yourself. You can read more about game licenses on [[BGA Game licenses]] page.&lt;br /&gt;
&lt;br /&gt;
Once you selected the game but before creating a new project, please take a few seconds to check that someone is not already developing this game. If it is the case, maybe you can propose to join the project?&lt;br /&gt;
&lt;br /&gt;
[http://en.studio.boardgamearena.com/#!projects Check the list of current projects]&lt;br /&gt;
&lt;br /&gt;
Even if you see a few projects with name of the game they may not be active. There are a lot of abandoned game projects. If it&#039;s not clear by the status, post to Developers forum asking if anybody actively working on the project or send a message to developers listed for the abandoned projects, and at the same time ask admins on the same forum post to send you graphics for that game if they have them (there a button on [https://en.studio.boardgamearena.com/licensing Available Licenses] page to request graphics, but it will just send email).&lt;br /&gt;
&lt;br /&gt;
If your goal was to fix bugs in an existing project, first try to locate on studio, projects developed by bga admins are not in the studio. Then get read only access to the project and you can create your own as a copy of the existing one. Contact existing project admin about getting write access to the original project or if they willing to take your patches - apply them.&lt;br /&gt;
&lt;br /&gt;
If you want to take over an existing project first ask on forum to see if project is abandoned, then get read only access (via project list) and see if this worth using it, if it has no code or graphics just start from the scratch, don&#039;t worry about project name it can be renamed later.&lt;br /&gt;
&lt;br /&gt;
== Create a project ==&lt;br /&gt;
&lt;br /&gt;
If you have not already, you have to create a project in BGA Studio for this game. If the original game name is taken use gamenameYOURINITIALS&lt;br /&gt;
template, i.e.&amp;quot;heartsla&amp;quot;. Don&#039;t worry too much about the name, if game would be good enough to be publish it will be renamed to original name. &lt;br /&gt;
&lt;br /&gt;
Find and start the game in turn based mode, make sure it works.&lt;br /&gt;
&lt;br /&gt;
Second, modify the text in .tpl file, reload the page in the browser and make sure your ftp sync works as expected.&lt;br /&gt;
Note: if you have not setup [http://en.doc.boardgamearena.com/Tools_and_tips_of_BGA_Studio#File_Sync FTP auto-sync] yet, do it now, manually copying files is a no-starter.&lt;br /&gt;
&lt;br /&gt;
Update your project status in [http://en.studio.boardgamearena.com/#!studio Control Panel &amp;gt; Manage games] page, you can say &amp;quot;development started&amp;quot; or &amp;quot;waiting for license&amp;quot; or &amp;quot;waiting for graphics&amp;quot; or combination of those.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Development Tools ==&lt;br /&gt;
&lt;br /&gt;
At some point you need to setup your development environment which consist of multiple tools, such as&lt;br /&gt;
* Editor or IDE&lt;br /&gt;
* Browser with dev tools&lt;br /&gt;
* File sync tools&lt;br /&gt;
* BGA Web tools&lt;br /&gt;
* Image manipulation tools&lt;br /&gt;
* Version control tools&lt;br /&gt;
&lt;br /&gt;
Please scan though articles from [[Studio#BGA_Studio_user_guide]] especially related to debugging and tools, there is a lot of useful info there.&lt;br /&gt;
&lt;br /&gt;
== Hook version control system ==&lt;br /&gt;
&lt;br /&gt;
If its a real game I would commit the code to version control right at start. You going to find yourself in the situation&lt;br /&gt;
when game does not even start anymore and no way of debugging it unless you have a way to revert. That is where version control becomes very handy.&lt;br /&gt;
If you don&#039;t know what I am talking about then at least back-up your files after each of major steps. Starting now.&lt;br /&gt;
You can also create a project on github, but make sure &#039;&#039;&#039;you don&#039;t commit original publisher graphics files&#039;&#039;&#039; and &#039;&#039;&#039;you don&#039;t include a file with your sftp password&#039;&#039;&#039; (github is automatically crawled for passwords by hackers; a hacking attempt occurred on BGA studio for this reason in June 2020).&lt;br /&gt;
You can (and should) also commit your modification periodically via studio&#039;s control panel.&lt;br /&gt;
&lt;br /&gt;
== Obtain game graphics ==&lt;br /&gt;
&lt;br /&gt;
If you developing a game from Available Licenses games, ask the admins to send you graphics by contacting studio@boardgamearena.com. While that request is being processed (it can take time, as it often requires some back and forth  between the admins and the publishers) you can proceed to next step - project creation.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t get original graphics you go to &#039;&#039;&#039;Scavenger Hunt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you developing a public domain card game you can borrow standard cards from BGA generic assets, see [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Standard game pieces - meeples, cubes, dice can be found here as well [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Go to boardgamegeek.com find your game and obtain 3D game box image, 2D box image, and if you lucky they also sometime have boards and token scans in &amp;quot;Game Pieces&amp;quot; section of Images&lt;br /&gt;
* If that fail google &amp;quot;boardgame &amp;lt;name&amp;gt;&amp;quot; and check Images section&lt;br /&gt;
* Get the rules PDF as well, there tools that allows you to extract graphics from PDF, which usually good for meeples, cubes and such (can use pdfimages command line tool)&lt;br /&gt;
&lt;br /&gt;
Once you get the graphics one way or another you have to massage it to fit in the BGA criteria, which usually involves&lt;br /&gt;
* If publisher sends graphics in one token/card per file mode, you have to stitch them in sprite and scale down&lt;br /&gt;
* For non square tiles and game pieces you need transparency&lt;br /&gt;
* Usually you chop off scoring &amp;quot;ring&amp;quot; around the board of the game since scoring track not needed for online adaptation&lt;br /&gt;
&lt;br /&gt;
More details about graphics requirements can be found here [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
[[File:Rrr_search.png]]&lt;br /&gt;
&lt;br /&gt;
== Obtain game documentation ==&lt;br /&gt;
&lt;br /&gt;
Also at this time obtain a electronic copy of rules, such as PDF (English version). &lt;br /&gt;
&lt;br /&gt;
Also grab any other documents you may find on boardgamegeek such as FAQ, additional Reference books, and user created assistant documents, such&lt;br /&gt;
as cheat-sheets (may be easier to get a data from these then trying to scrub pdf). You create and place them in the doc/ folder of the project then&lt;br /&gt;
exclude them from version control. There is also a misc/ folder now but it will hold up to 1 Mb of data files which would be checked in, so rules pdf&#039;s may not fit there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Update game infos and box graphics ==&lt;br /&gt;
&lt;br /&gt;
Even it does not nothing yet start with making sure game looks descent in the game selector, meaning it has nice box graphics and information is correct. &lt;br /&gt;
&lt;br /&gt;
For that we need to edit [[Game_meta-information: gameinfos.inc.php|gameinfos.inc.php]].&lt;br /&gt;
What you would do for real game you would go to http://boardgamegeek.com find the game and use the information from web-site to fill the gameinfos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step is to replace game_box.png with proper images, usually you can find all images including publisher logo on boardgamegeek website.&lt;br /&gt;
&lt;br /&gt;
Details about images can be found here: [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
Now important step. You have to LOAD these files in studio website through control panel. So go to Control Panel -&amp;gt; Manager Games -&amp;gt; YOURPROJECT&lt;br /&gt;
and press Reload for &#039;Reload game informations&#039; and &#039;Reload game box image&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Gamepanel_sharedcode.png]]&lt;br /&gt;
&lt;br /&gt;
Now try to start the game again. If you some-how introduced a syntax error in gameinfos file it may not actually work (game won&#039;t start).&lt;br /&gt;
Always use &amp;quot;Express Start&amp;quot; button to start the game. You should see a standard state prompt from template. You should see X players on the right, testdude0 .. testdudeX-1.&lt;br /&gt;
To switch between them press the red arrow button near their names, it will open another tab. This way you don&#039;t need to login and logout from multiple accounts!&lt;br /&gt;
&lt;br /&gt;
== Fix source copyright ==&lt;br /&gt;
&lt;br /&gt;
Now since you have your own project, you want put your name in the copyright header, so replace&lt;br /&gt;
&lt;br /&gt;
  © &amp;lt;Your name here&amp;gt; &amp;lt;Your email address here&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
  © John Snow &amp;lt;jsnow@gameofthrones.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well not exactly this but whatever your real name is. For all files in project directory, its about 10 files. Make sure project still starts after that :)&lt;br /&gt;
&lt;br /&gt;
== Reduce the Rules ==&lt;br /&gt;
&lt;br /&gt;
Programming a game will take a lot more time than you may think. Most of the projects in the studio are abandoned because of lack of patience or skill.&lt;br /&gt;
To keep sane, start the game with *reduced* rules and try to complete that first.&lt;br /&gt;
&lt;br /&gt;
* If it has any expansions - do not even attempt to deal with them, not even - &amp;quot;I will just add graphics for them now and not use&amp;quot; - waste of time if you don&#039;t complete basic&lt;br /&gt;
* If it has advanced rules - start with basic rules only, i.e. &amp;quot;beginner game&amp;quot;&lt;br /&gt;
* If it has special rules for 2 player vs 4, start with most basic form (i.e. 4), restrict to 4 players &lt;br /&gt;
* If it has 50 unique cards of 2 each - start with 2 unique cards with 25 each (just to keep it moving)&lt;br /&gt;
* Any sort of rules that you think can be removed and not included in base - set aside for now &lt;br /&gt;
* Ignore any sort of cool animations - dice rolling, card flipping, choo-choo sounds of the trains - all this fluff can be added later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Game Elements ==&lt;br /&gt;
Technically game elements are already designed by board game designer but your job is to map it to program space.&lt;br /&gt;
Each physical piece (card, token, cube) will leave footprints all over the code (unfortunatly in multiple disconnected places).&lt;br /&gt;
To prepare the game you need to sort out these elements, i.e. categorize. I usually have to the following categorization (in object oriented view):&lt;br /&gt;
* Instance - all individual pieces are instances, i.e. two red cubes are two instances of &#039;red cube&#039; type (class)&lt;br /&gt;
* Type - element type which distinctly represents that element in appearence (i.e. red cube is different type than blue cube)&lt;br /&gt;
* Super Type - one of more common types that similar properties (i.e. red OR cube)&lt;br /&gt;
* Player color - supertype specific for player color (sometimes there is no colors but like player 1 - but is conceptually the same, I use color because its easier to track)&lt;br /&gt;
&lt;br /&gt;
Personally I like to encode my elements in string using reverse dns notation listing all the properties above, i.e.&lt;br /&gt;
  meeple_ff0000_7 - this is instance #7 of type meeple_ff0000 (red meeple)&lt;br /&gt;
Or&lt;br /&gt;
  card_yellow_magic_2 - this is instance #2 of yellow card (in this case yellow is color of deck not related to player color) that can do magic&lt;br /&gt;
&lt;br /&gt;
So every game element would be in the&lt;br /&gt;
&lt;br /&gt;
1. Database - instances. The db record would be something like &lt;br /&gt;
  key|location|state&lt;br /&gt;
  meeple_ff0000_7|slot_action_2|1&lt;br /&gt;
  meeple_ff0000_2|tableau_ff0000|0&lt;br /&gt;
2. Material file - types and supertypes, we never need repeating info here, so never list individual instances but only types or supertypes, in this case we don&#039;t really need to define red meeple vs blue meeple&lt;br /&gt;
  &#039;meeple&#039;=&amp;gt;{&#039;name&#039;=&amp;gt;totranslate(&#039;Meeple&#039;)}&lt;br /&gt;
3. Client (js, css, tpl, etc) - instances and types. For example my meeple will be like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;meeple_ff0000_7&amp;quot; class=&amp;quot;meeple meeple_ff0000&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
with .css something like&lt;br /&gt;
  .meeple { background-image: url(img/tokens.png); width: 2em; height: 2em;}&lt;br /&gt;
  .meeple_ff0000 {background-position: 20% 0%;}&lt;br /&gt;
4. Game php - setup and logic. During setup you have to generate all the pieces and place them in right positions. Also sometimes you need to reference elements to code the logic (I usually try to encode all rules in material file as much as possible)&lt;br /&gt;
&lt;br /&gt;
For complex card games I think it is the best to keep all these info and rules in spreadsheet and generate other files such as material.inc.php.&lt;br /&gt;
See more info below about design of the individual layers.&lt;br /&gt;
&lt;br /&gt;
== Create Initial Layout and Game Graphics ==&lt;br /&gt;
&lt;br /&gt;
Mentally it is easier to start with game layout and graphics pieces. Even when nothing is working its give you moral satisfaction!&lt;br /&gt;
&lt;br /&gt;
There are a few ways how the html could have been generated. You could have started with nothing and generate&lt;br /&gt;
it all by javascript, or you could have started with complete game markup in html and make javascript just hide and move pieces around. BGA framework also provides a third way, which is mix of both, plus a template engine to generate HTML using PHP. The only thing that is really annoying about the template engine is that you cannot put any translatable strings in the template (which means any visible text at all). If you are using the template approach all strings have to extracted as variables and injected through PHP (.view.php). This page explains the template engine in great detail:[[Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl|Template Engine]].&lt;br /&gt;
&lt;br /&gt;
The other disadvantage of the template engine is you cannot run and debug it locally, in the beginning of development it&#039;s a lot faster run off local pages, &lt;br /&gt;
you can do it with some trickery described here [[Tools_and_tips_of_BGA_Studio#Speed_up_CSS_development_and_layout|Tools and Tips for BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
During this step you have to decide what technical solutions you will be using, such as&lt;br /&gt;
* Use inline positioning of all moving pieces, controlled by JS. There are a few classes that already exist in Studio to help with that (see [[Studio#Game_interface_.28Client_side.29|Game Interface - Client Side]]). OR use html/css layout engine to position pieces (my personal choice).&lt;br /&gt;
* Use BGA template engine OR create all ui elements by JS OR manually write or generate complete html markup. The game usually contain 200-300 pieces, it seems wrong but actually its faster to type all of this up in html/css when trying write than debug code for page generator.&lt;br /&gt;
Static HTML markup also means you have to use players color or abstracted player number (such as red is 1, blue is 2) not player id&#039;s anywhere in JS, since player id is dynamic by nature.&lt;br /&gt;
&lt;br /&gt;
Start by creating and mapping all games assets, best way is probably to open rule book on &amp;quot;boardgame contents&amp;quot; page and go through every piece. Every pieces of boardgame would have its &amp;quot;print&amp;quot; in multiple files in your game:&lt;br /&gt;
* Some sort if &amp;quot;div&amp;quot; in html, where id of element match id of element in database (easiest way)&lt;br /&gt;
* Css for the element (either unique or for class), usually with background propery refering to part of sprite image&lt;br /&gt;
* Entry in material.inc.php referring to static properties of the element, i.e. name, tooltip, rules, etc&lt;br /&gt;
* Entry in .tpl file to represent static or initial location on the table OR creation template&lt;br /&gt;
&lt;br /&gt;
Here are some specific examples:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create entry in .tpl file for the board, it will be static entry as we never need to create this dynamically&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;board&amp;quot; class=&amp;quot;board shadow board4p&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create entry in .css file for this board and other board variants (in example below we have 4 ppl board whcih is diffrent than 2 ppl board)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.board {&lt;br /&gt;
	position: relative;&lt;br /&gt;
	width: 980px;&lt;br /&gt;
	height: 433px;&lt;br /&gt;
	margin-bottom: 5px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.board4p {&lt;br /&gt;
	background-image: url(img/board4p.jpg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That would be pretty much it for the board itself, as it does not really need a tooltip so we don&#039;t need entry in material.inc.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board Slots&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are interactive areas on the board, usually illustrated as such. In most cases you can get away with rectangular shapes, but sometimes you have to create circle or oval shapes (and in really advanced case would be some svg paths). For slots you can do the following:&lt;br /&gt;
&lt;br /&gt;
Entry in material.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;token_types = array(&lt;br /&gt;
...&lt;br /&gt;
&#039;slot_action_2&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;type&#039; =&amp;gt; &#039;slot_action&#039;,&lt;br /&gt;
  &#039;name&#039; =&amp;gt; clienttranslate(&amp;quot;2 Gray Track Advancements&amp;quot;),&lt;br /&gt;
  &#039;tooltip&#039; =&amp;gt; clienttranslate(&amp;quot;This action gives you two advancements of gray track. You cannot use this action if you cannot complete all advancements.&amp;quot;),&lt;br /&gt;
  &#039;o&#039;=&amp;gt;&amp;quot;1,0,0,gg&amp;quot;, // automatic rules&lt;br /&gt;
),&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in template inside the &amp;quot;board&amp;quot; div&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;slot_action_2&amp;quot; class=&amp;quot;slot_action_2 slot_action slot_w_1 slot&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in .css with absolute position within the board (its actually better to use percentage - would be easier to scale later)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.slot_action_2 {&lt;br /&gt;
	top: 83px;&lt;br /&gt;
	left: 37px;&lt;br /&gt;
}&lt;br /&gt;
.slot_action {&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	width: 46px;&lt;br /&gt;
	height: 26px;&lt;br /&gt;
	padding: 9px 7px 6px 4px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Meeples&#039;&#039;&#039; - also cards, tokens, other mobile stuff&lt;br /&gt;
&lt;br /&gt;
In CSS these guys will use &amp;quot;sprite&amp;quot; images with transparency, so it will look like this this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	background-image: url(img/tokens.png);&lt;br /&gt;
	width: 25px;&lt;br /&gt;
	height: 25px;&lt;br /&gt;
}&lt;br /&gt;
.meeple_ff0000 { /* red */&lt;br /&gt;
	background-position: 14% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As for creation you can either generate them using template (where whole thing wrapped in template block and {COLOR} replace with all possible colors in .view.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_1&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_2&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can declare a template js var in .tpl file &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    var jstpl_mepple = &#039;&amp;lt;div id=&amp;quot;meeple_${color}_${num}&amp;quot; class=&amp;quot;meeple meeple_${color} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;; // this is in .tpl file at the bottom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and create in js, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 var tokenDiv = this.format_block(&#039;jstpl_mepple&#039;, {&lt;br /&gt;
                                &amp;quot;color&amp;quot; : color,&lt;br /&gt;
                                &amp;quot;num&amp;quot; : i&lt;br /&gt;
                            }); // this in js code somewhere before placing it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you dealing with cards and decks, there are pre-build components that can generate stuff for you.&lt;br /&gt;
&lt;br /&gt;
When do you create dom element matching game element?&lt;br /&gt;
* If you have static layout you create it in .tpl file and its always there, but during initial setup or during notification it moved in proper spot (including &amp;quot;removed from the game&amp;quot; spot)&lt;br /&gt;
* If you dynamically generated pieces you create the element during notification, and sometimes during animation. Also don&#039;t forgot to hook event listener to it if its interactive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One of the greatest parts about the web is all client side code can be viewed in your browser, so if you wondering how something is done in another BGA game just load the page and spy on it! In Chrome that would be right click and &amp;quot;Inspect Element&amp;quot;. That would immediately show html of the given element alongside with css used for it (on the right). Another great way to learn is you can add yourself to any BGA project as read only from the project page!&lt;br /&gt;
&lt;br /&gt;
So at the end of this stage you should complete the following (keeping in mind reduced rules/material for first iteration):&lt;br /&gt;
* Create a layout of the game, with positioning of main board, player areas, zones, other supporting areas, etc&lt;br /&gt;
* Create css and html snippets for all game pieces: boards, tokens, meeples, etc. Place them all in initial template (even if they&#039;re not supposed to be visible at start). I.e. create fake player&#039;s hand with cards, put meeples on the board&lt;br /&gt;
* Hook layout to number of players and colors picked by the game and test with multiple players&lt;br /&gt;
* Figure out what you want to display in mini-player boards and hook it up&lt;br /&gt;
* Create material.inc.php and populate with initial values (names, tooltips, rules) for all relevant game elements or classes of elements&lt;br /&gt;
&lt;br /&gt;
If at this time you don&#039;t have graphics yet create pieces with just CSS, you can use shape, background color and object text using css ::after construct to fake the pieces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Injected_text.png]]&lt;br /&gt;
&lt;br /&gt;
== Hook Input and Animation ==&lt;br /&gt;
&lt;br /&gt;
This step can be done before or after some of the server steps, or you go in iterations switching back and forward until you get it done, up to you.&lt;br /&gt;
&lt;br /&gt;
At this time you want to hook clicking on pieces and buttons and provide some reaction, such of moving a piece. The handler code will be replaced later by the server hook, but at the beginning you want your game to be alive as early as possible. &lt;br /&gt;
&lt;br /&gt;
Usually all pieces will be hooked to onclick during JS &amp;quot;setup&amp;quot; method, in addition if you create elements during server notification they have to be hooked up at that time.&lt;br /&gt;
&lt;br /&gt;
You can play with animation effects you want put in place, in general all the pieces that move in real game should be moving, such as meeples, resources tokens/cubes, cards, vp tokens. &lt;br /&gt;
Regular piece animation is provided by BGA framework, but if you use html layout positioning not inline positioning you have to remove absolute positions (inline position styling) after each move. The set of functions for relative position token animation can found in https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js &lt;br /&gt;
&lt;br /&gt;
Also its a good idea to give player a visual cues on what game elements are clickable now, usually it will be a style, such as &amp;quot;active_slot&amp;quot;, with visual effect of white dashed outline (outline is better then border, because border changes will make piece slightly move since it changes the size) or box-shadow (i.e. neon glow)&lt;br /&gt;
&lt;br /&gt;
If you read [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] you know that you should not get carried away with animation, you are creating a board game not a video game... That also applies to sound effects (in general, you should not use any sounds effects beside already provided by framework).&lt;br /&gt;
&lt;br /&gt;
See [[Game_interface_logic:_yourgamename.js#Players_input|Player&#039;s Input]] and [[Game_interface_logic:_yourgamename.js#Access_and_manipulate_the_DOM|Animation and DOM Manipulation]] for JS reference.&lt;br /&gt;
&lt;br /&gt;
== Create Database Schema ==&lt;br /&gt;
&lt;br /&gt;
At some point you have to design your game database. Do it sooner then later since it would be harder to change it later, since some&lt;br /&gt;
code decisions would be based on that.&lt;br /&gt;
&lt;br /&gt;
If you have grid-based abstract game use template from reversi, if you have a card game use template from hearts (the cards one also commented out in generated template for your project). The cards database goes with php class called [[Deck]].&lt;br /&gt;
&lt;br /&gt;
In general make it as simple as possible. &lt;br /&gt;
Think about it, your game has 300 pieces (likely less). Using database to store this amount of data is like shooting a mosquito with a tank.&lt;br /&gt;
Anything more complex then one table with 5 columns or two tables will only going to make it harder to develop and not improve performance.&lt;br /&gt;
You can forget about normalising and any fancy stuff you learn about databases in school. String field for a primary key would be as fast as integer when we talking about this size of data. So don&#039;t over-optimize with trying to have integers field that have state based on bitmask!&lt;br /&gt;
&lt;br /&gt;
Also remember that static (non dynamic) information about the game does not need to be stored in the database, that all include everything that does not change, i.e&lt;br /&gt;
all token/card properties such as name, tooltips, &amp;quot;strength&amp;quot;, color, etc. This is stored in material.inc.php and server has access to it from anywhere, as well as client&lt;br /&gt;
if you send it with getAllDatas(). The only reason store some of it in database if it can affect your queries (i.e. type of token).&lt;br /&gt;
&lt;br /&gt;
Usually design process will contain the following steps:&lt;br /&gt;
* Design game model - model that represent your game in progress, such as at any given step you can restore the game from that model&lt;br /&gt;
* Mapping - now map real game to that model&lt;br /&gt;
* Encoding - now represent this model in database and material file with reasonable amount of fields&lt;br /&gt;
&lt;br /&gt;
Example: &#039;&#039;&#039;The card game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but as part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in your database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position itself usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what info changes and what info is static, static info is always candidate for material file or html&lt;br /&gt;
* For dynamic stuff we should try to reduce amount of fields we need, i.e. we need a field for card, so its one, we need to know what zone cards belong to, its 2, and we have possible few other fields, but if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face  down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
You can also use cards database schema and [[Deck]] implementation for most purposes (even you not dealing with cards).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another Example: &#039;&#039;&#039;The euro game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based &lt;br /&gt;
games can be in most case represented by (string: token_key, string: location, int: state), example of such database schema can be found here:&lt;br /&gt;
[https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php tokens.php].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See [[Game database model: dbmodel.sql]] for details about editing the file.&lt;br /&gt;
&lt;br /&gt;
Note: the simpler the database is the less debugging of db issues you have to deal with including database migration. The tokens database above - if you use it you never have to worry about migration because you don&#039;t need extra tables in 95% of the games.&lt;br /&gt;
Here are some example of how real games are mapped to such database:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chess&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
- chess is grid base game and normally you would use positional columns, but just for the sake of argument, the chess game will look like this&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_white&lt;br /&gt;
|f3&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|P_black_2&lt;br /&gt;
|c6&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|K_black&lt;br /&gt;
|e8&lt;br /&gt;
|1&lt;br /&gt;
|}&lt;br /&gt;
And the state in this case indicated that kind was moved for example (which means castling cannot be performed)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Classic card game&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Lets pretend we need 2 decks for that game&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_spades_1&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_2&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|2 /* position */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_1&lt;br /&gt;
|tableau_common&lt;br /&gt;
|1 /* face down */&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Eminent Domain (card game)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|card_tech_23&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|1 /* face up */&lt;br /&gt;
|-&lt;br /&gt;
|reource_s_22 /* silicon */&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|2 /*  production state */&lt;br /&gt;
|-&lt;br /&gt;
|fighter_F_1&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also look at other games that use Tokens database and access layer: Nippon, Dungeon Petz, Lewis &amp;amp; Clark, Battleship, Russian Railroads, Khronos&lt;br /&gt;
&lt;br /&gt;
== Implement Game Setup ==&lt;br /&gt;
&lt;br /&gt;
Once you have your database schema you can do a proper game setup. Usually you open rulebook on the &amp;quot;Game Setup&amp;quot; page&lt;br /&gt;
and implement these step by step populating the database (using db access API).&lt;br /&gt;
Game initialization is performed in php method setupNewGame, this method is called once when game table is created.&lt;br /&gt;
Game notifications cannot be sent during this time.&lt;br /&gt;
&lt;br /&gt;
== Implement One time game model synchronisation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now at any point in the game we need to make sure that database information can be reflected back in UI, so we fix getAllDatas function&lt;br /&gt;
to return all possible data we need to reconstruct the game. The template for getAllDatas already taking care of player info, but you &lt;br /&gt;
have to alter it to return all other data from database visible to the &amp;quot;current&amp;quot; player.&lt;br /&gt;
&lt;br /&gt;
After that on the client side we should display this data, so in your .js file in setup function (which is the receiver of getAllDatas) you add calls that handle data send by server, usually by calling animation function such as &amp;quot;placeToken&amp;quot; or &amp;quot;placeCard&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Create State Machine ==&lt;br /&gt;
&lt;br /&gt;
Now you need to create a game state machine. &lt;br /&gt;
&lt;br /&gt;
The state handling spread across 4 files, so you have to make sure all the pieces are connected together.&lt;br /&gt;
The state machine states.inc.php defines all the states, and function handlers on php side in a form of string,&lt;br /&gt;
and if any of these functions are not implemented it would be very hard to debug because it will break in random places.&lt;br /&gt;
&lt;br /&gt;
Please first watch this again [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine  BGA game state machine]&lt;br /&gt;
and then please read [[Your game state machine: states.inc.php]].&lt;br /&gt;
&lt;br /&gt;
Now the state machine should be relatively simple. If you find yourself with machine with more than 20 states its probably not the way to go.&lt;br /&gt;
Not all the player interactions need separate states, a lot of things can be implemented directly on client, i.e. if your player need to select&lt;br /&gt;
a reward token, which offers choice of resource, instead of two states on server just have one state on server and possible few states on client (client side states)&lt;br /&gt;
to collect this info.&lt;br /&gt;
&lt;br /&gt;
== Handle Turn Order ==&lt;br /&gt;
&lt;br /&gt;
If your game goes in clockwise order in natural sitting position nothing really needed you just use standard API and you are good. However if position is complecated&lt;br /&gt;
it may require some trickery.&lt;br /&gt;
&lt;br /&gt;
Usually turn order is done by &amp;quot;game state&amp;quot; (see state machine above). Basically it would be two choices:&lt;br /&gt;
* Turn order depends on game situation (such as we take player with highest number of red cubes)&lt;br /&gt;
* Turn order is custom and assign on previos step - i.e. we not playing in clockwise order anymore. In this case you either need to extend player table with new order info (CANNOT use player_no column) or use order markers that come with game (i.e. marker_ff0000 on position_1). In this we can build player array in right order and pick next player based on previous player using existing helper function such as $this-&amp;gt;createNextPlayerTable($player_ids)&lt;br /&gt;
&lt;br /&gt;
== Implement Notification handling ==&lt;br /&gt;
&lt;br /&gt;
Now to implement things for real we have hook UI actions to ajax calls, and process notifications send by server.&lt;br /&gt;
So previously we hooked onclick js handler right to client animation, in real game its a two&lt;br /&gt;
step operation. When user clicks on something, client sends an ajax call to server, server processes it and updates database, server sends&lt;br /&gt;
notification in response, client hooks animations to server notification. See [[Game_interface_logic:_yourgamename.js#Notifications|JS Notifications]].&lt;br /&gt;
&lt;br /&gt;
Exception to this is client states, if you need to process two step user interaction such as select meeple, place meeple, you may want &lt;br /&gt;
to avoid sending data to server until step is complete (which may involve direct client side animation). See [[BGA_Studio_Cookbook#Multi_Step_Interactions:_Select_Worker.2FPlace_Worker_-_Using_Selection|Multi-Step Interactions]]&lt;br /&gt;
&lt;br /&gt;
Part of the sending notifications would be to update player&#039;s scoring, BGA uses standard control for score (on JS side), see [[Game_interface_logic:_yourgamename.js#Update_players_score|Update Player&#039;s Score]].&lt;br /&gt;
&lt;br /&gt;
In BGA there is only two ways interact with the server (officially)&lt;br /&gt;
* Initial data dump - when JS client starts it gets all current data via setup() method&lt;br /&gt;
* Game actions - ajaxcall from client, it returns error or ok (not data), then server send butch of notifications to client&lt;br /&gt;
&lt;br /&gt;
Note current ajaxcall is super vebosy and prone to errors, I suggest to use helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
				if (!args) args = []; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
				&lt;br /&gt;
				args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
&lt;br /&gt;
				if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
					this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
						this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                                handler); // this is real result handler - it called both on success and error, its is optional param - you rarely need it&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you insert a single action you have to update multiples files:&lt;br /&gt;
* in ggg.js add ajaxcall, i.e. something like &lt;br /&gt;
  this.addActionButton(&#039;pass&#039;,_(&#039;Pass&#039;),()=&amp;gt;this.ajaxcallwrapper(&#039;pass&#039;));&lt;br /&gt;
* in states.php - add action &#039;pass&#039; to list of possible actions&lt;br /&gt;
  &#039;possibleactions&#039; =&amp;gt; [&#039;pass&#039;,&#039;playCard&#039;]&lt;br /&gt;
* in action.php - add action hander, see https://en.doc.boardgamearena.com/Players_actions:_yourgamename.action.php&lt;br /&gt;
* in game.php - add action hander, there you must do the following&lt;br /&gt;
** call checkAction to validate the action&lt;br /&gt;
** possible do more game specific check to validate what player doing is legal (even its not possible from your js side - player can cheat - not allow that)&lt;br /&gt;
** do some database maniplations, using access api&lt;br /&gt;
** send notifications - this is the &amp;quot;reply&amp;quot; for action&lt;br /&gt;
** transition to new state (it very rare that  user will remain in the same state, except for multi-active states)&lt;br /&gt;
* back to ggg.js add notification subsciption and notification handler (two separate things)&lt;br /&gt;
&lt;br /&gt;
== Wrap Up ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Implement game progression (getGameProgression() in php)&lt;br /&gt;
* Implement Zombie turn  (zombieTurn() in php)&lt;br /&gt;
* Define and implemented some meaningful statistics for your game (i.e. total points, point from source A, B, C...)&lt;br /&gt;
* The games logs should explain what happened if player was not looking&lt;br /&gt;
* You need to implemented tiebreaking (using aux score field) and updated tiebreaker description in meta-data&lt;br /&gt;
* Make sure all UI strings are marked for translation&lt;br /&gt;
* UI elements which are images (i.e. tokens, cards) should have tooltips&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Alpha ==&lt;br /&gt;
When you think you game is completely working there is still bunch of stuff you have to do/check before telling admin that game is ready, please go though this [[Pre-release checklist]].&lt;br /&gt;
&lt;br /&gt;
If you think its completely ready, let admin know (studio@boardgamearena.com) and it they will push it to alpha.&lt;br /&gt;
&lt;br /&gt;
Finally, visit the game page for your alpha game (https://boardgamearena.com/gamepanel?game=…) to add the following information if you can:&lt;br /&gt;
* Links to the rules (in multiple languages if available).&lt;br /&gt;
* Links to teaching videos.&lt;br /&gt;
* In the &amp;quot;On the web&amp;quot; section, links to:&lt;br /&gt;
** The official website for the game (if there is one).&lt;br /&gt;
** The BoardGameGeek page for the game.&lt;br /&gt;
* Consider writing a summary of the rules.&lt;br /&gt;
&lt;br /&gt;
== Level Up ==&lt;br /&gt;
&lt;br /&gt;
When you successfully created a basic game and you want more, its time to make it fancy!&lt;br /&gt;
&lt;br /&gt;
* Add game externtions and variants using gameoptions file&lt;br /&gt;
* Add user preferences for customizations&lt;br /&gt;
* Use theming! That involves replacing hardwood background, changing tooltips, using different sounds, different fonts, changing state prompt and logs&lt;br /&gt;
* You can use fancy scoring board at the end of game instead of default nothing&lt;br /&gt;
* And finally super cool dice rolling, card flipping and victory points evaporating effects&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
	<entry>
		<id>https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11463</id>
		<title>Create a game in BGA Studio: Complete Walkthrough</title>
		<link rel="alternate" type="text/html" href="https://en.doc.boardgamearena.com/index.php?title=Create_a_game_in_BGA_Studio:_Complete_Walkthrough&amp;diff=11463"/>
		<updated>2022-01-18T22:31:28Z</updated>

		<summary type="html">&lt;p&gt;Grandepezzin: /* Create Initial Layout and Game Graphics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Studio_Framework_Navigation}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This document is not a tutorial, but step by step instructions on how to build your own first game adaptation using BGA Studio framework.&lt;br /&gt;
&lt;br /&gt;
Before you read this material, you must:&lt;br /&gt;
* Read the overall presentations of the BGA [[Studio]].&lt;br /&gt;
* Some-what know the languages used by BGA Studio: PHP, SQL, HTML, CSS, Javascript&lt;br /&gt;
* Setup your development environment [http://en.doc.boardgamearena.com/First_steps_with_BGA_Studio First Steps with BGA Studio]&lt;br /&gt;
* Create a game using one of the available tutorials. Don&#039;t bother with a new game if you have not completed at least one of the tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck or have questions about this page post on [https://forum.boardgamearena.com/viewforum.php?f=12 BGA Developers forum].&lt;br /&gt;
If you&#039;re uncomfortable posting on the public forum you can send messages directly to developers who post answers on that forum but NOT the BGA admins.&lt;br /&gt;
If you find typos in this wiki - fix it.&lt;br /&gt;
&lt;br /&gt;
== Select a First Game ==&lt;br /&gt;
&lt;br /&gt;
For your first &#039;&#039;&#039;real&#039;&#039;&#039; game you must either&lt;br /&gt;
* Select a game from [https://en.studio.boardgamearena.com/licensing Available Licenses]&lt;br /&gt;
* Or from the Public Domain&lt;br /&gt;
&lt;br /&gt;
But what if the game you want is not there? If you are able to successfully publish your first game, you would gain the trust of the BGA admins and they will be happy to assist you in obtaining a license for a game you really want to do or you can request a license yourself. You can read more about game licenses on [[BGA Game licenses]] page.&lt;br /&gt;
&lt;br /&gt;
Once you selected the game but before creating a new project, please take a few seconds to check that someone is not already developing this game. If it is the case, maybe you can propose to join the project?&lt;br /&gt;
&lt;br /&gt;
[http://en.studio.boardgamearena.com/#!projects Check the list of current projects]&lt;br /&gt;
&lt;br /&gt;
Even if you see a few projects with name of the game they may not be active. There are a lot of abandoned game projects. If it&#039;s not clear by the status, post to Developers forum asking if anybody actively working on the project or send a message to developers listed for the abandoned projects, and at the same time ask admins on the same forum post to send you graphics for that game if they have them (there a button on [https://en.studio.boardgamearena.com/licensing Available Licenses] page to request graphics, but it will just send email).&lt;br /&gt;
&lt;br /&gt;
If your goal was to fix bugs in an existing project, first try to locate on studio, projects developed by bga admins are not in the studio. Then get read only access to the project and you can create your own as a copy of the existing one. Contact existing project admin about getting write access to the original project or if they willing to take your patches - apply them.&lt;br /&gt;
&lt;br /&gt;
If you want to take over an existing project first ask on forum to see if project is abandoned, then get read only access (via project list) and see if this worth using it, if it has no code or graphics just start from the scratch, don&#039;t worry about project name it can be renamed later.&lt;br /&gt;
&lt;br /&gt;
== Create a project ==&lt;br /&gt;
&lt;br /&gt;
If you have not already, you have to create a project in BGA Studio for this game. If the original game name is taken use gamenameYOURINITIALS&lt;br /&gt;
template, i.e.&amp;quot;heartsla&amp;quot;. Don&#039;t worry too much about the name, if game would be good enough to be publish it will be renamed to original name. &lt;br /&gt;
&lt;br /&gt;
Find and start the game in turn based mode, make sure it works.&lt;br /&gt;
&lt;br /&gt;
Second, modify the text in .tpl file, reload the page in the browser and make sure your ftp sync works as expected.&lt;br /&gt;
Note: if you have not setup [http://en.doc.boardgamearena.com/Tools_and_tips_of_BGA_Studio#File_Sync FTP auto-sync] yet, do it now, manually copying files is a no-starter.&lt;br /&gt;
&lt;br /&gt;
Update your project status in [http://en.studio.boardgamearena.com/#!studio Control Panel &amp;gt; Manage games] page, you can say &amp;quot;development started&amp;quot; or &amp;quot;waiting for license&amp;quot; or &amp;quot;waiting for graphics&amp;quot; or combination of those.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Development Tools ==&lt;br /&gt;
&lt;br /&gt;
At some point you need to setup your development environment which consist of multiple tools, such as&lt;br /&gt;
* Editor or IDE&lt;br /&gt;
* Browser with dev tools&lt;br /&gt;
* File sync tools&lt;br /&gt;
* BGA Web tools&lt;br /&gt;
* Image manipulation tools&lt;br /&gt;
* Version control tools&lt;br /&gt;
&lt;br /&gt;
Please scan though articles from [[Studio#BGA_Studio_user_guide]] especially related to debugging and tools, there is a lot of useful info there.&lt;br /&gt;
&lt;br /&gt;
== Hook version control system ==&lt;br /&gt;
&lt;br /&gt;
If its a real game I would commit the code to version control right at start. You going to find yourself in the situation&lt;br /&gt;
when game does not even start anymore and no way of debugging it unless you have a way to revert. That is where version control becomes very handy.&lt;br /&gt;
If you don&#039;t know what I am talking about then at least back-up your files after each of major steps. Starting now.&lt;br /&gt;
You can also create a project on github, but make sure &#039;&#039;&#039;you don&#039;t commit original publisher graphics files&#039;&#039;&#039; and &#039;&#039;&#039;you don&#039;t include a file with your sftp password&#039;&#039;&#039; (github is automatically crawled for passwords by hackers; a hacking attempt occurred on BGA studio for this reason in June 2020).&lt;br /&gt;
You can (and should) also commit your modification periodically via studio&#039;s control panel.&lt;br /&gt;
&lt;br /&gt;
== Obtain game graphics ==&lt;br /&gt;
&lt;br /&gt;
If you developing a game from Available Licenses games, ask the admins to send you graphics by contacting studio@boardgamearena.com. While that request is being processed (it can take time, as it often requires some back and forth  between the admins and the publishers) you can proceed to next step - project creation.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t get original graphics you go to &#039;&#039;&#039;Scavenger Hunt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If you developing a public domain card game you can borrow standard cards from BGA generic assets, see [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Standard game pieces - meeples, cubes, dice can be found here as well [[Common_board_game_elements_image_resources]]&lt;br /&gt;
* Go to boardgamegeek.com find your game and obtain 3D game box image, 2D box image, and if you lucky they also sometime have boards and token scans in &amp;quot;Game Pieces&amp;quot; section of Images&lt;br /&gt;
* If that fail google &amp;quot;boardgame &amp;lt;name&amp;gt;&amp;quot; and check Images section&lt;br /&gt;
* Get the rules PDF as well, there tools that allows you to extract graphics from PDF, which usually good for meeples, cubes and such (can use pdfimages command line tool)&lt;br /&gt;
&lt;br /&gt;
Once you get the graphics one way or another you have to massage it to fit in the BGA criteria, which usually involves&lt;br /&gt;
* If publisher sends graphics in one token/card per file mode, you have to stitch them in sprite and scale down&lt;br /&gt;
* For non square tiles and game pieces you need transparency&lt;br /&gt;
* Usually you chop off scoring &amp;quot;ring&amp;quot; around the board of the game since scoring track not needed for online adaptation&lt;br /&gt;
&lt;br /&gt;
More details about graphics requirements can be found here [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
[[File:Rrr_search.png]]&lt;br /&gt;
&lt;br /&gt;
== Obtain game documentation ==&lt;br /&gt;
&lt;br /&gt;
Also at this time obtain a electronic copy of rules, such as PDF (English version). &lt;br /&gt;
&lt;br /&gt;
Also grab any other documents you may find on boardgamegeek such as FAQ, additional Reference books, and user created assistant documents, such&lt;br /&gt;
as cheat-sheets (may be easier to get a data from these then trying to scrub pdf). You create and place them in the doc/ folder of the project then&lt;br /&gt;
exclude them from version control. There is also a misc/ folder now but it will hold up to 1 Mb of data files which would be checked in, so rules pdf&#039;s may not fit there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Update game infos and box graphics ==&lt;br /&gt;
&lt;br /&gt;
Even it does not nothing yet start with making sure game looks descent in the game selector, meaning it has nice box graphics and information is correct. &lt;br /&gt;
&lt;br /&gt;
For that we need to edit [[Game_meta-information: gameinfos.inc.php|gameinfos.inc.php]].&lt;br /&gt;
What you would do for real game you would go to http://boardgamegeek.com find the game and use the information from web-site to fill the gameinfos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step is to replace game_box.png with proper images, usually you can find all images including publisher logo on boardgamegeek website.&lt;br /&gt;
&lt;br /&gt;
Details about images can be found here: [[Game art: img directory]].&lt;br /&gt;
&lt;br /&gt;
Now important step. You have to LOAD these files in studio website through control panel. So go to Control Panel -&amp;gt; Manager Games -&amp;gt; YOURPROJECT&lt;br /&gt;
and press Reload for &#039;Reload game informations&#039; and &#039;Reload game box image&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Gamepanel_sharedcode.png]]&lt;br /&gt;
&lt;br /&gt;
Now try to start the game again. If you some-how introduced a syntax error in gameinfos file it may not actually work (game won&#039;t start).&lt;br /&gt;
Always use &amp;quot;Express Start&amp;quot; button to start the game. You should see a standard state prompt from template. You should see X players on the right, testdude0 .. testdudeX-1.&lt;br /&gt;
To switch between them press the red arrow button near their names, it will open another tab. This way you don&#039;t need to login and logout from multiple accounts!&lt;br /&gt;
&lt;br /&gt;
== Fix source copyright ==&lt;br /&gt;
&lt;br /&gt;
Now since you have your own project, you want put your name in the copyright header, so replace&lt;br /&gt;
&lt;br /&gt;
  © &amp;lt;Your name here&amp;gt; &amp;lt;Your email address here&amp;gt;&lt;br /&gt;
with&lt;br /&gt;
  © John Snow &amp;lt;jsnow@gameofthrones.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well not exactly this but whatever your real name is. For all files in project directory, its about 10 files. Make sure project still starts after that :)&lt;br /&gt;
&lt;br /&gt;
== Reduce the Rules ==&lt;br /&gt;
&lt;br /&gt;
Programming a game will take a lot more time than you may think. Most of the projects in the studio are abandoned because of lack of patience or skill.&lt;br /&gt;
To keep sane, start the game with *reduced* rules and try to complete that first.&lt;br /&gt;
&lt;br /&gt;
* If it has any expansions - do not even attempt to deal with them, not even - &amp;quot;I will just add graphics for them now and not use&amp;quot; - waste of time if you don&#039;t complete basic&lt;br /&gt;
* If it has advanced rules - start with basic rules only, i.e. &amp;quot;beginner game&amp;quot;&lt;br /&gt;
* If it has special rules for 2 player vs 4, start with most basic form (i.e. 4), restrict to 4 players &lt;br /&gt;
* If it has 50 unique cards of 2 each - start with 2 unique cards with 25 each (just to keep it moving)&lt;br /&gt;
* Any sort of rules that you think can be removed and not included in base - set aside for now &lt;br /&gt;
* Ignore any sort of cool animations - dice rolling, card flipping, choo-choo sounds of the trains - all this fluff can be added later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Game Elements ==&lt;br /&gt;
Technically game elements are already designed by board game designer but your job is to map it to program space.&lt;br /&gt;
Each physical piece (card, token, cube) will leave footprints all over the code (unfortunatly in multiple disconnected places).&lt;br /&gt;
To prepare the game you need to sort out these elements, i.e. categorize. I usually have to the following categorization (in object oriented view):&lt;br /&gt;
* Instance - all individual pieces are instances, i.e. two red cubes are two instances of &#039;red cube&#039; type (class)&lt;br /&gt;
* Type - element type which distinctly represents that element in appearence (i.e. red cube is different type than blue cube)&lt;br /&gt;
* Super Type - one of more common types that similar properties (i.e. red OR cube)&lt;br /&gt;
* Player color - supertype specific for player color (sometimes there is no colors but like player 1 - but is conceptually the same, I use color because its easier to track)&lt;br /&gt;
&lt;br /&gt;
Personally I like to encode my elements in string using reverse dns notation listing all the properties above, i.e.&lt;br /&gt;
  meeple_ff0000_7 - this is instance #7 of type meeple_ff0000 (red meeple)&lt;br /&gt;
Or&lt;br /&gt;
  card_yellow_magic_2 - this is instance #2 of yellow card (in this case yellow is color of deck not related to player color) that can do magic&lt;br /&gt;
&lt;br /&gt;
So every game element would be in the&lt;br /&gt;
&lt;br /&gt;
1. Database - instances. The db record would be something like &lt;br /&gt;
  key|location|state&lt;br /&gt;
  meeple_ff0000_7|slot_action_2|1&lt;br /&gt;
  meeple_ff0000_2|tableau_ff0000|0&lt;br /&gt;
2. Material file - types and supertypes, we never need repeating info here, so never list individual instances but only types or supertypes, in this case we don&#039;t really need to define red meeple vs blue meeple&lt;br /&gt;
  &#039;meeple&#039;=&amp;gt;{&#039;name&#039;=&amp;gt;totranslate(&#039;Meeple&#039;)}&lt;br /&gt;
3. Client (js, css, tpl, etc) - instances and types. For example my meeple will be like &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;meeple_ff0000_7&amp;quot; class=&amp;quot;meeple meeple_ff0000&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
with .css something like&lt;br /&gt;
  .meeple { background-image: url(img/tokens.png); width: 2em; height: 2em;}&lt;br /&gt;
  .meeple_ff0000 {background-position: 20% 0%;}&lt;br /&gt;
4. Game php - setup and logic. During setup you have to generate all the pieces and place them in right positions. Also sometimes you need to reference elements to code the logic (I usually try to encode all rules in material file as much as possible)&lt;br /&gt;
&lt;br /&gt;
For complex card games I think it is the best to keep all these info and rules in spreadsheet and generate other files such as material.inc.php.&lt;br /&gt;
See more info below about design of the individual layers.&lt;br /&gt;
&lt;br /&gt;
== Create Initial Layout and Game Graphics ==&lt;br /&gt;
&lt;br /&gt;
Mentally it is easier to start with game layout and graphics pieces. Even when nothing is working its give you moral satisfaction!&lt;br /&gt;
&lt;br /&gt;
There are a few ways how the html could have been generated. You could have started with nothing and generate&lt;br /&gt;
it all by javascript, or you could have started with complete game markup in html and make javascript just hide and move pieces around. BGA framework also provides a third way, which is mix of both, plus a template engine to generate HTML using PHP. The only thing that is really annoying about the template engine is that you cannot put any translatable strings in the template (which means any visible text at all). If you are using the template approach all strings have to extracted as variables and injected through PHP (.view.php). This page explains the template engine in great detail:[[Game_layout:_view_and_template:_yourgamename.view.php_and_yourgamename_yourgamename.tpl|Template Engine]].&lt;br /&gt;
&lt;br /&gt;
The other disadvantage of the template engine is you cannot run and debug it locally, in the beginning of development it&#039;s a lot faster run off local pages, &lt;br /&gt;
you can do it with some trickery described here [[Tools_and_tips_of_BGA_Studio#Speed_up_CSS_development_and_layout|Tools and Tips for BGA Studio]]&lt;br /&gt;
&lt;br /&gt;
During this step you have to decide what technical solutions you will be using, such as&lt;br /&gt;
* Use inline positioning of all moving pieces, controlled by JS. There are a few classes that already exist in Studio to help with that (see [[Studio#Game_interface_.28Client_side.29|Game Interface - Client Side]]). OR use html/css layout engine to position pieces (my personal choice).&lt;br /&gt;
* Use BGA template engine OR create all ui elements by JS OR manually write or generate complete html markup. The game usually contain 200-300 pieces, it seems wrong but actually its faster to type all of this up in html/css when trying write than debug code for page generator.&lt;br /&gt;
Static HTML markup also means you have to use players color or abstracted player number (such as red is 1, blue is 2) not player id&#039;s anywhere in JS, since player id is dynamic by nature.&lt;br /&gt;
&lt;br /&gt;
Start by creating and mapping all games assets, best way is probably to open rule book on &amp;quot;boardgame contents&amp;quot; page and go through every piece. Every pieces of boardgame would have its &amp;quot;print&amp;quot; in multiple files in your game:&lt;br /&gt;
* Some sort if &amp;quot;div&amp;quot; in html, where id of element match id of element in database (easiest way)&lt;br /&gt;
* Css for the element (either unique or for class), usually with background propery refering to part of sprite image&lt;br /&gt;
* Entry in material.inc.php referring to static properties of the element, i.e. name, tooltip, rules, etc&lt;br /&gt;
* Entry in .tpl file to represent static or initial location on the table OR creation template&lt;br /&gt;
&lt;br /&gt;
Here are some specific examples:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create entry in .tpl file for the board, it will be static entry as we never need to create this dynamically&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  &amp;lt;div id=&amp;quot;board&amp;quot; class=&amp;quot;board shadow board4p&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create entry in .css file for this board and other board variants (in example below we have 4 ppl board whcih is diffrent than 2 ppl board)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.board {&lt;br /&gt;
	position: relative;&lt;br /&gt;
	width: 980px;&lt;br /&gt;
	height: 433px;&lt;br /&gt;
	margin-bottom: 5px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.board4p {&lt;br /&gt;
	background-image: url(img/board4p.jpg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
That wold be pretty much it for the board itself, as it does not really need a tooltip so we don&#039;t need entry in material.inc.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Game Board Slots&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
These are interactive areas on the board, usually illustrated as such. In most cases you can get away with rectangular shapes, but sometimes you have to create circle or oval shapes (and in really advanced case would be some svg  paths). For slots you can do the following:&lt;br /&gt;
&lt;br /&gt;
Entry in material.inc.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$this-&amp;gt;token_types = array(&lt;br /&gt;
...&lt;br /&gt;
&#039;slot_action_2&#039; =&amp;gt; array(&lt;br /&gt;
  &#039;type&#039; =&amp;gt; &#039;slot_action&#039;,&lt;br /&gt;
  &#039;name&#039; =&amp;gt; clienttranslate(&amp;quot;2 Gray Track Advancements&amp;quot;),&lt;br /&gt;
  &#039;tooltip&#039; =&amp;gt; clienttranslate(&amp;quot;This action gives you two advancements of gray track. You cannot use this action if you cannot complete all advancements.&amp;quot;),&lt;br /&gt;
  &#039;o&#039;=&amp;gt;&amp;quot;1,0,0,gg&amp;quot;, // automatic rules&lt;br /&gt;
),&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in template inside the &amp;quot;board&amp;quot; div&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	&amp;lt;div id=&amp;quot;slot_action_2&amp;quot; class=&amp;quot;slot_action_2 slot_action slot_w_1 slot&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Entry in .css with absolute position within the board (its actually better to use percentage - would be easier to scale later)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.slot_action_2 {&lt;br /&gt;
	top: 83px;&lt;br /&gt;
	left: 37px;&lt;br /&gt;
}&lt;br /&gt;
.slot_action {&lt;br /&gt;
	position: absolute;&lt;br /&gt;
	width: 46px;&lt;br /&gt;
	height: 26px;&lt;br /&gt;
	padding: 9px 7px 6px 4px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Meeples&#039;&#039;&#039; - also cards, tokens, other mobile stuff&lt;br /&gt;
&lt;br /&gt;
In css these guys will use &amp;quot;sprite&amp;quot; images with transparency, so it will look like this this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.meeple {&lt;br /&gt;
	background-image: url(img/tokens.png);&lt;br /&gt;
	width: 25px;&lt;br /&gt;
	height: 25px;&lt;br /&gt;
}&lt;br /&gt;
.meeple_ff0000 { /* red */&lt;br /&gt;
	background-position: 14% 0%;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As for creation you can either generate them using template (where whole thing wrapped in template block and {COLOR} replace with all possible colors in .view.php&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_1&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;div id=&amp;quot;meeple_{COLOR}_2&amp;quot; class=&amp;quot;meeple meeple_{COLOR} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can declare a template js var in .tpl file &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    var jstpl_mepple = &#039;&amp;lt;div id=&amp;quot;meeple_${color}_${num}&amp;quot; class=&amp;quot;meeple meeple_${color} meepleable&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;; // this is in .tpl file at the bottom&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and create in js, like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 var tokenDiv = this.format_block(&#039;jstpl_mepple&#039;, {&lt;br /&gt;
                                &amp;quot;color&amp;quot; : color,&lt;br /&gt;
                                &amp;quot;num&amp;quot; : i&lt;br /&gt;
                            }); // this in js code somewhere before placing it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you dealing with cards and decks, there are pre-build components that can generate stuff for you.&lt;br /&gt;
&lt;br /&gt;
When do you create dom element matching game element?&lt;br /&gt;
* If you have static layout you create it in .tpl file and its always there, but during initial setup or during notification it moved in proper spot (including &amp;quot;removed from the game&amp;quot; spot)&lt;br /&gt;
* If you dynamically generated pieces you create the element during notification, and sometimes during animation. Also don&#039;t forgot to hook event listener to it if its interactive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One of the greatest parts about the web is all client side code can be viewed in your browser, so if you wondering how something is done in another BGA game just load the page and spy on it! In Chrome that would be right click and &amp;quot;Inspect Element&amp;quot;. That would immediately show html of the given element alongside with css used for it (on the right). Another great way to learn is you can add yourself to any BGA project as read only from the project page!&lt;br /&gt;
&lt;br /&gt;
So at the end of this stage you should complete the following (keeping in mind reduced rules/material for first iteration):&lt;br /&gt;
* Create a layout of the game, with positioning of main board, player areas, zones, other supporting areas, etc&lt;br /&gt;
* Create css and html snippets for all game pieces: boards, tokens, meeples, etc. Place them all in initial template (even if they&#039;re not supposed to be visible at start). I.e. create fake player&#039;s hand with cards, put meeples on the board&lt;br /&gt;
* Hook layout to number of players and colors picked by the game and test with multiple players&lt;br /&gt;
* Figure out what you want to display in mini-player boards and hook it up&lt;br /&gt;
* Create material.inc.php and populate with initial values (names, tooltips, rules) for all relevant game elements or classes of elements&lt;br /&gt;
&lt;br /&gt;
If at this time you don&#039;t have graphics yet create pieces with just css, you can use shape, background color and object text using css ::after construct to fake the pieces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Injected_text.png]]&lt;br /&gt;
&lt;br /&gt;
== Hook Input and Animation ==&lt;br /&gt;
&lt;br /&gt;
This step can be done before or after some of the server steps, or you go in iterations switching back and forward until you get it done, up to you.&lt;br /&gt;
&lt;br /&gt;
At this time you want to hook clicking on pieces and buttons and provide some reaction, such of moving a piece. The handler code will be replaced later by the server hook, but at the beginning you want your game to be alive as early as possible. &lt;br /&gt;
&lt;br /&gt;
Usually all pieces will be hooked to onclick during JS &amp;quot;setup&amp;quot; method, in addition if you create elements during server notification they have to be hooked up at that time.&lt;br /&gt;
&lt;br /&gt;
You can play with animation effects you want put in place, in general all the pieces that move in real game should be moving, such as meeples, resources tokens/cubes, cards, vp tokens. &lt;br /&gt;
Regular piece animation is provided by BGA framework, but if you use html layout positioning not inline positioning you have to remove absolute positions (inline position styling) after each move. The set of functions for relative position token animation can found in https://github.com/elaskavaia/bga-sharedcode/blob/master/sharedcode.js &lt;br /&gt;
&lt;br /&gt;
Also its a good idea to give player a visual cues on what game elements are clickable now, usually it will be a style, such as &amp;quot;active_slot&amp;quot;, with visual effect of white dashed outline (outline is better then border, because border changes will make piece slightly move since it changes the size) or box-shadow (i.e. neon glow)&lt;br /&gt;
&lt;br /&gt;
If you read [http://www.slideshare.net/boardgamearena/bga-studio-guidelines BGA developers guidelines] you know that you should not get carried away with animation, you are creating a board game not a video game... That also applies to sound effects (in general, you should not use any sounds effects beside already provided by framework).&lt;br /&gt;
&lt;br /&gt;
See [[Game_interface_logic:_yourgamename.js#Players_input|Player&#039;s Input]] and [[Game_interface_logic:_yourgamename.js#Access_and_manipulate_the_DOM|Animation and DOM Manipulation]] for JS reference.&lt;br /&gt;
&lt;br /&gt;
== Create Database Schema ==&lt;br /&gt;
&lt;br /&gt;
At some point you have to design your game database. Do it sooner then later since it would be harder to change it later, since some&lt;br /&gt;
code decisions would be based on that.&lt;br /&gt;
&lt;br /&gt;
If you have grid-based abstract game use template from reversi, if you have a card game use template from hearts (the cards one also commented out in generated template for your project). The cards database goes with php class called [[Deck]].&lt;br /&gt;
&lt;br /&gt;
In general make it as simple as possible. &lt;br /&gt;
Think about it, your game has 300 pieces (likely less). Using database to store this amount of data is like shooting a mosquito with a tank.&lt;br /&gt;
Anything more complex then one table with 5 columns or two tables will only going to make it harder to develop and not improve performance.&lt;br /&gt;
You can forget about normalising and any fancy stuff you learn about databases in school. String field for a primary key would be as fast as integer when we talking about this size of data. So don&#039;t over-optimize with trying to have integers field that have state based on bitmask!&lt;br /&gt;
&lt;br /&gt;
Also remember that static (non dynamic) information about the game does not need to be stored in the database, that all include everything that does not change, i.e&lt;br /&gt;
all token/card properties such as name, tooltips, &amp;quot;strength&amp;quot;, color, etc. This is stored in material.inc.php and server has access to it from anywhere, as well as client&lt;br /&gt;
if you send it with getAllDatas(). The only reason store some of it in database if it can affect your queries (i.e. type of token).&lt;br /&gt;
&lt;br /&gt;
Usually design process will contain the following steps:&lt;br /&gt;
* Design game model - model that represent your game in progress, such as at any given step you can restore the game from that model&lt;br /&gt;
* Mapping - now map real game to that model&lt;br /&gt;
* Encoding - now represent this model in database and material file with reasonable amount of fields&lt;br /&gt;
&lt;br /&gt;
Example: &#039;&#039;&#039;The card game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* In real word to &amp;quot;save&amp;quot; the game we take a picture a play area, save cards from it, then put away draw deck, discard and hand of each player separately and mark it, also we will record current scoring (if any) and who&#039;s turn was it&lt;br /&gt;
* Framework handles state machine transition, so you don&#039;t have to worry about database design for that (i.e. who&#039;s turn it is, what phase of the game we are at, you still have to design it but as part of state machine step)&lt;br /&gt;
* Also framework supports basic player information, color, order around the table, basic scoring, etc, so you don&#039;t have to worry about it either&lt;br /&gt;
* The only thing you need in your database is state of the &amp;quot;board&amp;quot;, which is &amp;quot;where each pieces is, and in what state&amp;quot;, or (position,rotation) pair.&lt;br /&gt;
* The card state is very simple, its usually &amp;quot;face up/face down&amp;quot;, &amp;quot;tapped/untapped&amp;quot;, &amp;quot;right side up/up side down&amp;quot;&lt;br /&gt;
* As position go we never need real x,y,z. We need to know what &amp;quot;zone&amp;quot; card was, and depending on the zone it may sometimes need an extra &amp;quot;z&amp;quot; or &amp;quot;x&amp;quot; as card order. The zone position itself usually static or irrelevant.&lt;br /&gt;
* So our model is: we have cards, which have some attributes, at any given point in time they belong to a &amp;quot;zone&amp;quot;, and can also have order and state&lt;br /&gt;
* Now for mapping we should consider what info changes and what info is static, static info is always candidate for material file or html&lt;br /&gt;
* For dynamic stuff we should try to reduce amount of fields we need, i.e. we need a field for card, so its one, we need to know what zone cards belong to, its 2, and we have possible few other fields, but if you look closely at you game you may find out that most of the zone only need one attribute at a time, i.e. draw pile always have cards face  down, hand always face up, also for hand and discard order does not matter at all (but for draw it does matter). So in majority of cases we can get away with one single extra integer field representing state or order&lt;br /&gt;
* In real database both card and zone will be integers as primary keys referring to additional tables, but in our case its total overkill, so they can be strings as easily&lt;br /&gt;
&lt;br /&gt;
You can also use cards database schema and [[Deck]] implementation for most purposes (even you not dealing with cards).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `card` (&lt;br /&gt;
  `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `card_type` varchar(16) NOT NULL,&lt;br /&gt;
  `card_type_arg` int(11) NOT NULL,&lt;br /&gt;
  `card_location` varchar(16) NOT NULL,&lt;br /&gt;
  `card_location_arg` int(11) NOT NULL,&lt;br /&gt;
  PRIMARY KEY (`card_id`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another Example: &#039;&#039;&#039;The euro game&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
See details on database design for euro game at [[BGA_Studio_Cookbook#Database_for_The_euro_game]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the piece mapping for non-grid based &lt;br /&gt;
games can be in most case represented by (string: token_key, string: location, int: state), example of such database schema can be found here:&lt;br /&gt;
[https://github.com/elaskavaia/bga-sharedcode/blob/master/dbmodel.sql dbmodel.sql] and class implementing access to it here [https://github.com/elaskavaia/bga-sharedcode/blob/master/modules/tokens.php tokens.php].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `token` (&lt;br /&gt;
  `token_key` varchar(32) NOT NULL,&lt;br /&gt;
  `token_location` varchar(32) NOT NULL,&lt;br /&gt;
  `token_state` int(10),&lt;br /&gt;
  PRIMARY KEY (`token_key`)&lt;br /&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See [[Game database model: dbmodel.sql]] for details about editing the file.&lt;br /&gt;
&lt;br /&gt;
Note: the simpler the database is the less debugging of db issues you have to deal with including database migration. The tokens database above - if you use it you never have to worry about migration because you don&#039;t need extra tables in 95% of the games.&lt;br /&gt;
Here are some example of how real games are mapped to such database:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chess&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
- chess is grid base game and normally you would use positional columns, but just for the sake of argument, the chess game will look like this&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_white&lt;br /&gt;
|f3&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|P_black_2&lt;br /&gt;
|c6&lt;br /&gt;
|0&lt;br /&gt;
|-&lt;br /&gt;
|K_black&lt;br /&gt;
|e8&lt;br /&gt;
|1&lt;br /&gt;
|}&lt;br /&gt;
And the state in this case indicated that kind was moved for example (which means castling cannot be performed)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Classic card game&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Lets pretend we need 2 decks for that game&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|Q_spades_1&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_2&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|2 /* position */&lt;br /&gt;
|-&lt;br /&gt;
|10_hearts_1&lt;br /&gt;
|tableau_common&lt;br /&gt;
|1 /* face down */&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Eminent Domain (card game)&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+token&lt;br /&gt;
! token_key&lt;br /&gt;
! token_location&lt;br /&gt;
! token_state&lt;br /&gt;
|-&lt;br /&gt;
|card_tech_23&lt;br /&gt;
|hand_ff0000&lt;br /&gt;
|0 /* state not used for hand */&lt;br /&gt;
|-&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|1 /* face up */&lt;br /&gt;
|-&lt;br /&gt;
|reource_s_22 /* silicon */&lt;br /&gt;
|card_planet_19&lt;br /&gt;
|2 /*  production state */&lt;br /&gt;
|-&lt;br /&gt;
|fighter_F_1&lt;br /&gt;
|tableau_ff0000&lt;br /&gt;
|0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also look at other games that use Tokens database and access layer: Nippon, Dungeon Petz, Lewis &amp;amp; Clark, Battleship, Russian Railroads, Khronos&lt;br /&gt;
&lt;br /&gt;
== Implement Game Setup ==&lt;br /&gt;
&lt;br /&gt;
Once you have your database schema you can do a proper game setup. Usually you open rulebook on the &amp;quot;Game Setup&amp;quot; page&lt;br /&gt;
and implement these step by step populating the database (using db access API).&lt;br /&gt;
Game initialization is performed in php method setupNewGame, this method is called once when game table is created.&lt;br /&gt;
Game notifications cannot be sent during this time.&lt;br /&gt;
&lt;br /&gt;
== Implement One time game model synchronisation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now at any point in the game we need to make sure that database information can be reflected back in UI, so we fix getAllDatas function&lt;br /&gt;
to return all possible data we need to reconstruct the game. The template for getAllDatas already taking care of player info, but you &lt;br /&gt;
have to alter it to return all other data from database visible to the &amp;quot;current&amp;quot; player.&lt;br /&gt;
&lt;br /&gt;
After that on the client side we should display this data, so in your .js file in setup function (which is the receiver of getAllDatas) you add calls that handle data send by server, usually by calling animation function such as &amp;quot;placeToken&amp;quot; or &amp;quot;placeCard&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Create State Machine ==&lt;br /&gt;
&lt;br /&gt;
Now you need to create a game state machine. &lt;br /&gt;
&lt;br /&gt;
The state handling spread across 4 files, so you have to make sure all the pieces are connected together.&lt;br /&gt;
The state machine states.inc.php defines all the states, and function handlers on php side in a form of string,&lt;br /&gt;
and if any of these functions are not implemented it would be very hard to debug because it will break in random places.&lt;br /&gt;
&lt;br /&gt;
Please first watch this again [http://www.slideshare.net/boardgamearena/bga-studio-focus-on-bga-game-state-machine  BGA game state machine]&lt;br /&gt;
and then please read [[Your game state machine: states.inc.php]].&lt;br /&gt;
&lt;br /&gt;
Now the state machine should be relatively simple. If you find yourself with machine with more than 20 states its probably not the way to go.&lt;br /&gt;
Not all the player interactions need separate states, a lot of things can be implemented directly on client, i.e. if your player need to select&lt;br /&gt;
a reward token, which offers choice of resource, instead of two states on server just have one state on server and possible few states on client (client side states)&lt;br /&gt;
to collect this info.&lt;br /&gt;
&lt;br /&gt;
== Handle Turn Order ==&lt;br /&gt;
&lt;br /&gt;
If your game goes in clockwise order in natural sitting position nothing really needed you just use standard API and you are good. However if position is complecated&lt;br /&gt;
it may require some trickery.&lt;br /&gt;
&lt;br /&gt;
Usually turn order is done by &amp;quot;game state&amp;quot; (see state machine above). Basically it would be two choices:&lt;br /&gt;
* Turn order depends on game situation (such as we take player with highest number of red cubes)&lt;br /&gt;
* Turn order is custom and assign on previos step - i.e. we not playing in clockwise order anymore. In this case you either need to extend player table with new order info (CANNOT use player_no column) or use order markers that come with game (i.e. marker_ff0000 on position_1). In this we can build player array in right order and pick next player based on previous player using existing helper function such as $this-&amp;gt;createNextPlayerTable($player_ids)&lt;br /&gt;
&lt;br /&gt;
== Implement Notification handling ==&lt;br /&gt;
&lt;br /&gt;
Now to implement things for real we have hook UI actions to ajax calls, and process notifications send by server.&lt;br /&gt;
So previously we hooked onclick js handler right to client animation, in real game its a two&lt;br /&gt;
step operation. When user clicks on something, client sends an ajax call to server, server processes it and updates database, server sends&lt;br /&gt;
notification in response, client hooks animations to server notification. See [[Game_interface_logic:_yourgamename.js#Notifications|JS Notifications]].&lt;br /&gt;
&lt;br /&gt;
Exception to this is client states, if you need to process two step user interaction such as select meeple, place meeple, you may want &lt;br /&gt;
to avoid sending data to server until step is complete (which may involve direct client side animation). See [[BGA_Studio_Cookbook#Multi_Step_Interactions:_Select_Worker.2FPlace_Worker_-_Using_Selection|Multi-Step Interactions]]&lt;br /&gt;
&lt;br /&gt;
Part of the sending notifications would be to update player&#039;s scoring, BGA uses standard control for score (on JS side), see [[Game_interface_logic:_yourgamename.js#Update_players_score|Update Player&#039;s Score]].&lt;br /&gt;
&lt;br /&gt;
In BGA there is only two ways interact with the server (officially)&lt;br /&gt;
* Initial data dump - when JS client starts it gets all current data via setup() method&lt;br /&gt;
* Game actions - ajaxcall from client, it returns error or ok (not data), then server send butch of notifications to client&lt;br /&gt;
&lt;br /&gt;
Note current ajaxcall is super vebosy and prone to errors, I suggest to use helper function. It does a lot of stuff you must do anyways.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
			ajaxcallwrapper: function(action, args, handler) {&lt;br /&gt;
				if (!args) args = []; // this allows to skip args parameter for action which do not require them&lt;br /&gt;
				&lt;br /&gt;
				args.lock = true; // this allows to avoid rapid action clicking which can cause race condition on server&lt;br /&gt;
&lt;br /&gt;
				if (this.checkAction(action)) { // this does all the proper check that player is active and action is declared&lt;br /&gt;
					this.ajaxcall(&amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + this.game_name + &amp;quot;/&amp;quot; + action + &amp;quot;.html&amp;quot;, args, // this is mandatory fluff &lt;br /&gt;
						this, (result) =&amp;gt; { },  // success result handler is empty - it is never needed&lt;br /&gt;
                                                handler); // this is real result handler - it called both on success and error, its is optional param - you rarely need it&lt;br /&gt;
				}&lt;br /&gt;
			},&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you insert a single action you have to update multiples files:&lt;br /&gt;
* in ggg.js add ajaxcall, i.e. something like &lt;br /&gt;
  this.addActionButton(&#039;pass&#039;,_(&#039;Pass&#039;),()=&amp;gt;this.ajaxcallwrapper(&#039;pass&#039;));&lt;br /&gt;
* in states.php - add action &#039;pass&#039; to list of possible actions&lt;br /&gt;
  &#039;possibleactions&#039; =&amp;gt; [&#039;pass&#039;,&#039;playCard&#039;]&lt;br /&gt;
* in action.php - add action hander, see https://en.doc.boardgamearena.com/Players_actions:_yourgamename.action.php&lt;br /&gt;
* in game.php - add action hander, there you must do the following&lt;br /&gt;
** call checkAction to validate the action&lt;br /&gt;
** possible do more game specific check to validate what player doing is legal (even its not possible from your js side - player can cheat - not allow that)&lt;br /&gt;
** do some database maniplations, using access api&lt;br /&gt;
** send notifications - this is the &amp;quot;reply&amp;quot; for action&lt;br /&gt;
** transition to new state (it very rare that  user will remain in the same state, except for multi-active states)&lt;br /&gt;
* back to ggg.js add notification subsciption and notification handler (two separate things)&lt;br /&gt;
&lt;br /&gt;
== Wrap Up ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Implement game progression (getGameProgression() in php)&lt;br /&gt;
* Implement Zombie turn  (zombieTurn() in php)&lt;br /&gt;
* Define and implemented some meaningful statistics for your game (i.e. total points, point from source A, B, C...)&lt;br /&gt;
* The games logs should explain what happened if player was not looking&lt;br /&gt;
* You need to implemented tiebreaking (using aux score field) and updated tiebreaker description in meta-data&lt;br /&gt;
* Make sure all UI strings are marked for translation&lt;br /&gt;
* UI elements which are images (i.e. tokens, cards) should have tooltips&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Alpha ==&lt;br /&gt;
When you think you game is completely working there is still bunch of stuff you have to do/check before telling admin that game is ready, please go though this [[Pre-release checklist]].&lt;br /&gt;
&lt;br /&gt;
If you think its completely ready, let admin know (studio@boardgamearena.com) and it they will push it to alpha.&lt;br /&gt;
&lt;br /&gt;
Finally, visit the game page for your alpha game (https://boardgamearena.com/gamepanel?game=…) to add the following information if you can:&lt;br /&gt;
* Links to the rules (in multiple languages if available).&lt;br /&gt;
* Links to teaching videos.&lt;br /&gt;
* In the &amp;quot;On the web&amp;quot; section, links to:&lt;br /&gt;
** The official website for the game (if there is one).&lt;br /&gt;
** The BoardGameGeek page for the game.&lt;br /&gt;
* Consider writing a summary of the rules.&lt;br /&gt;
&lt;br /&gt;
== Level Up ==&lt;br /&gt;
&lt;br /&gt;
When you successfully created a basic game and you want more, its time to make it fancy!&lt;br /&gt;
&lt;br /&gt;
* Add game externtions and variants using gameoptions file&lt;br /&gt;
* Add user preferences for customizations&lt;br /&gt;
* Use theming! That involves replacing hardwood background, changing tooltips, using different sounds, different fonts, changing state prompt and logs&lt;br /&gt;
* You can use fancy scoring board at the end of game instead of default nothing&lt;br /&gt;
* And finally super cool dice rolling, card flipping and victory points evaporating effects&lt;/div&gt;</summary>
		<author><name>Grandepezzin</name></author>
	</entry>
</feed>