 # Repository <a href="https://github.com/premasagar/pablo">Pablojs</a> <a href="https://github.com/onepicesteem">My Github Profile</a> <a href="https://github.com/onepicesteem/Minefield-Game-Using-HTML-5-SVG-Part2">Minefield Game Using HTML 5 SVG (Part-2)</a> # What Will I Learn? - You will learn how to build games using `HTML5 SVG`. - You will learn to create svg objects more easily using `Pablojs`. - You will learn to create a svg object as text on the screen. # Requirements <a href="https://github.com/Microsoft/vscode">Visual Studio Code in GitHub</a> # Difficulty - Basic # Tutorial Contents In the previous article we created minefields for game and set mines at random. Mines were randomly settled in different places when we refresh the page. Now we can place the numbers in the boxes next to the bombs. In this article I will show the number of bombs that are placed next to the boxes that are not bombs. I'll use `svg.text()` to do this. Let's start. I created a object named `square` to create a box so that I could keep the properties of the boxes. I could keep the value, appearance and starting points of this box with this object. #### Let's make a few edits in our code Change the `rect` property to `obj` before you start placing numbers. I also return the rectangle drawn in the `rectBuilder()` function. So we can click on the boxes with the help of the pointer and play the game. Let's arrange the `obj` property into the `square` object. ``` var square={ value:0, obj:rectBuilder(pointX,pointY,'#dcdde1'), pointX:pointX, pointY:pointY } ``` <br> Let's edit the `rectBuilder()` function. ``` function rectBuilder(x,y,color){ return arc=svg.rect({ x:x, y:y, width:50, height:50, fill: color, }); ``` <br> We can start to place numbers according to what we made the necessary changes. #### Set Value Property We created the `value property` to hold the values of the bombs and the numbers to be written next to it. We set the value to null when creating bombs so we can add values next to this box when `value = null`. When we refresh the page, the `area` object having random bombs is as follows. #### Screenshot 1  <br> If we increase the value of the boxes next to the bombs by one and we repeat it for all the bombs, we will place the numbers correctly. I will use the nested for loop for minefield fields so I will have access to x-y coordinates. When the value attribute in the area array is null, we can catch what we are on the bomb. ``` for (var x = 0; x < 5; x++) { for (var y = 0; y < 5; y++) { if(area[x][y].value==null){ } } } ``` <br> We need to access the sides of the bomb. #### Screenshot 2  <br> With the nested for loop we can find the boxes on the sides of the bomb. Increase the value properties of the boxes next to it. ``` for (var x = 0; x < 5; x++) { for (var y = 0; y < 5; y++) { if(area[x][y].value==null){ console.log(x+','+y); for (var i = x-1; i <=x+1; i++) { for (var j = y-1; j <=y+1; j++) { area[i][j].value=area[i][j].value+1; } } } } } ``` <br> When we create our algorithm like this, we will encounter an error when we refresh the page. This error occurs because we went out of the minefield area. If the bomb is placed on the edges, we can not find such an area because we have adjusted the values of the boxes on the sides of the bomb. If we place the values by controlling the edges of the minefield, we will not have such a problem. ``` for (var x = 0; x < 5; x++) { for (var y = 0; y < 5; y++) { if(area[x][y].value==null){ console.log(x+','+y); for (var i = x-1; i <=x+1; i++) { for (var j = y-1; j <=y+1; j++) { if(i<0||i>4){//We are checking bounds in x coordinate. }else{ if(j<0||j>4){//We are checking bounds in y coordinate. } else{ if(area[i][j].value!=null){ area[i][j].value=area[i][j].value+1; } } } } } } } } ``` <br> So we set the value property to the box next to the bomb. #### Screenshot 3  <br> The values next to the bomb were set. ### Drawing Numbers On The Screen I'll define one function to draw the numbers on the screen. I can create a drawing with the `text()` function from the svg object we created. With the `text() function`, we can set the color, size and starting point of the text to be written on the screen. The text to be written to the screen, we will send it as a parameter to the `content()` function. Let's create the function. ``` function textBuilder(x,y,color,value){ text = svg.text({ x:x, y:y, fill:color, 'font-size':'15px', 'font-family':'sans-serif' }); text.content(value); } ``` <br> We send to this function the starting points of the text, the color and the value to be written. Now, we need to do this in a 5x5 nested for loop using this function to draw value values. ``` for (var x = 0; x < 5; x++) { for (var y = 0; y < 5; y++) { if(area[x][y].value!=null){ textBuilder(area[x][y].pointX,area[x][y].pointY,'#1abc9c',area[x][y].value); } } } ``` <br> I printed the values in the boxes outside the bomb box. I started the starting points of the boxes and the starting points of the texts from the same place. #### Screenshot 4  <br> The mine field was like the one pictured above because we made such an encoding. The problem will be solved if we shift the starting points of the text a bit. The new `textBuilder()` function is below. ``` function textBuilder(x,y,color,value){ text = svg.text({ x:x+20, y:y+35, fill:color, 'font-size':'15px', 'font-family':'sans-serif' }); text.content(value); } ``` <br> The new version of the minefield is below. #### Screenshot 5  <br> So we set the numbers and when the page is refreshed it is rearranged according to the position of the bombs. #### Screenshot 6  ### What Is Next ? We put bombs and numbers in the minefield. Must be invisible and clickable to become a game # Curriculum - [Minefield Game Using HTML 5 SVG (Part-1)](https://steemit.com/utopian-io/@onepice/minefield-game-using-html-5-svg-part-1) # Proof of Work Done https://github.com/onepicesteem/Minefield-Game-Using-HTML-5-SVG-Part2
