<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ game - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ game - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 08 May 2026 22:32:42 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/game/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Break The Code 2.0: A Browser Game Where You Solve Missions Using Coding Skills ]]>
                </title>
                <description>
                    <![CDATA[ Break The Code 2.0 is a new browser game that sends you back in time to the year 1999. You complete codebreaking missions using your programming knowledge and your puzzle-solving intuition. The game is spread across 4 drives worth of missions: The /... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/break-the-code-2-game/</link>
                <guid isPermaLink="false">66b8d25a57c651c38343a94d</guid>
                
                    <category>
                        <![CDATA[ game ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Quincy Larson ]]>
                </dc:creator>
                <pubDate>Fri, 08 Apr 2022 03:38:54 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/os-loader--1-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Break The Code 2.0 is a new browser game that sends you back in time to the year 1999.</p>
<p>You complete codebreaking missions using your programming knowledge and your puzzle-solving intuition.</p>
<p>The game is spread across 4 drives worth of missions:</p>
<ul>
<li>The /g1/ drive – "BoxOfChocolates"</li>
<li>The /g2/ drive – "Fight Club"</li>
<li>And the /g3/ and /g4/ drives, which you can unlock by solving the first two drives</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Break_The_Code_2_by__Tech_Domains_---1.png" alt="Image" width="600" height="400" loading="lazy">
<em>The Windows 98-inspired interface of Break The Code 2.0. (And yes, in case you're wondering, Minesweeper is fully playable.)</em></p>
<p>Break The Code 2.0 is free, and you can <a target="_blank" href="https://go.tech/fcc">play right inside your browser</a> without installing anything.</p>
<p>Break The Code 2.0 was coded by a team of developers at .Tech Domains. It is a sequel to their codebreaking challenge from last year. </p>
<p>.Tech Domains have also given freeCodeCamp.org a grant for us to create a "Let's Play"-style walkthrough of the game.</p>
<p>In this walkthrough, freeCodeCamp software engineers Tom and Shaun work together to tackle some of the missions and crack some of the ciphers. (1 hour watch):</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/sWMAsRqcoWc" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>If you solve the puzzles before April 15, you may be eligible to win prizes worth up to $30,000.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Prize-Image.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>The prize catalogue. The scorpion-shaped gaming throne may clash with the other furniture in your room. But it sure looks comfy.</em></p>
<p>This is a fun way to test your codebreaking skills while competing with other developers from around the world. Jump back in time to 1999 and <a target="_blank" href="https://go.tech/fcc">take Break The Code 2.0 for a spin</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to build a matching game in your free time with Easel.js ]]>
                </title>
                <description>
                    <![CDATA[ By Yazed Jamal Part of my journey in the programming world is learning about game development. I have tried several languages such as Java and C++, but in the end I would like to go with Javascript. I have built one game before using JS. The game is ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/matching-game-with-easel-js-free-time-series-cf803c094a9f/</link>
                <guid isPermaLink="false">66c35b1f0cede4e9b1329cc5</guid>
                
                    <category>
                        <![CDATA[ game ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 03 Dec 2017 19:49:51 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*vc7x8QVmi5I9qDUcAT2zSw.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Yazed Jamal</p>
<p>Part of my journey in the programming world is learning about game development. I have tried several languages such as Java and C++, but in the end I would like to go with Javascript. I have built one game before using JS. The game is called <a target="_blank" href="http://yazedjamal.com/pongping/">Pong Ping</a>, which is the clone for the game Pong. This game was built purely using native Javascript.</p>
<p>But today I would like to build a game based on a Javascript game framework called Easel.js. The game that I am going to build is actually a very simple game: we flip squares over, and if they are the same color, they will disappear. The game will finish when every color is matched. Here’s an example of the game in the video below, but they are using pictures.</p>
<p><strong>Step 1</strong></p>
<p>I will create the index.html file and make a reference to the easel.js library. I choose to use CDN (Content Deliver Network) for this purpose. I will also need to make reference to main.js where all my Javascript code will be.</p>
<pre><code>#index.html&lt;!DOCTYPE html&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Pairing Game<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://code.createjs.com/easeljs-0.8.2.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"js/main.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">body</span> <span class="hljs-attr">onload</span>=<span class="hljs-string">"init()"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"myCanvas"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"960"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"600"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></span>
</code></pre><p>I need to make sure all the DOM elements are fully loaded before the Javascripts could be executed, so I am using the onload method to bind the Javascript through the function init().</p>
<p><strong>Step 2</strong></p>
<p>I will then create the main.js file and setup the easel.js environment.</p>
<pre><code>#js/main.jsvar squarHeight = <span class="hljs-number">200</span>;<span class="hljs-keyword">var</span> squareWidth = <span class="hljs-number">200</span>;
</code></pre><pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">init</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">var</span> stage = <span class="hljs-keyword">new</span> createjs.Stage(<span class="hljs-string">"myCanvas"</span>); <span class="hljs-keyword">var</span> square = drawSquare();
</code></pre><pre><code>stage.addChild(square); stage.update();}
</code></pre><p>Easel is using a Class called Stage as a container to display any element to the canvas defined. Now I will draw a square through the function drawSquare. I will utilize all the available APIs from easel.js</p>
<pre><code>#js/main.jsfunction drawSquare() { <span class="hljs-keyword">var</span> graphics = <span class="hljs-keyword">new</span> createjs.Graphics().setStrokeStyle(<span class="hljs-number">5</span>).beginStroke(<span class="hljs-string">"rgba(20,20,20,1)"</span>) graphics.beginFill(randomColor()).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squareWidth,squareHeight); <span class="hljs-keyword">var</span> shape = <span class="hljs-keyword">new</span> createjs.Shape(graphics); <span class="hljs-keyword">return</span> shape;}
</code></pre><pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">randomColor</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">var</span> num1 = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">255</span>); <span class="hljs-keyword">var</span> num2 = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">255</span>); <span class="hljs-keyword">var</span> num3 = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">255</span>); <span class="hljs-keyword">return</span> <span class="hljs-string">"rgba("</span>+num1+<span class="hljs-string">","</span>+num2+<span class="hljs-string">","</span>+num3+<span class="hljs-string">",1)"</span>; }
</code></pre><p>First I will define the stroke size I would like to use. Then I’ll apply the stroke with a specific color, define the color of the square, and create the square. The color of the square is a random color generated from the function randomColor. Below is how it will look in the browser.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*efa3EzNch2A0w_nCE1yrlA.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Step 3</strong></p>
<p>After I have successfully rendered a square with a random color, I need to design how many rows and columns there will be for the squares to fill in. I’ll also need to design the algorithm to render one square in each column and rows</p>
<pre><code>#js/main.js##upated codesvar squarHeight = <span class="hljs-number">200</span>;<span class="hljs-keyword">var</span> squareWidth = <span class="hljs-number">200</span>;<span class="hljs-keyword">var</span> squareGap = <span class="hljs-number">10</span>;<span class="hljs-keyword">var</span> column = <span class="hljs-number">3</span>;<span class="hljs-keyword">var</span> row = <span class="hljs-number">2</span>;
</code></pre><pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">init</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">var</span> stage = <span class="hljs-keyword">new</span> createjs.Stage(<span class="hljs-string">"myCanvas"</span>); <span class="hljs-keyword">var</span> square;
</code></pre><pre><code><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>; i &lt; column*row; i++) {    square = drawSquare();  square.x = (squareWidth+squareGap)*(i%column);  square.y = (squarHeight+squareGap)*<span class="hljs-built_in">Math</span>.floor(i/column);   stage.addChild(square);  stage.update();   }
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">drawSquare</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">var</span> graphics = <span class="hljs-keyword">new</span> createjs.Graphics().setStrokeStyle(<span class="hljs-number">5</span>).beginStroke(<span class="hljs-string">"rgba(20,20,20,1)"</span>) graphics.beginFill(randomColor()).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squarHeight,squareWidth); <span class="hljs-keyword">var</span> shape = <span class="hljs-keyword">new</span> createjs.Shape(graphics); <span class="hljs-keyword">return</span> shape;}
</code></pre><pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">randomColor</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">var</span> num1 = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">255</span>); <span class="hljs-keyword">var</span> num2 = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">255</span>); <span class="hljs-keyword">var</span> num3 = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">255</span>); <span class="hljs-keyword">return</span> <span class="hljs-string">"rgba("</span>+num1+<span class="hljs-string">","</span>+num2+<span class="hljs-string">","</span>+num3+<span class="hljs-string">",1)"</span>; }
</code></pre><p>From the above codes, I will get a rendered HTML something like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*z0H1evsVhzgLNqjZbBHkTg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>There are many ways of implementing the square rendering. We could use looping in a multi-dimensional array, or we could manipulate the square size with some mathematical function. In this case, I’ll use the later. But here is the algorithm if you would like to use the multi-dimensional method:</p>
<pre><code>#alternativevar positionX =<span class="hljs-number">0</span>; <span class="hljs-keyword">var</span> positionY = <span class="hljs-number">0</span>;
</code></pre><pre><code><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;row;i++) {  <span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>;j&lt;column;j++) {      square = drawSquare();   square.x = positionX;   square.y = positionY;   stage.addChild(square);   stage.update();   positionX += squareWidth+squareGap;   <span class="hljs-built_in">console</span>.log(positionX);  }  positionX = <span class="hljs-number">0</span>;  positionY += squarHeight+squareGap; }
</code></pre><p><strong>Step 4</strong></p>
<p>Again, the objective of this game is to match a pair of colors together. So I need to modify the code in order for it to generate groups of colors in pairs. To do that, I will use an if else logic to make sure the two similar colors are used during the square rendering.</p>
<pre><code>#js/main.jsvar temp;<span class="hljs-keyword">var</span> genOnce = <span class="hljs-literal">false</span>;
</code></pre><pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">drawSquare</span>(<span class="hljs-params"></span>) </span>{<span class="hljs-keyword">var</span> color = randomColor();<span class="hljs-keyword">var</span> graphics = <span class="hljs-keyword">new</span> createjs.Graphics().setStrokeStyle(<span class="hljs-number">5</span>).beginStroke(<span class="hljs-string">"rgba(20,20,20,1)"</span>)
</code></pre><pre><code> <span class="hljs-keyword">if</span>(!genOnce) {  graphics.beginFill(color).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squarHeight,squareWidth);  temp = color;  genOnce = <span class="hljs-literal">true</span>; }<span class="hljs-keyword">else</span> {  graphics.beginFill(temp).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squarHeight,squareWidth);  genOnce = <span class="hljs-literal">false</span>; }
</code></pre><pre><code> <span class="hljs-keyword">var</span> shape = <span class="hljs-keyword">new</span> createjs.Shape(graphics); <span class="hljs-keyword">return</span> shape;}
</code></pre><p>This will render a group of squares something like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*u6Tll_9BqW0aOHD9T67Cog.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Step 5</strong></p>
<p>Next, I want each of the squares to be rendered in a random position so the pairs are separated from each other. This can be achieved by first creating an array consisting of all indices of the squares, then shuffling the array so the index number is randomly placed.</p>
<pre><code>#js/main.jsvar squarePlacement = [];
</code></pre><pre><code>##<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">to</span> <span class="hljs-title">generate</span> <span class="hljs-title">array</span> <span class="hljs-title">with</span> <span class="hljs-title">all</span> <span class="hljs-title">the</span> <span class="hljs-title">squares</span> <span class="hljs-title">indexfunction</span> <span class="hljs-title">randomDoubleColor</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>; i&lt;totalTiles;i++) {  squarePlacement.push(i); }  squarePlacement = shuffleArray(squarePlacement);  <span class="hljs-keyword">return</span> squarePlacement;
</code></pre><pre><code>}
</code></pre><pre><code>##<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">of</span> <span class="hljs-title">the</span> <span class="hljs-title">array</span> <span class="hljs-title">random</span> <span class="hljs-title">shufflingfunction</span> <span class="hljs-title">shuffleArray</span>(<span class="hljs-params">array</span>) </span>{    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = array.length - <span class="hljs-number">1</span>; i &gt; <span class="hljs-number">0</span>; i--) {        <span class="hljs-keyword">var</span> j = <span class="hljs-built_in">Math</span>.floor(<span class="hljs-built_in">Math</span>.random() * (i + <span class="hljs-number">1</span>));        [array[i], array[j]] = [array[j], array[i]];    }    <span class="hljs-keyword">return</span> array;}
</code></pre><p>Then I’ll need to change how I render the square. Instead of iterating through the length of total squares, I will iterate through the randomly shuffled array.</p>
<pre><code>#js/main.jsfunction init() {  <span class="hljs-keyword">var</span> stage = <span class="hljs-keyword">new</span> createjs.Stage(<span class="hljs-string">"myCanvas"</span>); <span class="hljs-keyword">var</span> square; randomDoubleColor();
</code></pre><pre><code><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>; i &lt; squarePlacement.length; i++) {      square = drawSquare();  square.x = (squareWidth+squareGap)*(squarePlacement[i]%column);  square.y = (squarHeight+squareGap)*<span class="hljs-built_in">Math</span>.floor(squarePlacement[i]/column);   stage.addChild(square);  stage.update();   }
</code></pre><pre><code>}
</code></pre><p>This will get me a group of squares like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*KR02inRMlBsPSkxSMKR6Iw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>I can see the effect better if more squares are rendered:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*N9AHVk0vIfJcplChR5vcQw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Step 6</strong></p>
<p>My goal is now to create a function that will compare two squares which will be selected subsequently.</p>
<pre><code>#js/main.jsvar highlight = createjs.Graphics.getRGB(<span class="hljs-number">255</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>);<span class="hljs-keyword">var</span> tileChecked;
</code></pre><p>I will start with defining a variable highlight. This will be used to highlight the first selected squares and a variable tileChecked to store the same square.</p>
<pre><code>#js/main.jsfor(i=<span class="hljs-number">0</span>; i &lt; squarePlacement.length; i++) {      square = drawSquare();  square.x = (squareWidth+squareGap)*(squarePlacement[i]%column);  square.y = (squarHeight+squareGap)*<span class="hljs-built_in">Math</span>.floor(squarePlacement[i]/column);   stage.addChild(square);  square.addEventListener(<span class="hljs-string">"click"</span>, handleOnPress);  stage.update();   }
</code></pre><pre><code>}
</code></pre><p>I will then create an event listener which will respond to a mouse click and trigger the function defined, handleOnPress. Now I will define the function as follows:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleOnPress</span>(<span class="hljs-params">e</span>) </span>{  <span class="hljs-keyword">var</span> tile = e.target;  <span class="hljs-keyword">if</span>(!!tileChecked === <span class="hljs-literal">false</span>) {   tile.graphics.setStrokeStyle(<span class="hljs-number">5</span>).beginStroke(highlight).rect(<span class="hljs-number">5</span>, <span class="hljs-number">5</span>, squareWidth, squarHeight);   tileChecked = tile;  }<span class="hljs-keyword">else</span> {   <span class="hljs-keyword">if</span>(tileChecked.graphics._fill.style === tile.graphics._fill.style &amp;&amp; tileChecked !== tile) {    tileChecked.visible = <span class="hljs-literal">false</span>;    tile.visible = <span class="hljs-literal">false</span>;   }<span class="hljs-keyword">else</span> {    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"not match"</span>);    tileChecked.graphics.setStrokeStyle(<span class="hljs-number">5</span>).beginStroke(<span class="hljs-string">"rgba(20,20,20,1)"</span>).rect(<span class="hljs-number">5</span>, <span class="hljs-number">5</span>, squareWidth, squarHeight);   }   tileChecked = <span class="hljs-literal">null</span>;  }    stage.update();
</code></pre><pre><code>}
</code></pre><p>Basically the function will first check the variable tileChecked. If it is undefined, the selected square will be highlighted. The selected square object will be saved in the variable tileChecked. Otherwise (which I expect to happen on the second click), the color between the current selected square and the one which is stored in the variable tileChecked will be compared.</p>
<p>In this second comparison, if the color is a match, I will make both the squares disappear. If it is not a match, I will remove the highlight and reset the variable tileChecked to undefined.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*vc7x8QVmi5I9qDUcAT2zSw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Step 7</strong></p>
<p>To create a real puzzle game, all of the colors should not be displayed. I will make the squares covered by grey squares, and when each is clicked, then it will reveal the color. So when it is not a match, the grey square will cover the box again.</p>
<p>To make it more playable, I will make sure other squares are not clickable during the comparison. I will also put some delay between when the second color is displayed and when both squares disappear or turn to grey. Some modification needs to be done in order for everything to work properly</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">init</span>(<span class="hljs-params"></span>) </span>{  <span class="hljs-keyword">var</span> stage = <span class="hljs-keyword">new</span> createjs.Stage(<span class="hljs-string">"myCanvas"</span>);  randomDoubleColor();
</code></pre><pre><code><span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>; i &lt; squarePlacement.length; i++) {    <span class="hljs-keyword">var</span> color =randomColor();  <span class="hljs-built_in">console</span>.log(color);  <span class="hljs-keyword">var</span> square = drawSquare(color);  <span class="hljs-built_in">console</span>.log(square);    square[<span class="hljs-string">"color"</span>] = square.graphics._fill.style;  square.graphics._fill.style = <span class="hljs-string">"rgb(140, 136, 136)"</span>;    square.x = (squareWidth+squareGap)*(squarePlacement[i]%column);  square.y = (squareHeight+squareGap)*<span class="hljs-built_in">Math</span>.floor(squarePlacement[i]/column);   stage.addChild(square);  square.addEventListener(<span class="hljs-string">"click"</span>, handleOnPress);  stage.update();   }  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleOnPress</span>(<span class="hljs-params">e</span>) </span>{    <span class="hljs-keyword">var</span> tile = e.target;
</code></pre><pre><code>tile.graphics.beginFill(tile.color).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squareHeight,squareWidth);  <span class="hljs-built_in">console</span>.log(tile.mouseEnabled);  tile.mouseEnabled = <span class="hljs-literal">false</span>;  <span class="hljs-built_in">console</span>.log(tile.mouseEnabled);
</code></pre><pre><code><span class="hljs-keyword">if</span>(!!tileChecked === <span class="hljs-literal">false</span>) {      tileChecked = tile;  }<span class="hljs-keyword">else</span> {
</code></pre><pre><code>stage.mouseChildren = <span class="hljs-literal">false</span>;   tile.graphics.beginFill(tile.color).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squareHeight,squareWidth);
</code></pre><pre><code><span class="hljs-built_in">setTimeout</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"in"</span>);    <span class="hljs-built_in">console</span>.log(tile);    <span class="hljs-built_in">console</span>.log(tileChecked);       <span class="hljs-keyword">if</span>(tileChecked.color === tile.color &amp;&amp; tileChecked !== tile) {         tileChecked.visible = <span class="hljs-literal">false</span>;     tile.visible = <span class="hljs-literal">false</span>;                }<span class="hljs-keyword">else</span> {    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"not match"</span>);    tile.graphics.beginFill(<span class="hljs-string">"rgb(140, 136, 136)"</span>).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squareHeight,squareWidth);    tileChecked.graphics.beginFill(<span class="hljs-string">"rgb(140, 136, 136)"</span>).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squareHeight,squareWidth);
</code></pre><pre><code>}   tile.mouseEnabled = <span class="hljs-literal">true</span>;   tileChecked.mouseEnabled = <span class="hljs-literal">true</span>;   stage.mouseChildren = <span class="hljs-literal">true</span>;   tileChecked = <span class="hljs-literal">null</span>;
</code></pre><pre><code>stage.update();      }, <span class="hljs-number">1000</span>);              }    stage.update();
</code></pre><pre><code>}
</code></pre><pre><code>}
</code></pre><pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">drawSquare</span>(<span class="hljs-params">color</span>) </span>{     <span class="hljs-keyword">var</span> graphics = <span class="hljs-keyword">new</span> createjs.Graphics().setStrokeStyle(<span class="hljs-number">5</span>).beginStroke(<span class="hljs-string">"rgba(20,20,20,1)"</span>)
</code></pre><pre><code><span class="hljs-keyword">if</span>(!genOnce) {  graphics.beginFill(color).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squareHeight,squareWidth);  temp = color;  genOnce = <span class="hljs-literal">true</span>; }<span class="hljs-keyword">else</span> {  graphics.beginFill(temp).rect(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>,squareHeight,squareWidth);  genOnce = <span class="hljs-literal">false</span>; }    <span class="hljs-keyword">var</span> shape = <span class="hljs-keyword">new</span> createjs.Shape(graphics); <span class="hljs-keyword">return</span> shape;}
</code></pre><p>Below is a video of the game in action:</p>
<p>This game can be enhanced further by adding the winning or losing rules, or maybe by adding a timer to record each player’s finishing time. At the moment I will stop development up until this point. The full code can be found on GitHub below, and anybody is free to use it for any other project.</p>
<p><a target="_blank" href="https://github.com/muyaszed/Matching-game-using-Easel.js"><strong>muyaszed/Matching-game-using-Easel.js</strong></a><br><a target="_blank" href="https://github.com/muyaszed/Matching-game-using-Easel.js">_Contribute to Matching-game-using-Easel.js development by creating an account on GitHub._github.com</a></p>
<p><a target="_blank" href="http://yazedjamal.com/guess/">DEMO</a></p>
<p><strong>Notes</strong>: There are probably many ways to implement this feature, but this way was easiest for me. Anybody is free to comment on any mistakes or improvements that I can apply. This guide is initially for me to learn and remember what I have done. Nonetheless anybody is welcome to follow this guide if you find it is helpful.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
