Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // Creating variables
  2. var socket = io();
  3.  
  4.  
  5.  
  6. var grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
  7. for(var x = 0; x < 3; x++){
  8. grid[x] = [];
  9. for(var y = 0; y < 3; y++){
  10. grid[x][y] = 2;
  11. }
  12. }
  13.  
  14. function update() {
  15.  
  16. }
  17.  
  18. function draw() {
  19. for(var x = 0; x < 3; x++){
  20. for(var y = 0; y < 3; y++){
  21. if(grid[x][y] == 1){
  22. context.fillStyle = "blue";
  23. }else{
  24. if(grid[x][y] == 2){
  25. context.fillStyle = "red";
  26. }else{
  27. context.fillStyle = "black";
  28. }
  29. }
  30. context.fillRect(x * 100, y * 100, 99, 99);
  31. }
  32. }
  33. }
  34.  
  35. function keyup(key) {
  36. }
  37.  
  38. function mouseup() {
  39. console.log(Math.floor(mouseX/100), Math.floor(mouseY/100));
  40. socket.emit("kliknato", "ala balanica")
  41. }
  42.  
  43. socket.on("nqkoi natisna", function(x, y){
  44. console.log('nqkoi natisna', x, y)
  45. });
  46.  
  47. //server.js
  48. var app = require('express')();
  49. var http = require('http').Server(app);
  50. var io = require('socket.io')(http);
  51.  
  52. app.get('/', function(req, res){
  53. res.sendFile(__dirname + "/start.html");
  54. });
  55. app.get('/game.js', function(req, res){
  56. res.sendFile(__dirname + "/game.js");
  57. });
  58.  
  59. //kod moje da se pishe tuk
  60. //pri startirane se izpulnqva tova
  61. io.on('connection', function(socket){
  62. //изпълнява всеки път като се свърже клиент - socket e тръбата за комуникация с точно новосвързания клиент
  63. console.log("nqkoi sa vyrza iai");
  64. socket.on("kliknato", function(x, y){
  65. console.log("doide kliknato s informaciq", x, y);
  66. io.emit("nqkoi natisna", x, y);
  67. });
  68. });
  69.  
  70. http.listen(3000, function(){
  71. console.log("server started");
  72. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement