Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creating variables
- var socket = io();
- var grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
- for(var x = 0; x < 3; x++){
- grid[x] = [];
- for(var y = 0; y < 3; y++){
- grid[x][y] = 2;
- }
- }
- function update() {
- }
- function draw() {
- for(var x = 0; x < 3; x++){
- for(var y = 0; y < 3; y++){
- if(grid[x][y] == 1){
- context.fillStyle = "blue";
- }else{
- if(grid[x][y] == 2){
- context.fillStyle = "red";
- }else{
- context.fillStyle = "black";
- }
- }
- context.fillRect(x * 100, y * 100, 99, 99);
- }
- }
- }
- function keyup(key) {
- }
- function mouseup() {
- console.log(Math.floor(mouseX/100), Math.floor(mouseY/100));
- socket.emit("kliknato", "ala balanica")
- }
- socket.on("nqkoi natisna", function(x, y){
- console.log('nqkoi natisna', x, y)
- });
- //server.js
- var app = require('express')();
- var http = require('http').Server(app);
- var io = require('socket.io')(http);
- app.get('/', function(req, res){
- res.sendFile(__dirname + "/start.html");
- });
- app.get('/game.js', function(req, res){
- res.sendFile(__dirname + "/game.js");
- });
- //kod moje da se pishe tuk
- //pri startirane se izpulnqva tova
- io.on('connection', function(socket){
- //изпълнява всеки път като се свърже клиент - socket e тръбата за комуникация с точно новосвързания клиент
- console.log("nqkoi sa vyrza iai");
- socket.on("kliknato", function(x, y){
- console.log("doide kliknato s informaciq", x, y);
- io.emit("nqkoi natisna", x, y);
- });
- });
- http.listen(3000, function(){
- console.log("server started");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement