diff options
Diffstat (limited to 'examples/Conozco-Uruguay')
m--------- | examples/Conozco-Uruguay | 0 | ||||
-rwxr-xr-x | examples/Conozco-Uruguay/assets/.DS_Store | bin | 0 -> 6148 bytes | |||
-rwxr-xr-x | examples/Conozco-Uruguay/assets/generic/.DS_Store | bin | 0 -> 6148 bytes | |||
-rwxr-xr-x | examples/Conozco-Uruguay/assets/generic/images/capital.png | bin | 0 -> 667 bytes | |||
-rwxr-xr-x | examples/Conozco-Uruguay/assets/generic/images/deptosLineas.png | bin | 0 -> 41887 bytes | |||
-rwxr-xr-x | examples/Conozco-Uruguay/assets/generic/images/fondo.png | bin | 0 -> 40650 bytes | |||
-rwxr-xr-x | examples/Conozco-Uruguay/index.html | 25 | ||||
-rwxr-xr-x | examples/Conozco-Uruguay/js/capital.js | 139 | ||||
-rwxr-xr-x | examples/Conozco-Uruguay/js/lesson.js | 54 |
9 files changed, 218 insertions, 0 deletions
diff --git a/examples/Conozco-Uruguay b/examples/Conozco-Uruguay deleted file mode 160000 -Subproject c81a6fba4aa94662019013a857c8bb875e15fc8 diff --git a/examples/Conozco-Uruguay/assets/.DS_Store b/examples/Conozco-Uruguay/assets/.DS_Store Binary files differnew file mode 100755 index 0000000..f56d2c9 --- /dev/null +++ b/examples/Conozco-Uruguay/assets/.DS_Store diff --git a/examples/Conozco-Uruguay/assets/generic/.DS_Store b/examples/Conozco-Uruguay/assets/generic/.DS_Store Binary files differnew file mode 100755 index 0000000..10f526f --- /dev/null +++ b/examples/Conozco-Uruguay/assets/generic/.DS_Store diff --git a/examples/Conozco-Uruguay/assets/generic/images/capital.png b/examples/Conozco-Uruguay/assets/generic/images/capital.png Binary files differnew file mode 100755 index 0000000..09ddbe7 --- /dev/null +++ b/examples/Conozco-Uruguay/assets/generic/images/capital.png diff --git a/examples/Conozco-Uruguay/assets/generic/images/deptosLineas.png b/examples/Conozco-Uruguay/assets/generic/images/deptosLineas.png Binary files differnew file mode 100755 index 0000000..bcca5a4 --- /dev/null +++ b/examples/Conozco-Uruguay/assets/generic/images/deptosLineas.png diff --git a/examples/Conozco-Uruguay/assets/generic/images/fondo.png b/examples/Conozco-Uruguay/assets/generic/images/fondo.png Binary files differnew file mode 100755 index 0000000..81f9e9e --- /dev/null +++ b/examples/Conozco-Uruguay/assets/generic/images/fondo.png diff --git a/examples/Conozco-Uruguay/index.html b/examples/Conozco-Uruguay/index.html new file mode 100755 index 0000000..be1b5a2 --- /dev/null +++ b/examples/Conozco-Uruguay/index.html @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>Karma - Connoszco Uruguay</title> + <meta name="keywords" content="karma,javascript,html5,sugar,sugarlabs,gsoc,ole,nepal,urugay" /> + <script type="text/javascript" src="js/raphael-min.js"></script> + <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> + <script type="text/javascript" src="js/jquery.karma.js"></script> + <script type="text/javascript" src="js/karma.Gettext.js"></script> + <script type="text/javascript" src="js/lesson.js"></script> + <script type="text/javascript" src="js/capital.js"></script> + </head> + <body> + <div id="karma-main"> + + <div id="mycanvas"></div> + <div id="buttons"> + <button id="start">Start</button> + </div> + <div id="question"></div> + </div> + + </body> +</html>
\ No newline at end of file diff --git a/examples/Conozco-Uruguay/js/capital.js b/examples/Conozco-Uruguay/js/capital.js new file mode 100755 index 0000000..e19019a --- /dev/null +++ b/examples/Conozco-Uruguay/js/capital.js @@ -0,0 +1,139 @@ + +// returns a random number between 0 - upperbound +function random_between(upperbound) { + return Math.floor(Math.random() * (upperbound + 1)); +} + + function game(paper,img){ + var capitals = makeCapitals(); + var states = makeStates(); + var isVisible_f = function(boolval) { + return function(element,index,array) { + return element.isVisiblep() === boolval ; };}; + var oldquestions_f = isVisible_f(true); + var newquestions_f = isVisible_f(false); + + var selected = undefined; + var selectcap = function() { + if (!capitals.some(newquestions_f)) + return undefined; + var newcap = capitals.filter(newquestions_f); + var idx = random_between(newcap.length - 1); + selected = newcap[idx]; + return selected; + } + + return { + capitals : capitals, + newquestion : function() { + selected = selected === undefined ? selectcap() : selected; + return selected;}, + + isAnswerp : function(x,y) { + if (selected === undefined) + { + return false; + } + if (selected.isClickingp(x,y)) + { + selected.toogle(); + selected = undefined; + return true; + } + return false; }, + has_more_questionp : function() { + return capitals.some(newquestions_f); + }, + draw : function() { + var i; + states.map(function(state){ + state.draw(paper,img);}); + capitals.map(function(capital) { + capital.draw(paper,img) ;}); + } + }; + } + + + function createCapital(name,posx,posy) { + var visible = false; + var phrase = "Where is " + name + "?"; + return { + getPhrase : phrase, + isVisiblep : function() { + return visible === true; }, + toogle : function() { + visible = visible === false ? true : false; + }, + x : posx, + y : posy, + draw : function(paper,imgsrc) { + paper.image(imgsrc,posx,posy,10,10); + if (visible) + { paper.text(posx + 15, posy + 15, name);}}, + //paper.print(posx, posy, name, paper.getFont("Times"), 30);}, + + isClickingp : function(x,y) { + var radius = 20; + var diameter = radius * radius; + var eqt = Math.pow((x-posx),2) + Math.pow((y-posy),2); + return eqt <= diameter ? true : false; + } + } + } + + function createState(name,posx, posy) { + return { + draw : function(paper) { + paper.text(posx,posy,name); + }}; + } + + function makeStates() + { + return new Array( + createState("Artigas", 212,126), + createState("Salto", 202,254), + createState("Paysandú", 156,362), + createState("Río Negro", 130,500), + createState("Rivera", 490,272), + createState("Tacuarembó", 446,380), + createState("Soriano", 128,630), + createState("Colonia", 132,726), + createState("Flores", 246,614), + createState("Durazno", 388,550), + createState("Cerro Largo", 624,436), + createState("San José", 280,742), + createState("Florida", 386,668), + createState("Treinta y Tres", 624,534), + createState("Canelones", 382,786), + createState("Montevideo", 348,838), + createState("Lavalleja", 532,656), + createState("Maldonado", 522,818), + createState("Rocha", 654,678)); + } + + + function makeCapitals() + { + return new Array( + createCapital("Artigas",293,54), + createCapital("Salto",91,237), + createCapital("Paysandú",77,396), + createCapital("Fray Bentos",51,562), + createCapital("Rivera",446,162), + createCapital("Tacuarembó",376,299), + createCapital("Mercedes",86,582), + createCapital("Colonia del Sacramento",120,784), + createCapital("Trinidad",244,647), + createCapital("San José de Mayo",262,785), + createCapital("Durazno",309,593), + createCapital("Florida",351,715), + createCapital("Canelones",341,798), + createCapital("Montevideo",355,847), + createCapital("Melo",632,400), + createCapital("Treinta y Tres",633,554), + createCapital("Minas",483,744), + createCapital("Rocha",607,765), + createCapital("Maldonado",532,853) ); + } diff --git a/examples/Conozco-Uruguay/js/lesson.js b/examples/Conozco-Uruguay/js/lesson.js new file mode 100755 index 0000000..9a15a4d --- /dev/null +++ b/examples/Conozco-Uruguay/js/lesson.js @@ -0,0 +1,54 @@ +$(document).ready(function(){ + var DEFAULT_SIZE_X = 786; + var DEFAULT_SIZE_Y = 900; + //stupid hack, find out how to calc the diff between image and top + // of webpage + var OFFSET = 8; + var g = game(); + + var k = $.karma({container: "#karma-main"}) + k.init({ + images : [ + {name : "background", file : "fondo.png", localized : false }, + {name : "capital", file : "capital.png" , localized : false}, + {name : "lines", file : "deptosLineas.png", localized: false} + ] + }); + + k.main(function() { + var paper = Raphael("mycanvas",DEFAULT_SIZE_X,DEFAULT_SIZE_Y); + + var g = game(paper,k.library.images["capital"].src); + var q = g.newquestion(); + document.getElementById('question').innerHTML = q.getPhrase; + + var clicked = function(event){ + var x = event.clientX + document.documentElement.scrollLeft - OFFSET; + var y = event.clientY + document.documentElement.scrollTop - OFFSET; + var ans = g.isAnswerp(x, y); + if (ans) { + g.draw(); + q = g.newquestion(); + } + document.getElementById('question').innerHTML = q.getPhrase; + } + + var draw = function() { + paper.image(k.library.images["background"].src,0,0,DEFAULT_SIZE_X,DEFAULT_SIZE_Y); + var i = paper.image(k.library.images["lines"].src,0,0,DEFAULT_SIZE_X,DEFAULT_SIZE_Y); + g.draw(); + } + + + document.getElementById('mycanvas').addEventListener('click', clicked, false); + + document.getElementById('start'). + addEventListener('click', draw, false); + }); +}); + + + + + +
\ No newline at end of file |