Complete beginner: Creating Card Game program

I am brand new to object oriented programming, i'm trying to write a simple card game program, without using arrays or importing packages or vectors (whatever they all are?). can someone please help me?

First of all, arrays are a very good idea, as are other datastructures such as the hashtable. But you can also use a String, which is basically an array of characters.
The initial hurdle you will have in writing a card game will be modelling a single playing card. Your program will likely understand the sequence of cards as 2,3,4,5,6,7,8,9,10,11,12,13, even tho you will want to present this to your user as 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A. Computers deal well with the numbers, Humans like to refer to cards using the familiar symbolic references (J, Q, K, A). Suits likewise will probably be stores as integers (0-3).
Your program will have to determine whether one playing card is less than or greater than another, whether it is in the same suit, what value the card will have (for BlackJack, for instace). All of these behaviors can be engineered into your PlayingCard class.
To get going with your card game, you must thus begin an abstraction of the real-word PlayingCard. Start with a class such as this:
class PlayingCard {
final static String nums = "234567891JQKA" ;
final static String [] suits = "DCHS";
private int num, suit; // i.e. of this instance
public PlayingCard (String card) { // constructor
num = values.indexOf(card.charAt(0)) ;
suit = suits.indexOf(card.charAt(card.length()-1);
public String toString() {
return nums.charAt(value)+((num==8)?"0":"")+suits.charAt(suit);
int value() { return suit*4+num; }
boolean compareValue(PlayingCard first, PlayingCard second) {
return first.value() - second.value();
boolean sameSuitAs(PlayingCard p) {
return (this.suit == p.suit);
// etc.
For a BlackJackPlayingCard, extend PlayingCard and add/override specific behaviors such as counting (i.e. face cards = 10, Ace's two values, etc).
Have fun. Java is a great language.

Similar Messages

  • Multiplayer game programming - Code of a basic server

    I'm a beginner in multiplayer game programming and I'm looking for the code of a basic server for a multiplayer game. I don't mind which kind of game (I mean: chess, ping-pong, battlenet...) The important thing is the code pattern abnd the server structure.
    Could anyone help me?

    If you want to have a look at a generic multi-threaded server, check out the Java networking tutorial.. there's a basic example server that responds to a "Knock knock, who's there?" conversation.. you can start off with it..
    Of course it's not a game server but you could try sticking in a game engine to maintain the game world and change the user sessions to a proper game protocol.. e.g. sending key strokes or joystick movements. You could also get the server to send player and enemy positions etc...
    Good luck!

  • I upgraded to Lion OS and now my Hoyle card game will not work.  Any suggestions.  I already tried re-installing.

    I upgraded to Lion Os about 3 months ago.  I have a Hoyle Card Game program and it no longer will open.  I did try and re-install it and it still stalls at opening.  I can hear the sound but the picture doesn't start.  Computer locks up additionally.  Anyone have any suggestions?

    Try your Windows DVD.

  • Creating cards for a card game

    So I'm playing with the idea of putting together a simple battle card playing game and am running up against a data/code issue. In the game will be various Cards (potentially hundreds). Each card will have some data describing various its strengths and it may also have complex methods that handle what happens when you play the card.
    (I'd like each Card implementation to represent what the card does, as opposed to who may hold a particular copy of it. For example, I'd like to have a unique JackOfDiamondsCard object that represents info specific to the card. I may then have several Hands that contain CardInstance objects, some of which may have a reference to the unique JackOfDiamondsCard object. Thus the JackOfDiamonsCard could appear in multiple hands.)
    At first glance it's a simple case of having a root Card class and hundreds of children that fill out the details. However, this has the problem that I can create many instances of the same card, which both seems like a waste of memory (since all instances would have exactly the same data) and would make equals() and hashCode() give different results for different instances of the same card.
    One way around this is to put all the cards together into a single enum, but that would quickly grow to an unmanagable (and unreadable) size. I'd also like to be able to group the cards into different packages, or maybe even spread them across several jars.
    Another way may be to turn each card into a singleton and then build an index of all the cards in the jar (maybe using @annotations?) This seems kind of complicated, though, and writing all those singletons would make for a lot of boilerplate in each card class.
    Any ideas on a good way to tackle this? Are singletons the way to go or should I put up with potentially multiple copies of the same card object floating around?

    Mark_McKay wrote:
    The problem is that I need the overriding classes to provide some fairly complex code for each card. In a battle card game, there may be several different things in play that each card could alter in a wacky way. One card may give the player more 'energy points'. Another may strike the opponent with lightning damage. A third may cause one player to randomly steal a card from the other player. A fourth could set up some sort of defense barrier. The wide (and unpredictable) range things that each card may do prevent me from creating just one generic card class. (Although that would work well if the cards only differed by their data).Allow me to introduce some friends of mine. Probably the first one is going to be easiest for you to understand and get working quickly. The last one, probably only any use in conjunction with one of the others here.
    This wacky behaviour is really just another property of the card, like it's suit, or name, or whatever. Behaviours, like data, can often be assigned to objects at runtime, rather than expressed with unweildy inheritance trees.

  • Create a cross platform online Card Game

    How would I go about creating a cross platform online card game. An example of such an application is one I found where people can play the "Magic the Gathering" card game online and I was wondering how to go about creating a graphic interface where players could upload the images of cards and move them freely around the screen. There would not need to be any rules for the game. It would only need to be able to shuffle a deck and count how many cards are left in the deck and the discard pile.

    I agree just installing the application would be the best option however one of the requirements of this is that it can run from the CD as we are going to be distributing some promotional material in the form of a flash application and would like to have run on either windows or mac without needing to require the users to have to choose the version.

  • Need some OO design pointers for a Java card game I wrote for uni

    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
         private int value;                    //variable for the value of the card
         private int suit;                         //variable for the suit of the card
         private ImageIcon frontOfCard;     //Displays the image of the front of the cards
         private ImageIcon backOfCard;          //displays the image of the back of the cards
         public Card (int Value, int Suit, ImageIcon front, ImageIcon back)
              value = Value;               
              suit = Suit;               
              frontOfCard = front;     
              backOfCard = back;
              setIcon(backOfCard);     //To make it non-visible when dealt
         }As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    Card class
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instance
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.
    AI Class extends Player Class
    GUI Class
    Deck Class <-- contains 52 cards
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    Any help on this would be greatly appreciated!
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.

    Faz_86 wrote:
    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    Admirable, and the best way to learn, doing something that interests you.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    Do a quick Google on the model view controller pattern. Your listeners are your controllers. Your JPanel, JButton, etc. are your view. The AI, Player, Card and Deck (and presumably something like Score) are your model. Your model should be completely testable and not dependent on either the controller or the view. Imagine you could play the game from the command line. Get that working first. Then you can add all the bells and whistles for the UI.
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
    (redacted)
    As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.Extending JPanel is fine. As you noted, you need something to add listeners to. However, I would separate things a bit. First, a card really only has a rank and suit (and perhaps an association to either the deck or a player holding the card). The notion of setIcon() is where you are tripping up. The card itself exists in memory. You should be able to test a card without using a UI. Create a separate class (CardPanel or something similar) that has a reference to a Card and the additional methods needed for your UI.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    I am not an animation buff, so I will assume the above works.
    Card classRemove the UI aspects to this class, and I think you are all set here.
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instancePresumably this is where main() resides. It will certainly have a reference to model classes (player, game, deck, etc.) and likely the master JFrame (or a controller class you create yourself).
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.Does a player really have multiple hands? It seems to me more of a one-to-one relationship (or a player has a one-to-many relationship to Card).
    AI Class extends Player ClassWhy extend Player? Create a Player interface, then have a HumanPlayer and AIPlayer implementation. Common parts could be refactored out into either a helper class (delegation) or AbstractPlayer (inheritance).
    GUI ClassMy assumption is that this class has a reference to the master JFrame.
    Deck Class <-- contains 52 cards
    Yes. You may end up recycling this class such that a Deck can also function as a Hand for a given player. If there are differences between the two, create an interface and have a Hand and a Deck implementation. Coding to interfaces is a good thing.
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?You need to pass a reference to the appropriate view class. That is how MVC works. The controller receives a request from the view, dispatches to some model functionality you write (such as GameRulesEngine, Deck, etc.) and returns a result to the view (which could be the same view or a different one, imagine someone clicking 'high scores').
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    That is up to you to write the animation code. In principle, you have a mouse listener, and then you take the appropriate rendering steps.
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    See above.
    Any help on this would be greatly appreciated!
    You are welcome.
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.No, you have been doing fine.
    - Saish

  • Best bridge card game for Mac

    I'm looking for a really good Bridge (card game) app to play against on the computer and learn the game. Anything out there that works with Leopard?
    Also, a good online site would be great as well. Thanks!

    Having tried a number of bridge programs over the years, I have yet to find one that bids and plays well enough to let even a beginner learn about the game. I understand there are some PC versions that are somewhat better, but not one Mac program.
    If I may suggest, however, playing online with other people who are interested in learning is a much better way to go about it, plus it is much more social. [OKBridge|http://www.okbridge.com] is an online bridge club that has been around since [1990|http://www.okbridge.com/new-signup/deployed/about.php] (yeah, it's about as old as the Internet) and has 13,000 members all over the world. I've played at tables with players from four different continents! There are complete beginners and world champions, and a wonderful friendly atmosphere.
    Sad to say, [Pogo|http://www.pogo.com], while free, does not have the same ability to sustain a beginner. You can play, but be prepared to endure frustration. I play chess and backgammon on Pogo, but the bridge rooms are sorely lacking, and the level of play is terrible.

  • Java Card Game (Carioca)

    Hi everyone.
    Im currently making a card game in java for a south american game called Carioca
    originally i had
    CariocaController, which controlled game logic such as creating cards and players, dealing the cards setting the cards etc.
    btnStartGame in GUI would run controller method startGame which would initialize everything then set the GUI.
    CariocaTablelGUI, which extended JFrame and set the game GUI by using swingcomponents (JButtons with ImageIcons for cards)
    Card, like it says, card suit, no and value
    Deck, which created an ArrayList<Card> + 2 jokers.
    Pile which extended ArrayList<Card>. (Used for creating the 2deck game, player hands, putdown pile)
    Ive never been to good with GUI's and not enjoying my inopropriate gui structure i decided to read about java game designs.
    I read OReilly Killer Game Programming in Java chapters 1-13 before it got into 3d java. and not feeling it provided the examples i needed i went back to my old book
    Deitel & Deitel How to program Java Fifth edition. which has a case study of ElevatorSimulation which uses the Model View Controller design pattern.
    I have used this simulation as my guide to reform my code structure as i want to create this game as proffesionally and efficiently as possible.
    Now i have.
    CariocaTable which extends JFrame and in its constructor;
              // instantiate model, view and ,controller
              model = new CariocaModel();
              view = new CariocaPanel();
              controller = new CariocaController(model);
              // register View for Model events
              model.setCariocaListener( view );
              add(view, BorderLayout.CENTER);
              add(controller, BorderLayout.SOUTH);CariocaPanel in it has 4 player panels (4 player max game) which would contain their hands. then a center panel which contains the pickup and putdown piles.
    I am having alot of trouble implementing this pattern to my game (mybe im on the wrong track).
    the controller (in the ElevatorSimulation ) has 2 buttons which executes model method addPerson, thats about all the controller does which rocks my understanding.
    the model implements ElevatorSimulationListener (which extends all needed listeners) and has private variabels for all listeners.
    it then has a setElevatorSimulationListener(ElevatorSimulationListener listener) which is set with the view class.
    i have trouble understanding the communication between controller-view and model-view.. controller has to go threw model to talk to view but model only talks to view through listener methods
    public void lightTurnedOff( LightEvent lightEvent )
    //variable lightListener is the view.
          lightListener.lightTurnedOff( lightEvent );
       }i dont know where all the logic should go. i currently have model with the startGame method which creates players and cards, deals cards etc.
    am i on the right track. am i misunderstanding the design pattern? im sorry for the lengthy post, im having trouble understanding this and would like assistance with my understanding or even refer me to a book or website the would be helpful. if u would like more information please do ask.

    morgalr wrote:
    OK, I'll make a few assumptions and you can correct me if I am wrong on any of them:
    1 - the game is for 1 person to play against the computer
    2 - you may want to expend to multiplayer at some point
    3 - you would like to have the structure of the game as modular as possible to allow changesThank you for replying, yes thats exactly right.
    My approach now is to maintain the same structure as before instead of using the ElevatorSimulation as a guide.
    CariocaController will contain game logic and the static main method, and will update CariocaTable threw set methods.
    i will keep the revamped GUI classes, using what ive learned about using 2d instead of Swing Components, ive created an ImageLoader class which CariocaTable instantiates that loads all images into a hash map. PlayerPanel for each player, each panel contains variable Player, Pile hand, Pile downHand (objective of the game). Mybe i should get rid of the pile variables since the class Player already contains them?
    Its the drawing of the GUI that gets to me. Any other suggestions or ideas?

  • Drag and Drop Problem in Card Game

    Hi, everyone,
    I'm trying to adapt the memory game in chapter 3 of the book "ActionScript 3.0 Game Programming University" for my own uses. I want to get all of the cards to flip and drag. I am able to flip the first card and drag it, but when I flip the second card over, I can't drag it. I have two files, MatchingGameMe.fla and MatchingGameMe.as. All of the actionscript is in MatchingGameMe.as. Here is the code. Does anyone see how I can modify it so that all the cards drag? Thanks in advance for your help!
    MemoryGameMe.as:
    package {
    import flash.display.*;
    import flash.events.*;
    public class MatchingGameMe extends MovieClip {
      // game constants
      private static const boardWidth:uint = 6;
      private static const boardHeight:uint = 6;
      private static const boardOffsetX:Number = 120;
      private static const boardOffsetY:Number = 45;
      private var firstCard:Card;
      private var secondCard:Card;
      public function MatchingGameMe():void {
       // make a list of card numbers
       var cardlist:Array = new Array();
       for(var i:uint=0;i<boardWidth*boardHeight/2;i++) {
        cardlist.push(i);
        cardlist.push(i);
       // create all the cards, position them, and assign a randomcard face to each
       for(var x:uint=0;x<boardWidth;x++) { // horizontal
        for(var y:uint=0;y<boardHeight;y++) { // vertical
         var c:Card = new Card(); // copy the movie clip
         c.stop(); // stop on first frame
         var r:uint = Math.floor(Math.random()*cardlist.length); // get a random face
         c.cardface = cardlist[r]; // assign face to card
         cardlist.splice(r,1); // remove face from list
         c.addEventListener(MouseEvent.CLICK,clickCard); // have it listen for clicks
         addChild(c); // show the card
       // This function is called when the mouse button is pressed.
       function startDragging(event:MouseEvent):void
            c.startDrag();
        // This function is called when the mouse button is released.
        function stopDragging(event:MouseEvent):void
           c.stopDrag();
       c.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
       c.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
      // player clicked on a card
      public function clickCard(event:MouseEvent) {
       var thisCard:Card = (event.target as Card); // what card?
        firstCard = thisCard; // note it
        firstCard.gotoAndStop(thisCard.cardface+2); // turn it over

    Not sure if this will work inside classes, but in working with AS3, this would issue the command to object you just clicked, and the object you just dropped:
    // This function is called when the mouse button is pressed.
       function startDragging(event:MouseEvent):void
            event.currentTarget.startDrag();
        // This function is called when the mouse button is released.
        function stopDragging(event:MouseEvent):void
           event.currentTarget.stopDrag();

  • C# Universal App Unity bad card game render

    Hello,
    I am working on a card game designed in Unity and I am getting some blurry rendering.
    I thought perhaps someone here may know why.
    I only get strange rendering when building for Windows Store and Window Phone.
    Building for Desktop does not have rendering issues.
    Below are links to the rendered output.
    Desktop:
    http://1drv.ms/1GzQ7Qh
    Windows Store:
    http://1drv.ms/186ocZK
    Windows Phone:
    http://1drv.ms/186oi3A
    Why is the Windows Store build blurry?
    Notice that the Windows Phone render has even more problems.
    There appears to be what I think is an antialiasing problem on the right and top edges of the images.
    Notice that the empty hand with the no score disk, has noticeable streaks up and to the right.
    Also notice that the cards have a black rectangle to the right of them.
    I believe this is happening because I do not have a completely transparent border around the png file.
    All images are textures on a Unity plane object.
    The Windows Store and Windows Phone build were created as C# Universal App solution.

    Hi Takimchu,
    If you are asking unity render problem, I would recommend you post your question on unity community forum. This forum is to discuss questions about windows store app.
    http://forum.unity3d.com/.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • From a complete beginner

    I have been given a JAR file and a HTML document explaining the classes . I have extracted the files from the JAR and it is created a directory structure with a class file in
    I now want to write a simple java program which will execute a method of the class what are the steps I should take? I have only written a "Hello World " program in java so a complete beginner
    Can someone explain if I should of extracted the files from JAR and what are the steps I should do next are
    Thanks

    You don't need to extract the JAR. You can simply add the JAR to your classpath.
    Example:javac -classpath .;<any additional jar files or directories> YourClassName.java
    java -cp .;<any other directories or jars> YourClassName
    Javapedia: Classpath
    Setting the class path (Windows)
    How Classes are Found
    Additional Resources:
    The Java&#153; Tutorial - A practical guide for programmers
    Essentials, Part 1, Lesson 1: Compiling & Running a Simple Program
    New to Java Center
    How To Think Like A Computer Scientist
    Introduction to Computer Science using Java
    The Java Developers Almanac 1.4
    JavaRanch: a friendly place for Java greenhorns
    jGuru
    Bruce Eckel's Thinking in Java
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java

  • New to game programming

    I'm new to game programming, and I am interested in making rpg/mmpog, and I want to know, what are some classes I will need to know well? Does anyone have code I can pick at to help me learn?

    I too am new to JAVA, and am trying my hand at a VERY simple RPG. My suggestions, as I've found out over the past few weeks in class.
    1 - Get a good book, not all teachers (assuming you're taking a class) are very good, and I've found "Java 2 Complete" By Sybex excellant.
    2 - Go slow. Work through the book, learning those sections you think you'll need. I.E. as I found I wanted a GUI, I went through every example of the AWT package, and learned them as I typed.
    3 - Stay simple, I am creating my own classes for this (Rooms, Monsters, Players, Items are the only four) and use the array and TextArea classes a lot also.
    //Room class
       public class Rooms
          private int exits;
          private String name;
          private int flagN = 1;
          private int falgE = 2;
          private int flagS = 4;
          private int flagW = 8;
          private int flagMonster = 16;
          private int flagItem = 32;
          public Rooms()
             name = "Room One";
             exits = 1;
          public Rooms(String nameIn, byte exitsIn)
             name = nameIn;
             exits = exitsIn;
          public byte getExits()
             return exits;
          public void setExits(byte newexit)
             exits = newexit;
          public String getName()
             return name;
          public void setName(String newName)
             name = newName;
       }In this class, I set up a Room(s) with the name of 'name' and a byte of 'exits' which is how I'm marking the exits and items in a room. I'm not too far along, but I hope some or all of this helps!

  • [Newbie] Which JAVA API is a good choice for creating a game board?

    I'm a newbie in JAVA game programming.
    I would like to create a chess game for fun. I have a fairly good idea on how I want it to be, but I'm having some difficulty on the game board.
    I am not sure which set of JAVA API I should be using to design my board. I guess that the board will sits in the back, and in the front, there'll be my chess pieces that I can drag and drop.
    Should I be using JAVA Swing to do this? or JAVA 2D API? It will require some study for either one, so I figure I should pick a good one to learn.
    Thanks in advance! :-)

    Also if you would like to create a much simpler, 2D chess game, I would suggest you use the Swing API, which comes with Java from version 1.2 and on up. Naturally I would suggest at least using the latest 1.4 or 1.5 software development kit, because they have greater and more stable features, bug fixes and so on. I also would suggest you go to the library or Barnes and Noble nearest you, and pick up a book on Java. One recommendation that may be simpler to get an understanding of Java is from Deitel and Deitel: http://www.deitel.com/books/jHTP6/ though my beginner's Java book was geared directly toward how to program games (small games like memory, or tetris), though I can't remember what it was called. Anyway I believe it is very important to learn the basics of Java before you get into things that you may or may not understand. My opinion, so have a go at it.

  • How to create a game. Basic steps.

    So, just browsing through these forums, I see many posts by prospective game designers wanting to get started. But many of these questions are so ill-researched or off basis that most people don't even know how to respond.
    So here's a quickie guide on how to get started learning to make a game. Notice I didn't say making a game. First you learn, then you make, or else you'll just get frustrated and quit.
    Here's the basic steps:
    1) You need to learn Java. Seriously, don't even think about writing a game if you don't want to. Get a book. My favorite was one by Ivor Horton. But really, any will do.
    If Java is your first programming language, it is important for you to read through the book carefully and do the excercises. This is for you learn what a "programming language" actually is.
    All a computer can do is add numbers. A computer itself knows nothing about Mario or how to make Mario jump. So YOU have to figure out, just what does Mario have to do with numbers.
    2) Write a simple game, without animation in it.
    My first game was Minesweeper. Other examples include Solitaire, or Poker, etc...
    This teaches you how to organize a "large" program. Organization is important. If you don't organize, you'll begin writing a game, and eventually get stuck because your code is unreadable, and your bugs will be impossible to trace down. You'll be frustrated and quit.
    3) Learn the concepts behind animation and a 2D game.
    I see questions like: "I want to make a game, and I drew Mario. Now how to I make him move?". This is for you people.
    Animation is drawing a bunch of images in rapid succession. And a game, basically is a logic system that decides which animations to play at any given time.
    4) Write a 2D game.
    Now, you are ready to attempt an actual game. I started small and wrote a tetris-esque puzzler as my first game with animation. I suggest you do the same, but if you feel ready you can probably jump into a major project now.
    5) Learn about 3D.
    For those aiming high, you can get started learning the concepts behind 3D now. I suggest you know at least a basic knowledge of trigonometry. This means know your sin, cos, and tan inside out, or else you'll up for a lot of work.
    3D is not like 2D. There are quite a few concepts that you will need to learn, and they're not immediately intuitive. Those who have a stronger math background will progress faster. Those who have a weaker background will find it more difficult. But you'll learn a lot along the way. Nothing teaches trig faster than writing a 3D engine.
    6) Write a 3D engine.
    You're entering the hardcore right about now. Few people on this forum will have experience with this and you'll need to do a lot of thinking. Mainly, just because, there's not many people left to ask.
    Some of you will have some ideas on writing this engine. In this case, I recommend you go ahead and try. You might not succeed, but trying will teach you more than anything else.
    Those that don't quite have it down yet, or those that tried and didn't quite succeed can follow along with a book that takes you through this step. The book that I used was "Java game programming". It has a very in-depth section on 3D.
    7) Make your engine fast.
    This step is probably the hardest of all. If you completed step 6, you'll notice that writing a 3D engine, and writing a fast 3D engine is two almost completely different things.
    Here's when you'll research into various computer science algorithms and techniques in order to speed up your engine. Actually, this is when you'll probably learn the concept of "algorithm".
    This is research! You'll find almost no help at forums for this step. Nothing but hard work.
    I can't comment on more than that, as that's as far as I've gotten so far. But that's the basic roadmap.
    Good luck on your games.
    -Cuppo

    Okay I am going to add a few points since they have come up recently.
    With relation to what you should know with Java.
    Beyond the basics you should get a good grounding in the following
    - threading
    - networking in Java (if applicable)
    Threading
    For threading you can use the concurrency tutorial found here http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html
    Threading is really a must. No kidding. Because you will be unable to do anything performance wise without it. Additionally you can't normally take a non-threaded application and slap threading on it. You need to have a design that incorporates being threaded.
    You also don't want to come up with a design to find out later that it's wrong. Don't be afraid to ask questions about your design in general and as how it relates to threading.
    Making a good multi-threaded application is actually not all that difficult, once you understand it. But this is the thing that seems to trip up alot of people. I see an awful lot of bad threading code in the Java Programming forum. Tip: If you are using Thread Priorities you are doing something wrong!
    Networking
    The Java networking tutorial may be found here http://java.sun.com/docs/books/tutorial/networking/index.html
    This is a basic tutorial though so don't assume you know everything there is to know once you have finished it. If you are serious about your development then I HIGHLY recommend the following book
    http://books.google.com/books?id=l6f1jTB_XCYC&dq=Fundamental+Networking+in+Java&psp=1
    As a bonus the author is a long-time member on these forums and a regular in the Networking forums.
    Networking your program, especially depending on how you will use it is important to design into your game from the get-go. If you are planning to make a multi-player online game you need to know what the limitations are with regards to performance early in your development. If you build a beautiful game but it runs like a dog because of what you did in your networking code it would be a real shame and worse it may not be fixable.
    Again don't be afraid to ask questions.
    Restatement of CuppoJava's Comments
    This is a good thread and that's why I am adding these comments to it. I would also say that I totally agree with the sentiments on what you should expect.
    If you are new to Java and expect that in just a few months you are going to crank out a game with a custom 3-d engine you are in for a nasty surprise.
    It isn't that we want to be discouraging, but please do try and set yourself realistic goals and time deadlines. You'll find it a much more positive experience and the less frustrated you are the more likely we are to be able to help you. :)

  • Creating a service program in inventory results in 'no data found error'

    Hi,
    i tried creating a service program as was given in the sep 2001 issue of the crm newsletter. While saving the item it results in the following error:
    FRM-40735 ON-INSERT trigger raised unhandled exception ORA-01653
    ORA-01403 No data Found
    What could be the possible cause for the occurrence of this error?
    Thanks & Regards,
    Nithya

    You're doing a lot of unnecessary conversion of dates into character strings and back into dates again.
    Keep it simple and just use dates as-is:
    SQL> select * from T_REC_PER;
                     VAL START_PERIOD         END_PERIOD
                       5 15-OCT-2008 00:00:00 30-OCT-2008 00:00:00
                       6 31-OCT-2008 00:00:00 06-NOV-2008 00:00:00
                       8 07-NOV-2008 00:00:00 12-NOV-2008 00:00:00
    SQL> declare
      2     ls_per   date := to_date('17-OCT-2008','DD-MON-YYYY');
      3     ln_val   number;
      4  begin
      5     select t.val
      6     into   ln_val
      7     from   T_REC_PER t
      8     where  ls_per between t.start_period and t.end_period;
      9     dbms_output.put_line(ln_val);
    10  end;
    11  /
    5
    PL/SQL procedure successfully completed.
    SQL> declare
      2     ls_per   date := to_date('09-NOV-2008','DD-MON-YYYY');
      3     ln_val   number;
      4  begin
      5     select t.val
      6     into   ln_val
      7     from   T_REC_PER t
      8     where  ls_per between t.start_period and t.end_period;
      9     dbms_output.put_line(ln_val);
    10  end;
    11  /
    8
    PL/SQL procedure successfully completed.

Maybe you are looking for

  • Storage Location Level ATP check through CRM

    Hi: I am on an implemenation where the integration is between CRM, EWM and GATP. So, consider the situation where the sales order check is done through CRM and a call to GATP is made. Some background on supply EWM would like to receive the goods into

  • CS4 - why is the video so fast???

    I converted a mov to avi using automkv because the original file had a weird codec. It plays great on windows media player and seems fine. But, when I imported it into CS4 it is somehow 1600% faster! The actual length of the video is the same in the

  • Blue ray player connection to web help

    Just wondering if any iMac people have recently successfully connected their blue ray player to the internet? Apple tells me that I have to purchase "Apple TV" device. The Sony player (BDP-N460) I purchased said I only need to buy an additional 'Link

  • How can I access an amount in all the columns

    Hi, In my query I have calendar month/year in the column structure. 0Calmonth is mapped to posting date. If an amount is posted in jan, it'll be displayed under jan only. But I want to display the amount under every month. Is there any way to do this

  • Pro platforms & software? Mac or PC? Final Cut, Avid, Premiere, etc.?

    I've a 14-year-old niece who, with iMovie, Garageband and iDVD has, in the past year overtaken her Dad's digital video camera and has produced two films (that she's finished - she has others in the works) that would be remarkable for a 40-year-old an