mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

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

19·601 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 online now   Reply With Quote
Old 2006-02-04, 16:29   #2
Ken_g6
 
Ken_g6's Avatar
 
Jan 2005
Caught in a sieve

6128 Posts
Default

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
 
Mystwalker's Avatar
 
Jul 2004
Potsdam, Germany

33F16 Posts
Default

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
Reply

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 04:17.

Wed Aug 12 04:17:58 UTC 2020 up 26 days, 4 mins, 1 user, load averages: 1.55, 1.97, 2.17

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.