Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Board Game  (Read 2277 times)
0 Members and 1 Guest are viewing this topic.
Offline bigdaddy123

Senior Newbie




Java games rock!


« Posted 2005-05-21 00:39:58 »

I am new to Java.  I have been reading for a couple of months now and decided to build a board game with marbles and dice. I would like to use this game on my personal website just for personal use, so it shouldnt have alot of traffic.  Here is my question, I have started building the game and have the graphics layed out and have an animated dice to retrieve a random number when clicked and am preparing to add the game pieces (marbles). Can I build the applet with all the game logic included so that each client will have a fully functioning game and then just build a server page to forward events to each client as they happen. or is it way more complicated than that.  I bought a book on networking but it is cluttered with so much stuff to handle many players (playing, watching, waiting to play, etc.) that I wonder if for something like this it might be simpler. Thanks
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #1 - Posted 2005-06-03 07:47:03 »

I am not so sure on what you exactly want to do on your server? The less the server does,
the easier it is to implement!

Generelly, I agree, most books go way too far into details! Don't worry about it. All you need
is the most simplest example you understand, and you build on top of that! That's what I
always do. I built a realtime & turn-based networked game with that approach and didn't
have any major problems.

What I would do:
1. build your game excluding the client-server part at first, however having it in mind so you
    can easier add it later.
2. Take the simplest example you find and understand in networking and add it to the game.
    E.g. send a text from the client to the server and check if it works! Once you get that to work
    you can add functionality ...

Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-06-10 20:39:39 »

Thanks for the response. I have done as you suggested. The game is a 4 player game and is fully functional on one computer. It rotates the veiw of the board when players change.  I have 16 marbles on the board and they each have an x,y coordinate. when the player changes it updates these coordinates and repaints.  I need a way of exchanging these 16 points among the four applets. Its a slow paced game so I even thought about using mysql database as a means to hold these 16 points. but couldnt get that to work.  I think I need a servlet to contain these 16 variables but I have no experience with servlets.  I just subscribed to a new host that supports servlets. They told me to make my own WEB-INF & classes folders.which I did. They said to request a reload after changes. Do I need to request a reload everytime I add or change a file?  Also Im not sure how to deploy a servlet. I know the servlet will have to be listening for a connection from the applets. Thanks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2005-06-12 08:10:44 »

Okay,

Yo ucertainly CAN do this with a servlet for such a  slow paced game.  Every turn you would post each players update and keep the conenction open waiting for a response.  When the servlet has everybodie's inptu it sends the responses to all.

HOWEVER this is a lot fo work to do for somethingf so simple.  Does this game have to work over HTTP or can you simply open sockets to  a little Java server program?

In the simplest architecture, the serevr simply keeps tack of al lthe player sina  single game session and sends each play the Ips of the other players-- then they conenct directly and do all thier message passing straight to each other.

Note however  that an Applet cannot contact any machien other then the machine it w as served from unelss it is signed.  Thsi is one fo many reasons why applets are a  pain and Java Web Start plus an App is a much easier way to go.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #4 - Posted 2005-06-12 20:24:12 »

Hey Jeff, thanks for the reply.  I think the socket would be best, Im just having a problem understanding how to build the server and start it.  The applet has a multi dim array containing the x y coordinates of all 16 marbles ( balllocation[][])  This is the only info i need to exchange other than who's turn it is and maybe a few other things like when someone wins.  This game is strictly private on my website so It doesnt need any kind of "choose a table" interface or anything like that. 
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2005-06-13 01:42:53 »

Okay,

How familair are you with inetrnet sockets?  These are your fundemental communication mechanism.
If this is all brand new to you maybe we can dig up a reference.

By teh way i am assuming this is an internet game.  If ist a Lan-only game then I have pre-written
communciation code you could just grab out of "Practical Java Game Programming."

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #6 - Posted 2005-06-13 01:59:19 »

yes it is an internet game.  The game is now a fully functioning game applet.  I have done alot of reading on sockets and I think I understand the way the sockets work. My biggest question is the format of the serverside. I dont know how to build it. If I could build it as an applet and name the variables and put default values in init() and then use sockets to change the values of those variables and have the client applets update off of the main applet on the server. But I assume you cant use an applet as the server.  I think Im just missing the basic structure of the server.
Offline woogley
« Reply #7 - Posted 2005-06-13 02:15:08 »

I've built many network games (multiplayer pong and such), but the difference is it was on a LAN. LAN isn't too much different from Internet (in the end its all a Socket, basically), but the host computer that runs the server can be a deciding factor.

For local network games, having one of the computers on the network run the server like a normal java app is the easiest way to go. However if you're using a webhost such as geocities or something similiar, they probably don't allow you to run a java app on their side (and they probably dont even have a JRE in the first place). In fact if you read end-user agreements, most hosts say they forbid a custom server of any kind to run on their servers.

So if you don't have physical access to the computer that runs your game server, I don't know how you can accomplish this except through a dynamic server. What I mean by "dynamic server" is one of the clients can also act as the server.. so the first person who logs into your game becomes the server and waits for more players. The players that come connect to the first player (you'll need to sign the applet for this) and use the first player as the server. However there are SEVERAL pitfalls to this and is VERY inefficient. If the "first player" is on a dialup, the whole game is slow! Plus the whole game would have to reset if the "first player" disconnected...
Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #8 - Posted 2005-06-13 02:37:51 »

So what your saying is internet based multiplayer games are difficult to build?  How about using mysql to hold the x y coordinates of the marbles on the gameboard?  Can an applet write to a database?  Then the clients could query the database to update their board.
Offline woogley
« Reply #9 - Posted 2005-06-13 21:40:54 »

So what your saying is internet based multiplayer games are difficult to build?

Well they CAN be tricky to build, but I wasn't talking about that Wink I was saying it would be difficult to create an actual server (in the form of a Java app) because most webhosts don't let you run system commands (and like I said, their computers might not even have a JRE).

How about using mysql to hold the x y coordinates of the marbles on the gameboard? Can an applet write to a database? Then the clients could query the database to update their board.

This could be possible however it will use alot of bandwidth. Instead of the server telling the applets something has changed, the applet has to query the database over and over even if their is no change. What you might have in the database is a "modified date" variable for the applets to check. This way the applets would only query the board data when the "modified date" has change since the last modified date. Again the applets will be needing to check this quite often because the server can't notify the applets directly of any change.

I don't know how to get applets to query a database. I know there is a JDBC API you can use, however I'm 99% sure you need to sign your applet to use it. You will also need to find a JDBC driver to connect to a MySQL database. Try googling JDBC Smiley

If you can manage to have your applet query a database, then you can make a simple board game like this work. But unless you could run an actual custom server (as a java application), you won't be able to do things like MMORPGs because there's just too much data flying around (active chat, player movements, etc.).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #10 - Posted 2005-06-13 23:57:51 »

Okay I thiun ki need to udnerstand your constraints better.

What kidn of network resoruces do you have?  Do you have a machine that is connected to the internet and on full time that you can run your server on?

If so this is realtively simple.  If, on the other hand, all you have acess to is a "client" machien that is only turned on and connected while yo uare usign it, it gets a lot trickier.  Its worth noting that all professional game develoerps who do internet based games have such serves of their own either
on their own premises or rented in a "co-location" facility.

If you dont have acess to such a server then yo uare froced to deploy your serve side content in a form that a hosting rpovider will be willign to run for you.  The problem tehre is that such content is VERY limited i nwhat it cna be and do by the provider for security reasons.   In this case you are pretty much forced to use servlets or EJBs and do your communication over HTTP.  Thats a lot more work, frankly, to write.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #11 - Posted 2005-06-14 18:30:20 »

WOW this is kind of discouraging. After all the hours I put into building the applet.  I am using a web host that I pay for every month so It looks like the database is my only option then.  Can an applet even write to a database?  I was researching that on Google and found a post that said you could not so I dropped that idea and started looking into sockets. It just seems there ought to be a way to transfer a few variables from an applet to a page on the webhost and then a way for an applet to retreive a variable from that page. Anyway I guess I'll look into the mysql again.  I think the modified date thing sounds good. Then It wouldnt have to read the whole 16 entries every time. Just one unless it has changed. (is that what you were saying?) Thanks
Offline me

Senior Member


Projects: 4


Java games rock!


« Reply #12 - Posted 2005-06-15 06:34:02 »

Hi Big Daddy,

Below method + php script shows how to work with a mysql database. I use this method for my 'board' game.
To use the mysql/php/applet technique it saves a lot of costs by using a standard ISP contract rather than
buying/renting a dedicated server.


The URL that is executed includes the variables using the ?var=val&var2=val2 method. You could include URLEncoder.encode function when using strings as values to allow non URL characters like spaces.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
public String execute(String php){
   String retval="";
   String inputLine;
                     Date d=new Date();   // use seconds to ensure
           // the URL is not cached by
           // proxies ....
  try{
      // Server is a global variable obtained by
     // applet.getCodeBase().toString();
     URL Url = new URL(Server+php+"&dummy="+d.getTime());
      URLConnection uc = Url.openConnection();  
      BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
            while ((inputLine = in.readLine()) != null){
                   // Script is executing
             // catch output (result of php-script)
                   retval+=inputLine;
                } // while
  }catch(Exception ef){
System.out.println("Error getting result from: "+php+" : "+ef.toString());
               retval="";
        }
        return retval;
}



Calling the execute method:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
String result=global.execute("getonline.php?usernr="+global.usernr+"&othervar="+global.othervar+"&time="+date.getTime());
 
if(result.length() > 0){
   try{
        sn=new StringTokenizer(result, ""+(char)18);
        while(sn.hasMoreTokens()){
                  multilist.add("Team"+sn.nextToken());
        }
    }catch(Exception egge){
      //catch
    }
}



The getonline.php code :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
<?php
   // Some db initialization

        $usernr=$_GET['usernr'];
   $somevar=$_GET['othervar'];
 
   $query2="SELECT team FROM rooms WHERE  user!=".$usernr;
        $result2=mysql_query($query2, $db);
        while($myrow2=mysql_fetch_row($result2))
                        echo $myrow2[0].chr(18);
 
?>


Hope this helps!

Regards from
ME

http://www.mazeland.net   Multiplayer  Puzzle Game

M.E.
--------
Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #13 - Posted 2005-06-15 20:00:55 »

Thanks for the reply,Me
this looks like what I might be looking for. I have to go to work now and i'll need some time to study the code you posted to see if i understand it. I'll get back with you when I look at it. (im sure ill have some questions) Thanks bigdaddy
Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #14 - Posted 2005-06-15 22:36:00 »

ok I think I have an understanding of this script. A few minor questions but first let me ask you this.  This game is a four player marble game. The script you have above would allow each player to get x,y coordinates of all the marbles on the board. However when a player moves his marble how will he write the new x,y coordinates to the database. Can an applet do that through php also?
Offline me

Senior Member


Projects: 4


Java games rock!


« Reply #15 - Posted 2005-06-16 08:15:18 »

Hi Big Daddy,

The example indeed retrieves something from the database using php. But you can use all php & mysql commands you wish. So writing to the database is done by using UPDATE or INSERT  .  Your main problem will be to keep track of crashing connections so that a player which has left doesn't hold up the game. (When his computer has gone down abrubtly)
But I would suggest that you first determine which user 'has  the board'. Afterwards you can implement a kind of heart-beat
implementation so that you can delete database entries of users who have gone away.

Hope this helps a bit more!

Regards from M.E.

www.mazeland.net Multiplayer Puzzle Game


M.E.
--------
Offline bigdaddy123

Senior Newbie




Java games rock!


« Reply #16 - Posted 2005-06-26 00:32:07 »

Thanks ME, I tried the php database thing. And all seems to work fine. I have some other issues Im working out but don't think it is related to that.  Thanks again, Bigdaddy
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (21 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (87 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!