Below a very simple example of OOP. Note that it doesn't have any getters or setters for the sake of keeping the example short. If you get the idea of the code below then you can start building a lot more complex OOP.
Maybe the newbies forum might have been better for this post. If you are really looking for game sources then the thread about the 4K games have some links to source codes (maybe not textbook examples of OO usage).
public class DaGame
{
public static void main(String args[])
{
new DaGame().run();
}
public void run()
{
Player p1 = new Player("Jack", 1);
Player p2 = new Player("Jones", 2);
if(p1.score > p2.score)
{
System.out.println(p1.name + " is the winner!");
}
else if(p2.score > p1.score)
{
System.out.println(p2.name + " is the winner!");
}
else
{
System.out.println("we have a draw! Play again.");
}
}
}
class Player
{
public String name;
public intscore;
public Player(String name, int score)
{
this.name = name;
this.score = score;
}
}
Make so:
import java.util.Random;
////////////
public void run() {
Random random = new Random();
Player p1 = new Player("Jack", random.nextInt(10));
Player p2 = new Player("Jones", random.nextInt(10));
That will be more funny! :)
Let the excitement begin:
import java.util.Random;
////////////
public void run() {
Random random = new Random();
Player p1 = new Player("George Bush", random.nextInt(10));
Player p2 = new Player("John Kerry", random.nextInt(10));
how about a very simple mmorpg with fully 3d graphics, without using the java 3d api, as an applet. Then you could add functions for rotation, as well as having hundreds of thousands of randomly generated items, each with its individual picture. You could have the landscape generated individually for each person, but have everyone together (dont ask me how that will work). Then, you could deploy it on your own web site and make millions of dollars.
adam, my RPG is 3D (sort of ;) ) and will be multiplayer when my brother gets done dorking around with other stuff and comes to help me impliment that. However, I am designing random map capability and I've genericized the creation of items for the ability to make random items that do many different things. Now that I've got a start, think I can get part of that million bucks? I'll take a 20... :)