

Ask HN: How do I best learn Java in order to build a multiplayer game? - DesignerJoel

I have an idea for a project I'm really interested on working on. It's a pretty large mass multiplayer game, based mostly on text with some minimal graphics.<p>I have some coding knowledge, some barely remembered C, slightly more ruby and php, and a bit of processing (which is based on Java, I guess).<p>Basically, I want to start from scratch, but do it right. I don't want to hack this game together, I want to make it work. How would I go about that? Could I do it as I build the game?<p>Also, which aspects of Java, and possibly what other tools would I need to build a multiplayer game? Are there any libraries geared towards this stuff?<p>Thanks!
======
dkuntz2
So have you ever used Java before?

I ask because if you haven't that the logical place to start is with learning
the basics, followed by the building blocks to a multiplayer game.

If I were to start building a multiplayer game (preface: the main language I
write in is Java, due to it being the main language in my high school's cs
classes and my current cs course), I would start with building a really simple
single player game. Start with just the world and one player.

After getting a single player game working (as best you can with just one
player if the game is designed solely for multiple players), start trying to
decouple the world from the gui, start making the world a server and the gui a
client.

After that, you've got most of the pieces you need to start adding more
players.

\----

Additionally, I was in a class where the final project was to create a very
simple multiplayer world. Our process in leading up to that project was simply
working with the individual aspects of the project beforehand and adding it
together for the final.

We started off the class working with graphics, making a ball bounce using
relative gravity on the screen, animating sprites, creating and modifying
images (taking a jpeg with the color white meant to be transparent and making
it transparent on the screen, fading an image in and out, really simple
sounding things that would be used to form the basis of more complex, fun
things).

The second part was mostly networking. Starting with reading and writing text
files (which was done before the graphics, to let us read and write images)
and moving towards sending and receiving text from other machines. One of the
more complex projects in the class started with our teacher building a number
guessing server: his computer would pick a random number from Integer.MIN_INT
to Integer.MAX_INT, and we would have to guess it. The first of the three
projects with the random number server involved creating a simple client that
would have users enter a number. The second part required us to automate the
server. The third had us take the server and add user authentication to it.

After the random number projects, we moved on to sending and receiving objects
over the network, specifically images, and having them show up on another
computer's screen.

All of that lead into the final project, which had us build a server that
received icons from a computer, give each of those icons a position, and track
changes in position. The client for the server would pick an image, send that
image to the server, and move the icon around using the arrow keys. The client
would also display other icons from other clients connected to the server.
Essentially a really simple multiplayer game.

\----

In my current class, there was just an assignment requiring us to use both the
observer and proxy design patterns for a simple blogging application. Using
the observer and proxy patterns would probably be beneficial to you when you
get into the server/client part of the game. I don't really have any good
resources for leaning about those because it was mostly a lecture coupled with
an assignment and lab problem.

\----

I'm not sure if that answered your questions, but I hope it helped give you an
idea of where to start. I also acknowledge that I put down a lot in this
comment, but I personally think it's at least somewhat helpful.

~~~
DesignerJoel
It's very helpful, thanks :) Since I don't have a CS course at my disposal
anytime soon, do you know of any books or online courses that could cover the
basics? I'm not just looking for syntax, but design patterns, as you said.

Thanks again!

~~~
dkuntz2
I would provide you with book suggestions, but as I said, most of what I've
learned is due to lectures and examples.

If you've got to have a book, I've heard that O'Reilly's _Head First Design
Patterns_ is pretty good for the patterns themselves (heard the same for most
of the Head First series). That book uses Java.

As for when I come across a problem, I've found that if you search for your
problem on Google you'll generally get a good result. You could also check out
the Stack Exchange networks, specifically Stack Overflow, try under the Java
tag over there.

While I've never really looked, you might be able to find a nice Open Course
Ware class on learning Java, but again, I don't know if they exist or not.

The documentation for Java is also really nice and fairly easy to understand.

------
liquidcool
It's an ambitious undertaking, but your timing is good. Stanford's Programming
Methodology class is free online and teaches Java:

[http://see.stanford.edu/see/courseinfo.aspx?coll=824a47e1-13...](http://see.stanford.edu/see/courseinfo.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111)

There are many technology specific classes at JPassion.com. It used to be
free, so I'm not sure whether a subscription is required.

As for libraries, there are over 5,300 games written in Java on sf.net:

[http://sourceforge.net/search/?q=&fq%5B%5D=trove%3A198&#...</a><p>I subscribe
to their newsletter and Arianne and FreeCol are often listed as top projects,
so you'll want to check them out.<p>BTW, Steve Yegge did something similar
with Wyvern:<p><a href="http://en.wikipedia.org/wiki/Wyvern_(video_game)"
rel="nofollow">http://en.wikipedia.org/wiki/Wyvern_(video_game)</a><p>I
believe that contained hundreds of thousands of lines of Java. Given his bent
towards dynamically typed languages these days, I don't think he'd do it in
Java again.<p>(Note: I am in no way affiliated with any of the above
resources/people.)

