简体   繁体   English

使用JavaScript在HTML5画布上制作单词搜索网格

[英]Making a word search grid on HTML5 canvas using javascript

I want to develop a word search game such as [ http://codecanyon.net/item/word-search-game/full_screen_preview/2708856] 我想开发一个单词搜索游戏,例如[ http://codecanyon.net/item/word-search-game/full_screen_preview/2708856]

Uptil now I created two canvases- 1. for the word to search 直到现在,我创建了两个画布-1.搜索单词

function drawWords(words){
var c2 = document.getElementById("canvas2");
var ctx2 = c2.getContext("2d");
ctx2.fillStyle = "green";
ctx2.font = "bold 20px arial";
for(i=0,j=40; i< words.length; i++,j+=30)
{
ctx2.fillText(words[i], 70, j);
}
}

2.for the grid.The grid was drawn by drawing small rectangles to cover entire canvas 2.对于网格,通过绘制小矩形以覆盖整个画布来绘制网格

function drawRect(){
var c1=document.getElementById("canvas1");
var ctx1 =c1.getContext('2d'),i,j;
for(i=0; i<405 ;i+=27)
{
for(j=0;j<405;j+=27)
{
    ctx1.rect(i,j,27,27);
    ctx1.stroke();

}
}
}

I have stored the words along with random letters in a grid[15][15] array using javascript.However I have no idea how to print these on my grid canvas and also to link the words with this grid to know correct selection. 我已经使用javascript将单词和随机字母存储在grid [15] [15]数组中。但是我不知道如何在我的网格画布上打印这些单词以及如何将单词与该网格链接以了解正确的选择。 Please help 请帮忙

To print text to canvas, you need to use 要将文字打印到画布上,您需要使用

ctx.font="20px Arial"; //changed to whatever you want
  ctx.fillText("Hello World!",10,50); //in a for loop change hello world with letter 
                                      //the two number correspends to x and y
                                      //do some math and you will find how to fit the letters in the canvas

For testing i think is good idea to store the x and y that you use it to print letters and from where the user has clicked you figure out the x and y of the mouse and make your test 对于测试,我认为存储x和y来打印字母是一个好主意,从用户单击的位置中找出鼠标的x和y并进行测试

sorry for the english :s 对不起,英语:s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM