Jump to content

Multiplayer, simultaneous playing, multiple rooms. CHESS!


bilis_money

Recommended Posts

I'm planning to create a PHP CHESS games mix with AJAX i guess.

 

Where people can play simultaneously with multiple chess rooms.

 

and now i dunno where to begin with this.

 

I have no idea about the structure of the database.

 

Anyone out there knows or can share me a link or article for this type of database and has the same logic CLASS structure.

 

Thank you.

 

 

 

 

 

Link to comment
Share on other sites

You sure you want to use PHP & JAX for this? Wouldn't it be wiser to attempt this with AS3.0 & Flash, or Java, etc..?

 

I wouldn't know what to tell you about the DB, but I certainly wouldn't be attmepting it the way you are.

 

Good luck though.

Link to comment
Share on other sites

my friend unsider

 

i'm very aware of that.

 

in fact i'm was playing for more than 4 years on this site.

http://www.gameroom2000.com/multiplayer-games/chess.htm

 

i think they used java or flash.

 

i know it will be easier for those languages.

 

but don't you like, if we have it also under PHP & AJAX.

 

Since we have ajax i'm sure this is very possible.

 

anyone would  like to share?

 

thank you.

 

 

Link to comment
Share on other sites

For something like chess I would not recommend flash or Java, unless for some reason you wanted to focus on making it really flashy with lots of animation or whatever.  If you're just looking to have a top view checkboard with little thumbnail pieces that dynamically move around onclick (or whatever), it would be way better to just use ajax.  You're going to have to make use of a flatfile or database anyways (even if you go the flash or java route), in order to pass information back and forth between users. 

Link to comment
Share on other sites

Hrmmm...  Before I post what I would do, I would like to remind you that I suck at OOP, and my way is often not the best way (but trying helps me learn ;p).

 

Oh, and I'm going to do it C++ prototyping style.

 

class Chess_Board {
    private $board_id;
    private $pieces;
    private $whose_turn;
    public void function __construct($board_id); //basically pull data from the DB in here

    public bool function IsValidBoard(); //make sure everything loaded, and the board exists and what not

    public bool function IsPlayer(); //make sure the player is one of the players on this board

    public bool function MovePiece($player, $piece, $new_x, $new_y); //make sure it's the player's turn and the move is possible, and if it is, move the piece.  Also, the turn switching would happen in here.

    public bool function CommitData(); //take the variables, and re-store them in the DB

    void __destructor(); //Run CommitData if it's yet to be run.
}

 

 

You would of course need other methods (one to get the chess pieces from $pieces, for example), but that's essentially how I would do it.  Then the code (in the AJAX handler) could be like:

 

(I might actually use an OOP-style controller, but this is what I would see as the bare minimum.)

 

<?php
session_start();
//this assumes that the AJAX call passes something like ?board_id=1&act=move&piece=1&new_x=3&new_y=5
$board_id = (isset($_GET['board_id']) && ((int) $_GET['board_id'])) ? $_GET['board_id'] : false;
//make sure to do something if board_id is false
$act = (isset($_GET['act'])) ? trim($_GET['act']) : null;
$player_id = (isset($_SESSION['player_id'])) ? $_SESSION['player_id'] : false;
//make sure to do something if player_id is false

if($act == 'move') {
    $piece = (isset($_GET['piece'])) ? $_GET['piece'] : null;
    $new_x = (isset($_GET['new_x'])) ? $_GET['new_x'] : null;
    $new_y = (isset($_GET['new_y'])) ? $_GET['new_y'] : null;
    //Chess_Board::MovePiece can make sure this is valid.
    $board = new Chess_Board($board_id);
    if($board->ValidBoard() && $board->IsPlayer($player_id)) { //this could probably be handled better, since it seems pointless to load all of the board data before checking if the player is valid
        if($board->MovePiece($player_id, $piece, $new_x, $new_y))
            echo '1';
        else
            echo '0';
    }
}
else if($act == 'something else') {
    
}
else {
    //unexpected act....
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.