{"id":19983,"date":"2016-02-07T03:01:17","date_gmt":"2016-02-06T17:01:17","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=19983"},"modified":"2016-02-06T14:09:42","modified_gmt":"2016-02-06T04:09:42","slug":"htmljavascript-canvas-four-deck-card-game-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-four-deck-card-game-tutorial\/","title":{"rendered":"HTML\/Javascript Canvas Four Deck Card Game Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/two_o_eight_pick_up.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML\/Javascript Canvas Four Deck Card Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/two_o_eight_pick_up.jpg\" title=\"HTML\/Javascript Canvas Four Deck Card Game Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML\/Javascript Canvas Four Deck Card Game Tutorial<\/p><\/div>\n<p>We were amused recently with a <a target=_blank title='News story' href='http:\/\/www.bbc.com\/news\/world-asia-35491852'>story<\/a> about bridge players getting into trouble with being in possession of more than 120 playing cards.  We&#8217;ve designed today a game where you can deal with up to 4 decks of cards, online, all at once, in case you are trepidatious being the organiser of your local bridge club&#8217;s games, getting out the front gate undetected.<\/p>\n<p>We again use the Canvas HTML element tag, which can be used as the container to draw graphics on the fly usually via the use of Javascript functions for rendering and event management, as we did for the <a title='HTML\/Javascript Canvas Card Game Tutorial' href='#hjccgt'>HTML\/Javascript Canvas Card Game Tutorial<\/a> we based this game upon.<\/p>\n<p>In today&#8217;s tutorial we touch on the functionality to draw an image on the canvas via <a target=_blank title='HTML canvas element drawImage() method information from w3schools' href='http:\/\/www.w3schools.com\/tags\/canvas_drawimage.asp'>drawImage()<\/a> method.   In the case of this tutorial that image is either a playing card or an image of a playing card turned over, a quarter of the size it was for the tutorial below.   We start the canvas with a background image defined (the card turned over) as a repeated image with lots of transparency and this is changed at the first click, which is like this game&#8217;s definition of <i>&#8220;game on&#8221;<\/i>.<\/p>\n<p>So the game is a game of odds and the more daring you are with the card criteria you choose the more points you get, and there is not a lot of difference with the odds involved just because you have several decks of cards involved, curiously, but you are less likely to get those points, certainly at the start of each shuffled deck.<\/p>\n<p>The same challenge remains &#8230;<\/p>\n<blockquote>\n<p>Anyway, will leave the tactics to you, but the destination score achievement of 200 will take at least 4 goes.   If anybody gets it in 4 you can claim the cupie doll by emailing me (with a non-doctored screenshot &#8230; and would have to rule out the use of Firebug (and its like &#8230; this will involve a polygraph test)).<\/p>\n<\/blockquote>\n<p>To read more about the HTML canvas element you could consult <a target=_blank title='HTML Canvas Reference' href='http:\/\/www.w3schools.com\/tags\/ref_canvas.asp'>HTML Canvas Reference<\/a> as a generic reference, or here, at the tutorial <a target=_blank title='javascript - How do I add a simple onClick event handler to a canvas element? - Stack Overflow' href='http:\/\/stackoverflow.com\/questions\/9880279\/how-do-i-add-a-simple-onclick-event-handler-to-a-canvas-element'>javascript &#8211; How do I add a simple onClick event handler to a canvas element? &#8211; Stack Overflow<\/a>.<\/p>\n<p>As you can imagine, this HTML canvas element, new to HTML5, can be very useful for some practical client-side web functionality.<\/p>\n<p>Link to some downloadable HTML programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/two_o_eight_pick_up.html-GETME' title='two_o_eight_pick_up.html'>two_o_eight_pick_up.html<\/a> and see how it came to be created based on the changes to previous code at <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/two_o_eight_pick_up.html-GETME' title='two_o_eight_pick_up.html'>this link<\/a> or try our <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/two_o_eight_pick_up.html\" title='click picture'>live run<\/a> link.<\/p>\n<hr>\n<p id='hjccgt'>Previous relevant <a target=_blank title='HTML\/Javascript Canvas Card Game Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-card-game-tutorial\/'>HTML\/Javascript Canvas Card Game Tutorial<\/a><\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML\/Javascript Canvas Card Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/odds_200.jpg\" title=\"HTML\/Javascript Canvas Card Game Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML\/Javascript Canvas Card Game Tutorial<\/p><\/div>\n<p>The Canvas HTML element tag can be used as the container to draw graphics on the fly usually via the use of Javascript functions for rendering and event management.<\/p>\n<p>In today&#8217;s tutorial we touch on the functionality to draw an image on the canvas via drawImage() method.   In the case of this tutorial that image is either a playing card or an image of a playing card turned over.   We start the canvas with a background image defined (the card turned over) as a repeated image with lots of transparency and this is changed at the first click, which is like this game&#8217;s definition of <i>&#8220;game on&#8221;<\/i>.<\/p>\n<p>So the game is a game of odds and the more daring you are with the card criteria you choose the more points you get, but you are less likely to get those points, certainly at the start of each shuffled deck.  Anyway, will leave the tactics to you, but the destination score achievement of 200 will take at least 4 goes.   If anybody gets it in 4 you can claim the cupie doll by emailing me (with a non-doctored screenshot &#8230; and would have to rule out the use of Firebug (and its like &#8230; this will involve a polygraph test)).<\/p>\n<p>You may want to read more at <a target=_blank title='HTML Canvas Reference' href='http:\/\/www.w3schools.com\/tags\/ref_canvas.asp'>HTML Canvas Reference<\/a> as a generic reference, or here, at the tutorial <a target=_blank title='javascript - How do I add a simple onClick event handler to a canvas element? - Stack Overflow' href='http:\/\/stackoverflow.com\/questions\/9880279\/how-do-i-add-a-simple-onclick-event-handler-to-a-canvas-element'>javascript &#8211; How do I add a simple onClick event handler to a canvas element? &#8211; Stack Overflow<\/a>.<\/p>\n<p>As you can imagine, this HTML canvas element, new to HTML5, can be very useful for some practical client-side web functionality.<\/p>\n<p>Link to some downloadable HTML programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/odds_200.html_GETME' title='odds_200.html'>odds_200.html<\/a>\n<\/p>\n<p>You&#8217;ll notice heavy use of the Javascript <a target=_blank title='Javascript Math.random() information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_random.asp'>Math.random()<\/a> function and examination of URL <i>&#8220;get&#8221;<\/i> parameters (for game resumptions when reshuffling is required).<\/p>\n<p>We hope you enjoy this tutorial as a <a target=_blank title='Canvas HTML element live run tutorial'  href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Odds200\/\">live run<\/a>.<\/p>\n<p>Yes &#8230; you&#8217;ve reached the end &#8230; hope you have a good game!<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5539' onclick='var dv=document.getElementById(\"d5539\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=59\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5539' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d19983' onclick='var dv=document.getElementById(\"d19983\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/canvas\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d19983' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We were amused recently with a story about bridge players getting into trouble with being in possession of more than 120 playing cards. We&#8217;ve designed today a game where you can deal with up to 4 decks of cards, online, &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-four-deck-card-game-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,15,37],"tags":[184,187,476,477,576,652,953,997,1319],"class_list":["post-19983","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-games","category-tutorials","tag-canvas","tag-cards","tag-game","tag-games-2","tag-html","tag-javascript","tag-playing-cards","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/19983"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=19983"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/19983\/revisions"}],"predecessor-version":[{"id":19989,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/19983\/revisions\/19989"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=19983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=19983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=19983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}