<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Building Browsergames &#187; code</title>
	<atom:link href="http://buildingbrowsergames.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://buildingbrowsergames.com</link>
	<description>Ever wanted to build a browsergame?</description>
	<lastBuildDate>Mon, 29 Mar 2010 14:00:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>So long, and thanks for all the fish</title>
		<link>http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/</link>
		<comments>http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 14:00:39 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/</guid>
		<description><![CDATA[This post is very difficult to write.
When I started Building Browsergames back up again, I had big plans &#8211; a new design, a cleaner interface, more guest writers. Unfortunately, things didn&#8217;t go quite as I planned &#8211; and that&#8217;s why I&#8217;m writing this today.
Building Browsergames is shutting down. Forcing myself to find more writers and [...]]]></description>
			<content:encoded><![CDATA[<p>This post is very difficult to write.</p>
<p>When I started Building Browsergames back up again, I had big plans &#8211; a new design, a cleaner interface, more guest writers. Unfortunately, things didn&#8217;t go quite as I planned &#8211; and that&#8217;s why I&#8217;m writing this today.</p>
<p><strong>Building Browsergames is shutting down.</strong> Forcing myself to find more writers and games to review and tutorials has had a detrimental effect on quality of the content here &#8211; and when you&#8217;re teaching someone, you need to know what you&#8217;re teaching very well.</p>
<p>By continually trying to post tutorials and reviews under a time constraint, I&#8217;ve done a disservice both to myself, and to the browsergame community. Corners would get cut because the tutorial needed to be up in time, and questions would go unanswered.</p>
<p>I also have my own projects to consider. Faction Wars, while currently in the alpha stages, is doing very well &#8211; and there are a number of other projects that are getting close to that stage themselves. Writing something for Building Browsergames once or twice a week has proven to be too much of a distraction for me to be able to get as much done as I&#8217;d like to on my own projects.</p>
<p>What does this mean for you, the reader? Well, it means a few things:</p>
<ul>
<li>
<h3>Fewer Updates</h3>
<p>I won&#8217;t be writing much anymore. And while I&#8217;d like to publish guest posts from other developers and enthusiasts, no one actually seems interested &#8211; and anyone who does quickly changes their mind. With that in mind, it&#8217;s fairly safe to assume that Building Browsergames will not be updating very often in the near future.</p>
</li>
<li>
<h3>The tutorials stay</h3>
<p>I&#8217;m proud of what was built using the tutorials &#8211; and it even spawned <a href="http://icequest.sourceforge.net/portal/doku.php">an open-source project</a> based on the code. While the code might not be the best I&#8217;ve written, I&#8217;m glad that it&#8217;s helped visitors who wanted to learn to make their own games to get started.</p>
</li>
</ul>
<p>Essentially, Building Browsergames takes up too much of my time for me to be able to afford to keep it running at the level that I have without making some sort of income from it &#8211; and I don&#8217;t want to just plaster the site with ads and let the networks go to town. I don&#8217;t really want to do that to any of you &#8211; so for now, Building Browsergames has to go on a hiatus.</p>
<p>Thanks again to everyone who personally got in touch with me &#8211; there&#8217;s a good community here, and with a little bit of nurturing I think it can go on to achieve great things.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/03/29/so-long-and-thanks-for-all-the-fish/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Thursday Press Release: Fanta Trade</title>
		<link>http://buildingbrowsergames.com/2010/02/04/thursday-press-release-fanta-trade/</link>
		<comments>http://buildingbrowsergames.com/2010/02/04/thursday-press-release-fanta-trade/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 14:00:43 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[fanta-trade]]></category>
		<category><![CDATA[press-release]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/02/05/thursday-press-release-fanta-trade/</guid>
		<description><![CDATA[Hey, game creators &#8211; Building Browsergames is starting a new initiative called &#8220;Press Release Thursdays&#8221; &#8211; if you&#8217;ve got a new game that&#8217;s just getting out there, send us your press release and we&#8217;ll publish it!
To start things off, I have a release from Fanta-Trade, a stock market simulation game:


Fanta Trade is a browsergame where [...]]]></description>
			<content:encoded><![CDATA[<p>Hey, game creators &#8211; Building Browsergames is starting a new initiative called &#8220;Press Release Thursdays&#8221; &#8211; if you&#8217;ve got a new game that&#8217;s just getting out there, send us your press release and we&#8217;ll publish it!</p>
<p>To start things off, I have a release from <a href='http://fanta-trade.eu/index.php'>Fanta-Trade</a>, a stock market simulation game:</p>
<p></p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/fanta-trade/image001.jpg' width='445px' /></p>
<p>Fanta Trade is a browsergame where users are given <strong>100,000 (fanta) euros to invest</strong> when they sign up &#8211; in stocks, commodities, currencies, warrants &#8211; almost everything you can imagine. One of the nice things about Fanta Trade is that stock names and prices are <strong>real</strong> &#8211; so you can become a successful stock trader (or lose it all) without taking any risks in real life. You can also find some elements typical to most browsergames within Fanta Trade: teams, rankings, and a forum in which the best players can be found providing their own take on the market.</p>
<p>Fanta-Trade is a good game for anyone who has an interest in learning how the world of finance works &#8211; or for anyone who wants to face a different kind of competition than &#8220;send your soldiers to the enemy&#8217;s village&#8221;.</p>
<p>Fanta-Trade&#8217;s sophisticated simulation engine works well, and has succeeded in transforming something as complicated as investing in the stock market into something easy and enjoyable for all &#8211; especially those who don&#8217;t know how the market works. And if you get stuck, the vibrant community is always providing tips for the game &#8211; all users can open their own financial blog and start writing their own market analyses, so you can even start dispensing your own advice if you so choose.</p>
<p>Fanta-Trade was created in Italy, so most of the players are Italian &#8211; but it has also been translated into English. You can check it out at <a href='http://fanta-trade.eu'>http://fanta-trade.eu</a>.</p>
<p></p>
<p>Do <strong>you</strong> have a press release that you&#8217;d like us to publish? Get in touch by e-mailing <a href='mailto:buildingbrowsergames@gmail.com'>buildingbrowsergames@gmail.com</a>, leaving a comment below, or <a href='http://twitter.com/bbrowsergames/'>following us on Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/02/04/thursday-press-release-fanta-trade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop Using MD5</title>
		<link>http://buildingbrowsergames.com/2009/04/14/stop-using-md5/</link>
		<comments>http://buildingbrowsergames.com/2009/04/14/stop-using-md5/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 14:00:37 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[hashing]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=812</guid>
		<description><![CDATA[I recently got a comment on the tutorial entry about securing our hashes that felt like it should be turned into it&#8217;s own warning, passed on to all readers. Unfortunately, the poster didn&#8217;t give me any information, so I can&#8217;t credit them &#8211; but here&#8217;s what they said about why you shouldn&#8217;t be using MD5:

You [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got a comment on the tutorial entry about <a href='http://buildingbrowsergames.com/2008/07/15/securing-our-hashes-php/'>securing our hashes</a> that felt like it should be turned into it&#8217;s own warning, passed on to all readers. Unfortunately, the poster didn&#8217;t give me any information, so I can&#8217;t credit them &#8211; but here&#8217;s what they said about why you shouldn&#8217;t be using MD5:</p>
<blockquote><p>
You know, it&#8217;s really frustrating seeing people trying to pass off obscurity for security.  It doesn&#8217;t work.  It never has.  Don&#8217;t do it.  Don&#8217;t promote it.  Because, when you do, it damages security overall.</p>
<p>MD5 has been known to be useless as a security measure for well over a decade.  Why people keep using it I will never know.  Especially, when the SHA family is *vastly* more secure and available in all languages.  Here&#8217;s the PHP page for hash():</p>
<p>http://ca3.php.net/manual/en/function.hash.php</p>
<p>Just use SHA256/512 and be happy until the winner of the NIST contest is found.  Then use that.</p>
<p>At any rate, your &#8217;salt&#8217; completely misses the point of MD5&#8217;s weakness (btw, that&#8217;s security through obscurity which is completely useless).  As in, if they have access to your DB, then chances are that they have (or could have) access to your source as well.  Also, I could generate a collision to that password in well under a minute:</p>
<p>http://eprint.iacr.org/2006/105</p>
<p>So, I might not have the actual password.  But, I&#8217;ll certainly have *a* password that will generate the same hash.  If it doesn&#8217;t work, then I look at the source and find the obscuring factor, make a minor adjustment to my collision finding code and rerun.  In seconds I&#8217;ll start getting positive results.  Yes, it *is* that easy.</p>
<p>If you want to migrate people over to the new hash, then just create a new column in the DB which will hold it and set it to null.  Then on login, if this value is null redirect them to a change your password page.  *Require it*.  Then after some months, drop the MD5 column, clean up the logic and have the remain inactive users use the forgot your password feature if they want to play again.</p>
<p>That might sound like a lot of work, but it really isn&#8217;t.  Especially, when considering it&#8217;s the programmers fault for screwing up the security in the first place.
</p></blockquote>
<p>There are some good points made here &#8211; so if you&#8217;re using MD5 in your game for your hashes, you may want to look into updating your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2009/04/14/stop-using-md5/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Plant Wars: Postmortem</title>
		<link>http://buildingbrowsergames.com/2009/03/20/plant-wars-postmortem/</link>
		<comments>http://buildingbrowsergames.com/2009/03/20/plant-wars-postmortem/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 14:00:05 +0000</pubDate>
		<dc:creator>plantwars</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[monetization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[postmortem]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=795</guid>
		<description><![CDATA[This is Jon from Plant Wars, which is yet another PBBG (what else would I be doing here?). I started the game around 9 months ago as I was searching for a job after graduating with a bachelor&#8217;s in Computer Science. I had only learned a minimal amount of PHP for a class project earlier [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 273px"><img title="Plant Wars Logo" src="http://www.plantwars.com/images/logomedium.jpg" alt="Plant Wars Logo" width="263" height="332" /><p class="wp-caption-text">Plant Wars Logo</p></div>
<p>This is Jon from <a href="http://www.plantwars.com" target="_blank">Plant Wars</a>, which is yet another PBBG (what else would I be doing here?). I started the game around 9 months ago as I was searching for a job after graduating with a bachelor&#8217;s in Computer Science. I had only learned a minimal amount of PHP for a class project earlier in the year, so I definitely have used the process as a learning experience. Still, I&#8217;m pretty sure I can tell you more about what <strong>not</strong> to do than what <strong>to</strong> do. As with any web-based game, we are constantly developing and are far from being done.</p>
<p>First of all, set up a test site with its own test database. Keep it up to date so that you&#8217;re not tempted to cheat and just make this tiny change on the live site first. I cheated when I implemented the password change feature. The query it used when someone changed his password was &#8220;UPDATE Users SET Password=md5($newpassword)&#8221;. Notice something missing? That &#8220;WHERE Id=$_SESSION["Id"]&#8221; clause is just so easy to forget. That was a mess that would have been worth any level of inconvenience in maintaining the test site to avoid.</p>
<p>Secondly, I&#8217;d recommend using a framework, such as the <a href="http://framework.zend.com/" target="_blank">Zend Framework</a> for PHP. This is because I didn&#8217;t and still don&#8217;t. I don&#8217;t even have data access objects. Sure, I store some commonly used methods in files that I include on every page. Alas, I&#8217;m still in the habit of embedding queries in the pages directly. Separation of logic and presentation? Yeah, that&#8217;d be nice.. At my day job, I use the <a href="http://struts.apache.org/">Struts framework</a> with Java &#8211; and while it does make the initial development take somewhat longer in the case of Struts, it is definitely worth it. The maintainability is increased incredibly by the proper separation of concerns. Once you learn a framework, you should generally find that your productivity increases. The initial learning curve is worth the sacrifice at the beginning for the long term benefit.</p>
<p>Perhaps the most important thing I did right was to have my friend Daniel help me out whenever possible. Going at such an endless project alone is intimidating, and having someone else to shoulder some of the burden is essential. Coming home and seeing a new feature implemented that you didn&#8217;t have to lift a finger for is exhilarating. Plus, then you have someone to brainstorm with and to just talk with about the game. Your girlfriend (or mom, if that&#8217;s the case) may pretend to care, but she&#8217;s probably tired of hearing about it.</p>
<p>In the same vein, it&#8217;s essential to have some trustworthy staff members. Grant these people moderation powers on your game&#8217;s forum and give them the ability to check the logs for cheaters. Write a nice administration panel for them (and yourself) that will streamline the process of checking for cheaters. For example, one button click to see all users who have shared an IP address. Examining log files may be your thing, but it&#8217;s time that you should be spending developing. Ensure that your staff is &#8211; once again for emphasis &#8211; trustworthy, as well as good role models for your community.</p>
<p>If you have staff that you don&#8217;t know personally help on the site&#8217;s development, don&#8217;t give them access to the live database. Restrict them to the test site &#8211; another good reason for its existence. Merge their code yourself. I made the mistake of granting access to the live database to my first staff member. I got off easy when he just made a page to bump his stats up artificially.</p>
<p>My final recommendation is regarding monetization: if you would like to at least make enough cash to pay for your hosting costs (which we usually manage &#8211; if barely), ensure that people can donate for some advantage in your game. For example, with <a href="http://www.plantwars.com" target="_blank">Plant Wars</a>, donors gain fertilizer (which is spent to train, fight, etc) at twice the rate of non-donors. I charge a low price of $2/month, and I&#8217;m not sure if I would recommend going that low. My initial price was $5 and that received lots of complaints and no donors, but now that the game has progressed, I&#8217;m more inclined to believe that anyone who donates currently would be inclined to do so even if it were a couple bucks more expensive. Use your best judgment. Also, I allow anything that can be bought with real money to be sold player-to-player so that a) there is more motivation for people to give me real money and b) people who can&#8217;t give real money still have the opportunity to gain the same benefits with increased activity.</p>
<p>People hate clicking on ads. It is worth the minimal time investment necessary to sign up with some sort of pay-per-action network, such as <a href="http://www.cpalead.com/apply.php?ref=7364" target="_blank">CPALead</a> (disclosure: referral link). This allows players to fill out an obnoxious survey for an in-game reward, while you get some money.</p>
<p>Come check out the <a href="http://blog.plantwars.com" target="_blank">Plant Wars blog</a> and you can also <a href="http://twitter.com/plantwars" target="_blank">follow us on Twitter</a>! (As a related, post-final recommendation, open up communications from your game as much as possible. It increases the likelihood that someone will find you from a social networking site or a search engine.)</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2009/03/20/plant-wars-postmortem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Save bandwidth while improving performance!</title>
		<link>http://buildingbrowsergames.com/2009/02/13/save-bandwidth-while-improving-performance/</link>
		<comments>http://buildingbrowsergames.com/2009/02/13/save-bandwidth-while-improving-performance/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 14:00:32 +0000</pubDate>
		<dc:creator>donbonifacio</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=737</guid>
		<description><![CDATA[Bandwidth can be very troublesome, especially if you&#8217;re at a limited hosting solution, with only a small amount of gigabytes to serve per month. If your site uses a substantial quantity of images and scripts, you may find yourself having a big problem.
Lets imagine that a new user goes to your site and he/she will [...]]]></description>
			<content:encoded><![CDATA[<p>Bandwidth can be very troublesome, especially if you&#8217;re at a limited hosting solution, with only a small amount of gigabytes to serve per month. If your site uses a substantial quantity of images and scripts, you may find yourself having a big problem.</p>
<p>Lets imagine that a new user goes to your site and he/she will need to download 100kb of scripts and images, plus the XHTML page. If you have 50.000 requests, you&#8217;ll serve a significant quantity of bandwidth. And you may even serve static content to old users if you don&#8217;t configure correctly your static content headers.</p>
<h3>Step 1 &#8211; Decouple the static content from the dynamic content</h3>
<p>First you need to prepare your game to be able to get your images/scripts from anywhere. Instead of linking like:</p>
<pre>&lt;img src="/Images/Sample.png" /&gt;</pre>
<p>You need to code your application to link like:</p>
<pre>&lt;img src="http://some_host/Images/Sample.png" /&gt;</pre>
<p>And have the <strong>http://some_host</strong> easily configurable somewhere. That way you&#8217;ll be able to change the location of your static content and make use of <em>content distribution networks</em>. This can be a complex task if you leave it to the end, so you should start as soon as possible using this strategy. Note that this way you may still use your main server URL for static content.</p>
<h3>Step 2 &#8211; Use a Content Distribution Network</h3>
<p>Now that you have a configurable static content location, you have several options to consider. For example, if your game is open source, you may create an account at <a href="http://sf.net">SourceForge.net</a> and then you&#8217;ll have your own web space to use. You could then configure your game to use as a location for static content something like:</p>
<pre>http://your_game_name.sourceforge.net</pre>
<p>And that&#8217;s it! You&#8217;d save a lot of bandwidth and server load just by changing some configuration. But having an open source game isn&#8217;t always an option. Fortunately, there&#8217;s a free content distribution network named <a href="http://www.coralcdn.org/">Coral CDN</a> that is very easy to use. Imagine that your game is at the <em>http://your_game_name.com</em> url and that you configured your static content location to <strong>http://your_game_name.com</strong>. To use Coral CDN you&#8217;d have just to change the static location to:</p>
<pre>http://your_game_name.com.nyud.net</pre>
<p>Appending the <em>&#8220;.nyud.net&#8221;</em> will make Coral to automatically act as a proxy to your content and cache it. For example, you can try it at this site: <a href="http://buildingbrowsergames.com.nyud.net/">buildingbrowsergames.com.nyud.net</a>.</p>
<p>There are other CDN solutions out there, some will cost more money and will be better. A great advantage of CDNs is that they have servers all over the world and will sync your data all over them. So, if your server is in England but you have a user from Japan, the CDN will serve the static content from the nearest server, and your user won&#8217;t need to fetch content from the other part of the world.</p>
<h3>Step 3 &#8211; Configure Static Content Headers</h3>
<p>So, by now you don&#8217;t have to worry about bandwidth, because you&#8217;ll have a third party serving it for you. But there&#8217;s something more you can do to improve user experience. When a browser requests content it may cache it according to the server configuration. But if you don&#8217;t configure the server properly, the browser may ask for the same static file over and over again.</p>
<p>This won&#8217;t be costly for you, but for the user experience. If a user makes a request to your game and the browser has everything cached, the request will be almost instantaneous! However, if the browser needs to refresh data, it may ask for the static content again, and that may implicate that your user will have to wait a second and see loading images.</p>
<h3>Resources</h3>
<p>This article is just an introduction to make you aware of static content problems and how to solve them. To learn more about client side performance, you can study the <a href="http://developer.yahoo.com/performance/rules.html">Yahoo&#8217;s Best Practices for Speeding Up Your Web Site</a>. They have a lot of useful tips, and if you use Firefox, you may install <a href="http://developer.yahoo.com/yslow/">YSlow</a>, an extension that will rate your site in terms of client side performance.</p>
<p>Another great tool to use is something like <a href="http://www.fiddlertool.com/fiddler/">Fiddler</a>, that allows you to see all requests made by the browser, headers, and so on. By using it you&#8217;ll see where you can improve.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2009/02/13/save-bandwidth-while-improving-performance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making your game more accessible</title>
		<link>http://buildingbrowsergames.com/2009/02/05/making-your-game-more-accessible/</link>
		<comments>http://buildingbrowsergames.com/2009/02/05/making-your-game-more-accessible/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 14:00:27 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[accessibility]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=719</guid>
		<description><![CDATA[Recently, we talked about keeping your game accessible for those with disabilities. A few of the changes that we mentioned making to your game are fairly easy changes to make, but a few require some custom Javascript to implement. Today, we&#8217;ll be working through two simple tweaks you can make to improve the accessibility of [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, we talked about <a href='http://buildingbrowsergames.com/2009/02/02/keep-your-game-accessible/'>keeping your game accessible</a> for those with disabilities. A few of the changes that we mentioned making to your game are fairly easy changes to make, but a few require some custom Javascript to implement. Today, we&#8217;ll be working through two simple tweaks you can make to improve the accessibility of your pages: changing the text size, and changing the color scheme.</p>
<p>We will be using the <a href='http://jquery.com/'>jQuery</a> javascript library to accomplish both of these effects, along with some custom CSS.</p>
<p>First off, let&#8217;s say that the stylesheet for your page looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">75</span>%</span> verdana<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #993333;">white</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>If you want to add some alternate color schemes to your page, you could add them in your CSS like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">body<span style="color: #6666ff;">.default</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #993333;">white</span><span style="color: #00AA00;">&#125;</span>
body<span style="color: #6666ff;">.red</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #993333;">green</span><span style="color: #00AA00;">&#125;</span>
body<span style="color: #6666ff;">.blue</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #993333;">white</span><span style="color: #00AA00;">&#125;</span>
body<span style="color: #6666ff;">.green</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">green</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>By setting up our CSS in this way, it is easy for your designer to make color scheme changes to the entire page whenever we modify the body&#8217;s class, simple by writing their CSS based on which class the body has:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body<span style="color: #6666ff;">.red</span> p<span style="color: #6666ff;">.warning</span> <span style="color: #00AA00;">&#123;</span><span style="color: #808080; font-style: italic;">/* this would only be applied under the 'red on green' color scheme*/</span><span style="color: #00AA00;">&#125;</span>
body<span style="color: #6666ff;">.green</span> p<span style="color: #6666ff;">.warning</span> <span style="color: #00AA00;">&#123;</span><span style="color: #808080; font-style: italic;">/* this would only be applied under the 'green on black' color scheme*/</span><span style="color: #00AA00;">&#125;</span>
p<span style="color: #6666ff;">.warning</span> <span style="color: #00AA00;">&#123;</span><span style="color: #808080; font-style: italic;">/* this would be applied regardless of color scheme */</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>We will be using jQuery to dynamically add these classes to our document as necessary. We&#8217;ll start off with a basic HTML document &#8211; I&#8217;ve inlined the CSS so that you can see it all in one place; in a production environment you should make sure to keep your stylesheets separate.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span>
<span style="color: #00bbdd;">	&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #000066;">xml:lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jQuery accessibility demo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		body {font: 75% verdana, sans-serif;color:black;background:white}
	    body.default {color:black;background:white}
		body.red {color:red;background:green}
		body.blue {color:blue;background:white}
		body.green {color:green;background:black}
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>This is our page, with some filler content.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'body_colors'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'default'</span> <span style="color: #000066;">selected</span>=<span style="color: #ff0000;">'selected'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>default (black on white)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'red'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>red (red on green)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'blue'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>blue (blue on white)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'green'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>green (green on black)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>With our document set up, we&#8217;ll add the Javascript code to toggle our body&#8217;s class for us:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
$(document).ready(function() {
    $('#body_colors').change(function() {
        $('body').attr('class',$(this).val());
    })
})
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>If you&#8217;re new to jQuery, that will probably look like voodoo to you &#8211; but it&#8217;s actually a fairly simple piece of code. We&#8217;re selecting the element on the page with the ID #body_colors(just like you would with CSS &#8211; in this case it&#8217;s a &lt;select&gt; element), and then attaching an event handler to its <em>onchange</em> function &#8211; every time that the value of the &lt;select&gt; changes, our event handler fires. All it does is find our &lt;body&gt; tag, and then set it&#8217;s class to the class that the user just selected.</p>
<p>If you open up our tester page in your browser, you should be able to see that when you select something from the dropdown, the style of the page changes &#8211; which is exactly what we were going for. You can also see it in action at <a href='http://buildingbrowsergames.com/demos/accessibility-1.html'>http://buildingbrowsergames.com/demos/accessibility-1.html</a>.</p>
<p>Modifying the text size is a bit of an interesting change, as it will require you (possibly) to modify the way that you write your CSS. When we first defined the styles for our body, you&#8217;ll notice that we added the &#8216;font&#8217; declaration, with the size of &#8216;75%&#8217;. What this has effectively done is made it so that the baseline size for all the text on the page is 12 pixels. By putting this declaration onto our body element, we can now use ems to size our text; if you wanted to make some text that was 12 pixels, you would give it a font-size of <em>1em</em> &#8211; for 24 pixels, you would use <em>2em</em>, and so on.</p>
<p>Now, at first blush you may be saying &#8220;this is kind of cool, but&#8230;why would I ever use it?&#8221;. The reason for this is simple: <strong>it makes writing our javascript much easier</strong>. Let&#8217;s add some stuff to our HTML page:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    Change font size:
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'text_size'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'50%'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>smaller (8px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'75%'</span> <span style="color: #000066;">selected</span>=<span style="color: #ff0000;">'selected'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>default (12px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'100%'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>big (16px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'125%'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>bigger (20px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>With our font-size dropdown added, we will be writing a little bit more javascript:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>42
43
44
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#text_size'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'font-size'</span><span style="color: #339933;">,</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>This piece of jQuery is even simpler than the earlier one &#8211; all we do is modify the &#8216;font-size&#8217; attribute on our &lt;body&gt; tag with the value of the selected option.</p>
<p>If you take a look at your page in the browser now, you should notice that selecting different options in the dropdown also alters the text-size on your page. As long as you use em&#8217;s for all of your font-sizes in your document, that means that altering the text-size will transform the text across your <strong>entire</strong> site &#8211; making it much easier to read for users who have a hard time reading small text. If you&#8217;d like to see the entire page in action, you can take a look at <a href='http://buildingbrowsergames.com/demos/accessibility-2.html'>http://buildingbrowsergames.com/demos/accessibility-2.html</a>.</p>
<p>As you can see, making it so that users can alter the color scheme or text size of your page isn&#8217;t particularly difficult &#8211; but for users who need to be able to make those changes, it will make the difference between playing <strong>your</strong> game, and playing a different game that caters to their needs better. Here&#8217;s the entire source for our demo page:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span>
<span style="color: #00bbdd;">	&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #000066;">xml:lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jQuery accessibility demo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		body {font: 75% verdana, sans-serif;color:black;background:white}
	    body.default {color:black;background:white}
		body.red {color:red;background:green}
		body.blue {color:blue;background:white}
		body.green {color:green;background:black}
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>This is our page, with some filler content.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'body_colors'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'default'</span> <span style="color: #000066;">selected</span>=<span style="color: #ff0000;">'selected'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>default (black on white)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'red'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>red (red on green)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'blue'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>blue (blue on white)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'green'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>green (green on black)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    Change font size:
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'text_size'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'50%'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>smaller (8px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'75%'</span> <span style="color: #000066;">selected</span>=<span style="color: #ff0000;">'selected'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>default (12px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'100%'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>big (16px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'125%'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>bigger (20px)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    $(document).ready(function() {
        $('#body_colors').change(function() {
            $('body').attr('class','');
            $('body').addClass($(this).val());
        })
        $('#text_size').change(function() {
            $('body').css('font-size',$(this).val());
        })
    })
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2009/02/05/making-your-game-more-accessible/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Preparing our database for multiple area support</title>
		<link>http://buildingbrowsergames.com/2009/01/12/preparing-our-database-for-multiple-area-support/</link>
		<comments>http://buildingbrowsergames.com/2009/01/12/preparing-our-database-for-multiple-area-support/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 14:00:05 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=679</guid>
		<description><![CDATA[While we&#8217;ve been building our game, we&#8217;ve been slowly adding features &#8211; piece by piece. As these features have been added, our game has sort of grown organically &#8211; but some of these features are(at least at the moment) a little half-baked.
Today, we will be altering our database by adding a few of the prerequisites [...]]]></description>
			<content:encoded><![CDATA[<p>While we&#8217;ve been building our game, we&#8217;ve been slowly adding features &#8211; piece by piece. As these features have been added, our game has sort of grown organically &#8211; but some of these features are(at least at the moment) a little half-baked.</p>
<p>Today, we will be altering our database by adding a few of the prerequisites for our combat system to be a little fuller &#8211; instead of players visiting the forest to encounter enemies, they will be able to visit any number of areas that we can define in the database. We will start by adding an <em>areas</em> table to our database, that we can use to keep track of information related to each area the player can visit:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> areas<span style="color: #66cc66;">&#40;</span>
	id int <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
	name varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>In theory, this table is all that we need to add to enable multi-area support(after changing our combat code, of course) &#8211; but we will also add a table called <em>area_monsters</em> that will allow us to control which monsters can be encountered in which area:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> area_monsters<span style="color: #66cc66;">&#40;</span>
	id int <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
	area int<span style="color: #66cc66;">,</span>
	monster int<span style="color: #66cc66;">,</span>
	<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>With this table created, we will be able to insert rows for monster + area combinations &#8211; allowing us to control which types of monsters the player will encounter in each area.</p>
<p>If you&#8217;re aware of our current database structure, you might be wondering: why didn&#8217;t we just add another stat to each of our monsters, called something like &#8220;Area Monster Is In&#8221;? The reason for that is simple: with these new tables, we will be able to retrieve which monsters are in an area using a <strong>single</strong> SQL query, that would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> monster <span style="color: #993333; font-weight: bold;">FROM</span> area_monsters <span style="color: #993333; font-weight: bold;">WHERE</span> area <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&lt;</span>area_id<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>If we were to use our stats system for this, we would need to do something much more complex &#8211; first determining which stat we should be retrieving, and then retrieving the relevant rows for every entry in the database &#8211; at which point we would need to work through our rows and determine which values we actually needed to use. Therefore, adding our <em>area_monsters</em> table will allow us to keep track of which monsters are in which areas a little easier.</p>
<p>With that being said, all of our initial preparations are finished &#8211; our next step(which will come later) is to add the code to actually interact with the tables that we have added to our database.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2009/01/12/preparing-our-database-for-multiple-area-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick &amp; Dirty Rails Scaling Tips for PBBG&#8217;s</title>
		<link>http://buildingbrowsergames.com/2009/01/02/quick-dirty-rails-scaling-tips-for-pbbgs/</link>
		<comments>http://buildingbrowsergames.com/2009/01/02/quick-dirty-rails-scaling-tips-for-pbbgs/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 14:00:00 +0000</pubDate>
		<dc:creator>bsharpe</dc:creator>
				<category><![CDATA[optimization]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[scaling]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=647</guid>
		<description><![CDATA[Rails-based PBBG's can scale to handle the load that Facebook can generate.]]></description>
			<content:encoded><![CDATA[<p>I wrote a PBBG in Rails that lives on Facebook, so I&#8217;ve had some scaling issues to deal with.   Here are some tips I collected along the way on scaling Rails.</p>
<h3>Serve statics from somewhere else</h3>
<p>In the beginning, letting your Rails setup serve everything is very easy.  But as your game grows in popularity, you&#8217;ll notice that your app spends a lot of time serving up things that never change.</p>
<p>The first thing we did was separate out all the static images onto a separate server running nginx.   Nginx is notoriously fast at serving static content and it did a good job for us.  This left our Rails instances to serve only game-related activities.</p>
<p>Another useful bit was using a plugin called <a href="http://code.google.com/p/bundle-fu/">bundle_fu</a>.  Bundle_fu takes all the javascrips and stylesheets you use in your app and creates a single file for the browser to download.   So, instead of the browser having to make 6 connections to get all those pieces, it makes 1.  This functionality is built into Rails since version 2.0.</p>
<h3>Optimize your environment</h3>
<p>Initially, we ran Apache proxying to 5 to 10 mongrel servers running Rails.  Then we switched to Nginx/mongrels which gave us a bit of speed and a bit of memory back, after doing some more searching we eventually switched entirely to the Litespeed webserver with no mongrels.  <a href="http://www.litespeedtech.com/">Litespeed</a> is an awesome product and we have had rock solid performance with it for the last year.   Although, all my latest Rails deployments have been with Apache &amp; mod_rails (Passenger) running with the <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a>.</p>
<p>One big upside to Litespeed and <a href="http://www.modrails.com/">Passenger</a> is that you don&#8217;t have to manage mongrels anymore and restarting the website is super fast.  Also, <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a> (REE) can reduce your memory requirements up to 30%.</p>
<h3>Memcached</h3>
<p>I think the biggest anecdotal speed increase we got was from integrating support for <a href="http://www.danga.com/memcached/">memcached</a>.   It was as simple as adding the acts_as_cached plugin and marking a few models to be cached.   From there, we began optimizing which models were cached for the best performance.</p>
<h3>Watch for slow queries</h3>
<p>Edit your mysql.cnf file to start logging slow queries and then watch that log like a hawk.  When you see a query that isn&#8217;t using an index, make sure you add the appropriate index to get that query to be fast again.   This won&#8217;t help much if the query only runs once a day, but if it runs every few seconds &#8212; you&#8217;ll notice the difference.</p>
<h3>Throttling the game</h3>
<p>Early on when there were only a few hundred people in our game we added a bunch of notifications to our chat system so that people would know that others were there and something was happening.    Crank that up to several thousand people and those notifications are nothing but annoying.   So, we added code that checked for the number of currently online people and throttled those informative messages when things got busy and brought them back when things calmed down again.  This made a big improvement in the quality of play during busy times.</p>
<p>These are just a few of the things we tried, but they were the most successful at improving the performance of our game.</p>
<p>If you&#8217;d like to see it, browse over to <a href="http://www.friendsandfoesstudios.com/toothandclaw">Tooth &amp; Claw</a></p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2009/01/02/quick-dirty-rails-scaling-tips-for-pbbgs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Announcing the PBBG Network!</title>
		<link>http://buildingbrowsergames.com/2008/12/15/announcing-the-pbbg-network/</link>
		<comments>http://buildingbrowsergames.com/2008/12/15/announcing-the-pbbg-network/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 14:00:18 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=612</guid>
		<description><![CDATA[If you&#8217;re at all interested in developing browsergames, you may have noticed that the number of websites relaetd to the topic is sort of&#8230;small.
Now, that&#8217;s not to say that none of them are good or anything &#8211; just that the selection is limited. And with a number of sites vying to be the be-all-and-end-all with [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re at all interested in developing browsergames, you may have noticed that the number of websites relaetd to the topic is sort of&#8230;small.</p>
<p>Now, that&#8217;s not to say that none of them are good or anything &#8211; just that the selection is limited. And with a number of sites vying to be the be-all-and-end-all with forums, blogs, contests, and other features, it&#8217;s hard to decide: which site(s) should you follow?</p>
<p>With that in mind, I am proud to announce that Buillding Browsergames, <a href='http://bbgamezone.com'>Browser-Based Game Zone</a>, and <a href='http://bbguniverse.com'>BBG Universe</a> have united to form <a href='http://pbbgnetwork.com'>The PBBG Network</a>. Our goal is to bring you the best in PBBG-related content, on each of our member sites. Building Browsergames will be providing the &#8216;blog&#8217; portion of the network, while Browser-Based Game Zone will provide the forums, and BBG Universe will serve as the rankings site. Hopefully, by having each site switch to focusing on one main &#8216;feature&#8217;, we can improve each of our sites &#8211; and focus more on our core competencies and less on having every feature under the sun.</p>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2008/12/15/announcing-the-pbbg-network/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Rawrmy&#8217;s Combat System Refresh</title>
		<link>http://buildingbrowsergames.com/2008/11/24/rawrmys-combat-system-refresh/</link>
		<comments>http://buildingbrowsergames.com/2008/11/24/rawrmys-combat-system-refresh/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 14:00:31 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[combat]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[diaryofabrowsergame]]></category>
		<category><![CDATA[doab]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[rawrmy]]></category>
		<category><![CDATA[refresh]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/?p=577</guid>
		<description><![CDATA[This week was spent fleshing out Rawrmy&#8217;s combat system, and building in some of the more &#8216;traditional&#8217; elements &#8211; like experience, levels, and hit points.
I&#8217;ve been struggling for the last few weeks to try and find a way to make combat &#8216;fun&#8217; &#8211; while it&#8217;s a big part of a lot of browsergames, it&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>This week was spent fleshing out Rawrmy&#8217;s combat system, and building in some of the more &#8216;traditional&#8217; elements &#8211; like experience, levels, and hit points.</p>
<p>I&#8217;ve been struggling for the last few weeks to try and find a way to make combat &#8216;fun&#8217; &#8211; while it&#8217;s a big part of a lot of browsergames, it&#8217;s a part that (I think) could use a little bit more polish in most of them. Fighting monster after monster after monster isn&#8217;t fun &#8211; it&#8217;s only a means to an end. I think that even the boring parts of the game should still be fun. With that in mind, I set out to build a combat system that would achieve two things:</p>
<ol>
<li>Be a combat system.</li>
<li>Be fun.</li>
</ol>
<p>After thinking and pondering, I believe that I&#8217;ve finally come up with a system that works(and you&#8217;ll probably be able to figure out how it works in the screenshot below).</p>
<div id="attachment_579" class="wp-caption alignnone" style="width: 310px"><a href="http://buildingbrowsergames.com/blog/wp-content/uploads/2008/11/picture-7.png"><img src="http://buildingbrowsergames.com/blog/wp-content/uploads/2008/11/picture-7-300x182.png" alt="Rawrmy\&#039;s refreshed combat system" title="Rawrmy Combat" width="300" height="182" class="size-medium wp-image-579" /></a><p class="wp-caption-text">Rawrmy's refreshed combat system</p></div>
<p>A little bit more time was also spent fleshing out the different areas of the game &#8211; and they&#8217;re what I will be working on now. I am afraid that my schedule has been getting busier and busier, lately &#8211; which means I can&#8217;t devote as much time to Rawrmy as I would like to. While I am still hoping to have something releasable by the contest due date, I don&#8217;t think it will be quite as strong an entry as I would have liked.</p>
<h2>Completed this week:</h2>
<ul>
<li>Combat system refresh &#8211; the combat system is now a little more fun to use, in addition to more challenging for players who have gotten to the higher experience levels.</li>
</ul>
<h2>Still to do:</h2>
<ul>
<li>Content needs fleshing out &#8211; while this combat switch has made Rawrmy &#8216;feature complete&#8217;, it hasn&#8217;t made it <strong>solid</strong> yet. There needs to be a lot of polishing done in regards to content, areas, and the way that in-game items work.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2008/11/24/rawrmys-combat-system-refresh/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
