![]() |
![]() |
#1 |
∂2ω=0
Sep 2002
República de California
5×2,351 Posts |
![]()
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? |
![]() |
![]() |
![]() |
#2 |
Jan 2005
Caught in a sieve
5×79 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. ![]() |
![]() |
![]() |
![]() |
#3 |
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. |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
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 |