author | onepice |
---|---|
permlink | minefield-game-using-html-5-svg-part-2 |
category | utopian-io |
json_metadata | {"tags":["utopian-io","tutorials","jquery","pablojs","html5-game"],"image":["https://cdn.steemitimages.com/DQmXZmWSGqMeE3VmtYCFPxRMHoneKnAS88db8rcfRDo7iSP/jquery0.fw.png","https://cdn.steemitimages.com/DQmU4meZSAPzu9tMPn1m4hnszjiBZxpgLJMCyrZpz7NgeaK/jquery1.jpg","https://cdn.steemitimages.com/DQmPztXvwRF7RnMwDySA55fBynKLc94v9gefiw3kpQh4bRW/jquery1.fw.png","https://cdn.steemitimages.com/DQmcpe3Q8kCogZmHDHfGnjPp3MJbhK1gF5qX7njpLqayihA/jquery3.jpg","https://cdn.steemitimages.com/DQmP2WiS6FV6QEKNzYBQb3gz8qk4Br1UGX9odCYDiMhkrAB/jquery4.jpg","https://cdn.steemitimages.com/DQmbTa8Gpb6YvrF3B4kWwoyDm2NQSFsd3LV9539CEUxph7R/jquery5.jpg","https://cdn.steemitimages.com/DQmSRWpv8Zh9FcRbPqy2qeAN9djLda8yqudoz1muiaBa1yH/jquery6.JPG"],"links":["https://github.com/premasagar/pablo","https://github.com/onepicesteem","https://github.com/onepicesteem/Minefield-Game-Using-HTML-5-SVG-Part2","https://github.com/Microsoft/vscode","https://steemit.com/utopian-io/@onepice/minefield-game-using-html-5-svg-part-1"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-09-03 10:37:51 |
last_update | 2018-09-03 10:37:51 |
depth | 0 |
children | 5 |
last_payout | 2018-09-10 10:37:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 22.226 HBD |
curator_payout_value | 7.098 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 7,354 |
author_reputation | 9,626,549,398,383 |
root_title | "Minefield Game Using HTML 5 SVG (Part-2)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,172,617 |
net_rshares | 24,020,336,115,663 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
miniature-tiger | 0 | 129,277,373,210 | 100% | ||
aleister | 0 | 7,358,201,633 | 30% | ||
yuxid | 0 | 1,503,320,497 | 1% | ||
teo-nyx | 0 | 8,058,493,138 | 10% | ||
utopian-io | 0 | 23,475,202,150,103 | 15.66% | ||
yorkchinese | 0 | 82,425,208 | 1% | ||
amosbastian | 0 | 15,127,553,383 | 22.53% | ||
portugalcoin | 0 | 7,238,851,930 | 28% | ||
simoneg | 0 | 2,744,326,301 | 40% | ||
properfraction | 0 | 702,002,840 | 100% | ||
statsexpert | 0 | 1,339,200,079 | 20% | ||
instaforex | 0 | 503,408,076 | 100% | ||
kolxoznik0 | 0 | 506,063,182 | 100% | ||
artemnezlobin | 0 | 504,213,560 | 100% | ||
lordofreward | 0 | 429,900,159 | 1.5% | ||
council | 0 | 683,221,642 | 10% | ||
eduard999 | 0 | 513,809,184 | 100% | ||
stepanslobodyan | 0 | 503,659,587 | 100% | ||
hlebova1009 | 0 | 512,230,645 | 100% | ||
desp-er | 0 | 513,426,937 | 100% | ||
alabama2018 | 0 | 505,423,257 | 100% | ||
grabowskig | 0 | 504,087,451 | 100% | ||
xachatryank | 0 | 504,228,543 | 100% | ||
garikpetrosyan | 0 | 513,209,165 | 100% | ||
remind-me | 0 | 59,219,201 | 100% | ||
lusinehakobyan | 0 | 506,262,899 | 100% | ||
klaraminasyan | 0 | 513,856,541 | 100% | ||
bornd07 | 0 | 505,233,545 | 100% | ||
artnov0411 | 0 | 503,238,096 | 100% | ||
robsimsh | 0 | 504,707,439 | 100% | ||
volohavostr78 | 0 | 502,626,885 | 100% | ||
sstrazzefa | 0 | 505,527,623 | 100% | ||
hranushdavdyan | 0 | 505,659,613 | 100% | ||
hunangalstyan | 0 | 514,248,145 | 100% | ||
voronovboris | 0 | 513,993,272 | 100% | ||
cleavageobjects | 0 | 505,578,816 | 100% | ||
decorousoutspoke | 0 | 504,756,792 | 100% | ||
fedykosoy00 | 0 | 504,876,118 | 100% | ||
ervinj89 | 0 | 505,061,260 | 100% | ||
edwardcru96 | 0 | 506,844,398 | 100% | ||
mightypanda | 0 | 16,623,262,933 | 60% | ||
gravityenteral | 0 | 505,880,950 | 100% | ||
filmsdormant | 0 | 505,134,663 | 100% | ||
sutegloss | 0 | 514,488,917 | 100% | ||
payslipsitaly | 0 | 504,920,349 | 100% | ||
seasonedgrade | 0 | 504,612,209 | 100% | ||
uglypsi | 0 | 505,113,942 | 100% | ||
woodtongue | 0 | 505,043,418 | 100% | ||
embryofemur | 0 | 505,253,476 | 100% | ||
headerharem | 0 | 505,154,578 | 100% | ||
pastrytorn | 0 | 505,497,679 | 100% | ||
wagglergranted | 0 | 504,401,013 | 100% | ||
irinakolcova91 | 0 | 505,155,147 | 100% | ||
linashevchyk | 0 | 505,032,241 | 100% | ||
peruska | 0 | 505,035,693 | 100% | ||
tamilaisaeva | 0 | 504,933,329 | 100% | ||
kernovanatali | 0 | 503,736,920 | 100% | ||
truthly | 0 | 68,278,335 | 100% | ||
antalovaelena | 0 | 502,777,236 | 100% | ||
artyrdavletov | 0 | 505,422,149 | 100% | ||
nikolay.suhoruk | 0 | 505,738,643 | 100% | ||
ricklargo | 0 | 506,045,357 | 100% | ||
vadimstapov | 0 | 512,456,383 | 100% | ||
wivesfesnying | 0 | 503,952,907 | 100% | ||
shallowcuttle | 0 | 502,896,187 | 100% | ||
rinkchops | 0 | 512,216,433 | 100% | ||
drinkschin | 0 | 505,511,904 | 100% | ||
patcheswish | 0 | 503,256,170 | 100% | ||
towheelocate | 0 | 512,248,254 | 100% | ||
redirectunkind | 0 | 503,586,552 | 100% | ||
nasturtiumfatty | 0 | 512,345,475 | 100% | ||
snailrepeat | 0 | 505,753,953 | 100% | ||
wailibis | 0 | 503,627,697 | 100% | ||
corvushilt | 0 | 505,941,338 | 100% | ||
visitorsahem | 0 | 512,016,508 | 100% | ||
bumpyforster | 0 | 503,541,974 | 100% | ||
nuclearbooby | 0 | 512,422,160 | 100% | ||
casecod | 0 | 505,907,995 | 100% | ||
feettool | 0 | 503,035,295 | 100% | ||
fastandcurious | 0 | 3,398,326,009 | 100% | ||
medaltrot | 0 | 503,702,860 | 100% | ||
recentlyimply | 0 | 503,472,471 | 100% | ||
shalelinkage | 0 | 512,676,925 | 100% | ||
diplute | 0 | 503,547,187 | 100% | ||
coinsicy | 0 | 512,405,784 | 100% | ||
crystaleur | 0 | 512,392,158 | 100% | ||
spidervariety | 0 | 506,126,004 | 100% | ||
facedwrapped | 0 | 503,826,513 | 100% | ||
beeperaquitaine | 0 | 503,849,846 | 100% | ||
fourosprey | 0 | 503,823,674 | 100% | ||
couldpinkie | 0 | 506,591,656 | 100% | ||
grouseunhelpful | 0 | 503,604,329 | 100% | ||
huskyelectron | 0 | 503,694,596 | 100% | ||
listlabcoat | 0 | 503,508,118 | 100% | ||
zhilin8 | 0 | 503,466,250 | 100% | ||
nseregin8 | 0 | 506,151,164 | 100% | ||
kiryuha11 | 0 | 512,118,236 | 100% | ||
asavin88 | 0 | 502,942,230 | 100% | ||
iauns | 0 | 63,457,763,836 | 90% | ||
antoniel | 0 | 511,923,271 | 100% | ||
toenailnano | 0 | 503,396,654 | 100% | ||
massfishing | 0 | 504,197,263 | 100% | ||
brickgordon | 0 | 504,106,814 | 100% | ||
tuilleswine | 0 | 512,855,219 | 100% | ||
meaninglathered | 0 | 503,129,490 | 100% | ||
bullinachinashop | 0 | 1,984,921,828 | 80% | ||
steem-ua | 0 | 236,552,120,989 | 2.1% | ||
pashafeloff | 0 | 503,663,680 | 100% | ||
nikvoronkov1984 | 0 | 500,734,768 | 100% | ||
atihonov1990 | 0 | 503,496,768 | 100% | ||
saymonr | 0 | 500,732,251 | 100% | ||
ivan.dyuzhev | 0 | 500,734,768 | 100% | ||
kostya.borisenko | 0 | 500,734,768 | 100% | ||
aprokopenko1990 | 0 | 506,481,026 | 100% | ||
antonturov90 | 0 | 512,617,276 | 100% | ||
kuangtianwen | 0 | 352,172,269 | 100% |
Oh my God....!
author | nadir1122 |
---|---|
permlink | re-onepice-minefield-game-using-html-5-svg-part-2-20180909t041015640z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-09-09 04:10:21 |
last_update | 2018-09-09 04:10:21 |
depth | 1 |
children | 0 |
last_payout | 2018-09-16 04:10:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 14 |
author_reputation | 5,443,528,914 |
root_title | "Minefield Game Using HTML 5 SVG (Part-2)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,755,009 |
net_rshares | 0 |
Thank you for your contribution. After reviewing your tutorial we suggest the following: - Nice work on the explanations of your code, although adding a bit more comments to the code can be helpful as well. We are waiting to see the game with animation. Good job! Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category. To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/21113314). ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | portugalcoin |
---|---|
permlink | re-onepice-minefield-game-using-html-5-svg-part-2-20180903t222618295z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/8/21113314","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-09-03 22:26:18 |
last_update | 2018-09-03 22:26:18 |
depth | 1 |
children | 1 |
last_payout | 2018-09-10 22:26:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 5.806 HBD |
curator_payout_value | 1.873 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 757 |
author_reputation | 598,828,312,571,988 |
root_title | "Minefield Game Using HTML 5 SVG (Part-2)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,227,617 |
net_rshares | 6,651,943,769,385 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
pixelfan | 0 | 1,861,174,459 | 0.55% | ||
espoem | 0 | 16,566,701,170 | 15% | ||
utopian-io | 0 | 6,597,621,901,723 | 4.28% | ||
amosbastian | 0 | 4,160,077,180 | 6.69% | ||
reazuliqbal | 0 | 6,807,062,306 | 15% | ||
statsexpert | 0 | 5,175,673,029 | 80% | ||
mightypanda | 0 | 9,696,903,378 | 35% | ||
anonyvoter | 0 | 1,183,783,837 | 50% | ||
fastandcurious | 0 | 1,326,743,716 | 40% | ||
mops2e | 0 | 339,728,176 | 10% | ||
bullinachinashop | 0 | 973,375,127 | 40% | ||
onepice | 0 | 6,230,645,284 | 100% |
Thank you for your review, @portugalcoin! So far this week you've reviewed 14 contributions. Keep up the good work!
author | utopian-io |
---|---|
permlink | re-re-onepice-minefield-game-using-html-5-svg-part-2-20180903t222618295z-20180907t224011z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-09-07 22:40:12 |
last_update | 2018-09-07 22:40:12 |
depth | 2 |
children | 0 |
last_payout | 2018-09-14 22:40:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 116 |
author_reputation | 152,955,367,999,756 |
root_title | "Minefield Game Using HTML 5 SVG (Part-2)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,647,910 |
net_rshares | 0 |
#### Hi @onepice! Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation! Your post is eligible for our upvote, thanks to our collaboration with @utopian-io! **Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
author | steem-ua |
---|---|
permlink | re-minefield-game-using-html-5-svg-part-2-20180903t224016z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.54"}" |
created | 2018-09-03 22:40:18 |
last_update | 2018-09-03 22:40:18 |
depth | 1 |
children | 0 |
last_payout | 2018-09-10 22:40:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 286 |
author_reputation | 23,214,230,978,060 |
root_title | "Minefield Game Using HTML 5 SVG (Part-2)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,228,546 |
net_rshares | 0 |
Hey, @onepice! **Thanks for contributing on Utopian**. Weβre already looking forward to your next contribution! **Get higher incentives and support Utopian.io!** Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)). **Want to chat? Join us on Discord https://discord.gg/h52nFrV.** <a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
author | utopian-io |
---|---|
permlink | re-minefield-game-using-html-5-svg-part-2-20180904t031511z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-09-04 03:15:12 |
last_update | 2018-09-04 03:15:12 |
depth | 1 |
children | 0 |
last_payout | 2018-09-11 03:15:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 589 |
author_reputation | 152,955,367,999,756 |
root_title | "Minefield Game Using HTML 5 SVG (Part-2)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,246,285 |
net_rshares | 15,679,266,296 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 15,339,538,120 | 15% | ||
mops2e | 0 | 339,728,176 | 10% |