Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creating variables
- var goleminaX = 7, goleminaY = 7;
- var pole = [];
- var igrachNaHod = 1;
- for(var i = 0;i < goleminaX;i = i+1){
- pole[i] = [];
- for(var j = 0;j < goleminaY;j = j+1){
- pole[i][j] = 0;
- }
- }
- function update() {
- }
- var drawGolemina = 55;
- function draw() {
- for(var x = 0;x < goleminaX;x = x+1){
- for(var y = 0;y < goleminaY;y = y+1){
- if(pole[x][y] == 1) {
- context.fillStyle = "red";
- context.fillRect(x * drawGolemina, y * drawGolemina, drawGolemina, drawGolemina);
- }
- if(pole[x][y] == 2) {
- context.fillStyle = "blue";
- context.fillRect(x * drawGolemina, y * drawGolemina, drawGolemina, drawGolemina);
- }
- context.strokeRect(x * drawGolemina, y * drawGolemina, drawGolemina, drawGolemina);
- }
- }
- };
- function keyup(key) {
- // Show the pressed keycode in the console
- console.log("Pressed", key);
- };
- function mouseup() {
- // Show coordinates of mouse on click
- console.log("Mouse clicked at", mouseX, mouseY);
- var idxX=0;
- for(var tekustoKv = 0;;tekustoKv ++) {
- var tekX = tekustoKv * drawGolemina;
- if(tekX > mouseX) {
- idxX = tekustoKv-1;
- break;
- }
- }
- for(var i = goleminaY - 1;i >= 0;i --) {
- if(pole[idxX][i] == 0) {
- pole[idxX][i] = igrachNaHod;
- if(igrachNaHod == 1) {
- igrachNaHod = 2;
- } else {
- igrachNaHod = 1;
- }
- break;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement