Go Back > Extra Stuff > Programming

Thread Tools
Old 2006-02-02, 01:51   #1
ewmayer's Avatar
Sep 2002
República de California

11,399 Posts
Default JavaScript for 2-player interactive game-playing?

One of my mini-projects over the recent Christmas holidays was to teach myself the basics of JavaScript in some way that might prove fun as well as useful. To do this, I coded a simple chess GUI that allows one to point and click to move pieces, checks legality of moves, highlights when a player's king is in check or a player leaves a piece unprotected, allows move-takeback, and so forth. Nothing fancy, but a fun exercise nonetheless.

What I'd like to do next - and I don't know if JavaScript supports this, that's why I'm asking - is to allow 2 players to play each other online. To do that, I need some way to tie the window input to each of 2 IP addresses (one for each player), and into the code for piece selection and moving - e.g. when it's black's turn to move, only black can move the mouse and click to select a piece to move. Does JavaScript support this sort of thing?
ewmayer is offline   Reply With Quote
Old 2006-02-04, 16:29   #2
Ken_g6's Avatar
Jan 2005
Caught in a sieve

39410 Posts

Well, I don't think Javascript supports being a server, especially from within a browser. So you would need a (small) backend server to allow the two players to communicate. But beyond that, I think AJAX would work for you. Basically, each client would probably have to send a move to the server, via an XMLHttpRequest (or the equivalent IE6 method), and then periodically check to see if the other player made a move.

Fair warning: I haven't actually tried any AJAX yet.
Ken_g6 is offline   Reply With Quote
Old 2006-02-04, 19:22   #3
Mystwalker's Avatar
Jul 2004
Potsdam, Germany

3×277 Posts

Actually, the "asynchornous" in Ajax means that one does not need to periodically check for new information.
You just have a function that gets called due to a message arrival for handling it...

I also have next to no knowledge when it comes to Ajax, neither. But I'd first make sure whether there are game/P2P-communication - related frameworks already available. Asking resp. questions in a programming-centered forum might help - this subforum typically is about math-related programming discussions in my experience.
Mystwalker is offline   Reply With Quote

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting applets to Javascript alpertron Programming 61 2019-04-21 00:15
ECM success/failure probability graphs, the interactive online version! WraithX Math 0 2018-01-13 17:41
Göogle's AlphaGo AI is playing Lee Sedol (~ the best human Go player) Dubslow Hobbies 11 2016-06-02 12:29
A CD player from scratch Orgasmic Troll Puzzles 31 2012-09-12 21:47
Sun Tries to Get Hip to JavaScript ewmayer Programming 1 2006-10-07 21:23

All times are UTC. The time now is 09:45.

Sat Aug 8 09:45:35 UTC 2020 up 22 days, 5:32, 1 user, load averages: 1.67, 1.98, 2.03

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.