My first java game

import javax.swing.*;
import java.util.Random;
public class Cards extends Object{
     String cards[] = new String[53];
     Random rand = new Random();
     //constructor
     public Cards()
     public void clearitout () {
          for(int index=1;index<=cards.length;index++)
               cards[index]=("unused");
     public void deal () {
          int cardsdelt=0;
          int index=0;
          while(cardsdelt<=5)
               if (cards[index]=="unused")
                    cards[index]="used";
i have no clue what to do i just want to get a random number and check to see if itsd not already played

i had some help from one of my friends... but i got 2 loos of precision errors on the methods identifysuit&identifycard
import javax.swing.*;
import java.util.Random;
public class Cards extends Object{
String cards[] = new String[53];
String cardnames[] = {"ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"};
String suitnames[] = {"spades","hearts","clubs","diamonds"};
Random rand = new Random();
//constructor
public Cards()
public void clearitout () {
for(int index=1;index<=cards.length-1;index++)
cards[index]=("unused");
public void deal () {
int cardsdelt=0;
int index;
while(cardsdelt<=5)
index=(rand.nextInt(52)+1);
if (cards[index]=="unused")
cards[index]="used";
System.out.println(cardnames[identifycard(index)] + " of " + suitnames[identifysuit(index)]);
cardsdelt++;
private int identifysuit(int index) {
int suit=0;
suit = Math.floor(index+13)/13;
return suit;
private int identifycard (int index) {
int card=0;
card = (((((index+12)/13) - Math.floor(index+12)/13) *13) + 1);
return card;

Similar Messages

  • My first java game (Thks everybody to make it real)

    Thanks for help me to make my first game in pure Java
    look in http://www.angelfire.com/games3/slotsmax/English/index.htm and feel free to post your comments,,
    ~toki

    - 652kB is way too much to load at once. Load images when needed (preload them in the background before they are needed if you don't want delays when displaying an unloaded picture). Also load the music in the background. It doesn't matter if the music doesn't start immediately. It's more important that the game does.
    - Make a switch to turn of the damn music! (Who would want some POS music when listening to mp3s? Or when surfing on a library computer. Or in a netcaf�?)
    - Make the user interface more intuitive. E.g. what's that ">>>>" button supposed to be? Where can you click? What happens when you click e.g. at the numbers on the left/right to the wheels? Or on the wheels themselves? Each time I click on "Bet 1" the "Bet:" field value is increased, but when I click on "Bet 9" it stays on "9".
    - And don't forget to make the music optional.
    - Really remember making the music optional.
    This is a good start, but you do need to work on it some more. (If you haven't read any good user interface book(s) I recommend reading GUI Bloopers by Jeff Johnson.) Good luck!
    - Marcus

  • The ever so savvy "creating a java game" post

    Hey, I'm creating a java game, and I did research, and found that this question has been asked many, many times. But my question unfortunately did not match up with any of these posts :( So here goes...
    Im creating a java game, which will run as....kind of a mix between a 2d game, and 3d game (no i am not insane). I dont want the original zelda look, and i dont want the first person shooter look, I want my character to be viewed from an angle, like tibia - if anyone has ever played that. And I also want to leave open the door to changing the view within the game. I figured I can just get my graphics friends to draw things in 3-d, (draw a house [draw the 4 sides and the roof]), and then somehow skew these images to accomodate for a different view.
    I am more than willing to code some kind of graphics engine if what I need is not available, I have looked at a couple and found no such luck.
    So what is the most efficient way to create this game? By just sortof getting all the graphics to be from a certain percpective, and then somehow modifying them with java.....
    or by using some kind of graphics engine that allows me to change views? If so any recomendations?
    Thanks a lot - wow this was long, oh yea a couple Dukes for this too thanks again
    -Mark

    you don't need to do any skewing. Here's what I'd do. I'd store all the tile information in a matrix (Object[][]) with a custom tile class that has the information it needs to retrieve its appropriate image, and certain game related data like slow down factor when a person walks over a certain type of tile, and whether it can be collided with. I'd draw them based on however you decide to angle your tiles. But the important part is you go in this order:
    [0, 0], [0, 1], [1, 0], [0, 2], [1, 1], [2, 0], etc., etc....
    The idea is if you're turning the floor 45 degrees clockwise, to give the correct illusion of depth, you'll want to draw the furthest back tile first, and the furthest tile forward last. Whether you start on the left or right depends on what angle you decide to work with. At a 45 degree angle, it obviously doesn't matter whether you start on the left or right. But if you guess wrong with your rendering, it will show because tiles that are closer to the "camera" will be overlapped by tiles further from the "camera".
    for (int i = 0; i < tiles.length; i++) {
         for (int j = 0; j < tiles.length; j++) {
              graphics2D.drawImage(tiles[i].getImage(), i*horizontalSpacing - camera.getX(), j*verticalSpacing, camera.getY(), null);
    }horizontalSpacing and verticalSpacing will be determined by the angle of your tiles. Set those to match however you make your art.
    Drawing moving sprites will be a bit trickier because you'll have to decide which set of axes to follow... meaning, do you follow the axes of the screen, or the axes of your "rotated world." Give that some thought and once you understand what's happening with the perspective here you'll be able to see which is easiest.
    So there's your engine ;)
    Now, as for the art itself, make them in png format, so that you can have the base of your images be diamond shape, but of course tiles for players and walls and stuff will extend above that diamond. Just don't let them get below the base of their diamond otherwise the tile that gets drawn below them will cut them off. And you don't want a character's feet cut off by the "floor" as he runs ;)
    For your final question, don't let java skew the sprite. The only possible way to make it decent is if when you pick an angle, a 3D render takes your 3D world and it's 3D models and re-renders them at that angle; skewing is simply not capable of creating that illusion. The closest you could get is to simply squish the hight of your art to give the illusion that the camera is moving up, but since you can't expose things higher, like the top of your character's head (since the data doesn't exist in the "lower" version), it will be obviously funny looking.
    Hope that answers your questions, and good luck! I would definitely like to see what you come up with.

  • Making some basic Java games

    Can anyone help on how to make some basic java games for my website if you could that would be helpful
    thanks,
    Louie

    Well, first of all you program the Framework, add Graphics / sounds / Data , then you put it in your HP - There you are!

  • Getting that first java job

    Could anyone give some tips for going from graduate (BSc Comp Sci) to getting first java job? A lot of employeers want 'experience' but when you've just graduated you've only ever worked on uni assignments and not industrial ones. How do you crack this?
    Does certification impress anyone other than recruitment consultants?
    Is it a good idea to put together online portfolio of all work you've done?
    thanks

    Could anyone give some tips for going from graduate
    (BSc Comp Sci) to getting first java job? A lot of
    employeers want 'experience' but when you've just
    graduated you've only ever worked on uni assignments
    and not industrial ones. How do you crack this?
    Don't stare blindly at those numbers. Everyone says "experience preferred" and they mean it. Expect to have to take a lower starting salary than the stated one and don't write on jobs asking for more than a few years experience as those will be way over your head most likely.
    Otherwise, persevere or move to India (they seem to hire anyone who can spell the word 'computer' there).
    Does certification impress anyone other than
    recruitment consultants?
    Depends on the certification but in general yes.
    It impresses not the recruitment consultants but the non-technical people they're selling you to.
    Anyone with a grain of knowledge about certs will know that most if not all are completely useless without practical experience to back them up (and some worse than useless, think MCSE NT4 which was a disaster).
    Is it a good idea to put together online portfolio of
    all work you've done?
    Can't hurt, if it's relevant. I'd not put in time spent making levels for Doom unless you're trying for the games industry though (just an example).
    thanks

  • Java game AI

    Hi there, I am currently creating a battleship game which allows you to play against a computer or a human or run the game as a spectator watching the computer battle its own AI. I am having trouble finding an efficient way to program the AI when I hit a ship on the opponents map.
    Current logic: I hit an enemy ship and add all the possible directions into a queue and resolve them in order, up down left right. If there is an 'o' (miss) or 'x' (hit), currently in one of the suggested directions, it will be removed (since it has already been searched) and move on to the next coordinate.
    Problem: The AI is extensive in it's checking. It finds a long ship, 10 char long, and checkes all around the the ship making sure nothing else is there. Although this method is very accurate, it takes too many turns to verify that it has found the whole ship, therefore losing almost all the time.
    Any ideas?
    -Thanks in advance
    EDIT: Sample from AI vs AI.
    x = hit
    o = miss
    Computer2's Map
    0123456789
    0 .......xxo
    1 .ooo..o.o.
    2 ....o.....
    3 ..........
    4 .....ooooo
    5 ...ooooxxo
    6 .ooxxxxxo.
    7 .oooooooo.
    8 .......o..
    9 .o........
    Edited by: Krytical on Jul 15, 2009 2:55 PM

    I think you are not putting enough into it.
    AI is hard, no matter how simple the game may seem. I have written about 16 games (I might have missed one or two in a hasty count) and worked on a couple open source game projects. Of those 16, 2 of them include an option to play against the computer, i.e. they have a good enough AI. The rest are all strictly multiplayer or single player with no opponents (simulations). Of those two, both are also and where first multiplayer games. That is because until I can play a game enough to fully understand it strategically (even though I wrote it), it is impossible to write a working AI.
    So here is my advice, play a few dozen games against other players, the more different people you play against the better. Jot down your strategies in every situation, and ask you opponent if they would be kind enough to do likewise (it helps to tell them it is for writing an AI, otherwise they think you are just trying to learn their secrets for the next time you play). Then try out some of the strategies you get from others and see if you understand it, when it is best to use that strategy, and how well it works.
    At this point, you should try to code several of those strategies and see how well the computer does with it. Then code a way for the computer to weigh the possible effectives of the different strategies and randomly choose between them based on the weighted scale. As in, if start A is 5 times more likely to succeed than strat B in situation X then the computer should have 5 times more likelihood of choosing strat A over strat B for situation X.
    As a starting point, here is my strat for battleship in a way that should help with how to code it. I always look at which direction has the longest distance to where I have previously fired. But I also limit it to 4 spaces as that is the length of the longest ship (plus the one hit). So if I choose say F6 (isn't it letters across the top?) and get a hit, then I look around F6. Looking down I have already gotten a miss on F9 leaving 2 blank spaces. Looking left I have recorded a miss on A6, leaving 4 spaces that way. Looking up I have a miss on F5, so there is definately not one that way and this makes it less likely the boat runs north and south (up and down). To the right the nearest shot was a hit on a boat I already sunk but it is 7 spaces away, so I exceed the limit and reduce it to 4 spaces. So what do we have, 2 spaces down, no spaces up and 4 spaces to both the left and the right. At this point I am just going to randomly choose to go left or right and keep going that way until I get a miss or my opponent announces I sunk a ship, if a miss with no sinking I go the other way until said declaration. Should I get a miss on both sides without an additional hit then I will re-evaluate and since the only way left to go in that case would be down, that is how I would go. If I got a hit going either way but missed on both sides then I know I have two ships and I simply put the new hit on the back burner until I have sunk the first.
    Now this should all be relatively easy to code and should make the AI much more formidable. But there is actually far more I do when playing that game. For example, if the 5 length ship has already been sunk and the longest left is 4 length, then I only go 3 blank spaces each way in weighing my options. Similarly if the 2 length ship and both 3 length ships are sunk then I first check to ensure there is a total of at least 4 spaces along either axes (there must be on at least one of them). This will be a little more coding work, but will make the computer AI even more robust and formidable.
    If I was playing against your AI I would always place my ships from left to right, because I know the AI is then always going to waste at least 2 shots whenever it gets a hit. In AI the more unpredictable the AI is the better, this is why it is important to keep things random, and give the computer as many strategy choices as possible to weigh and then semi-randomly choose from.
    Also, this is the wrong place on these forums for this question, there is actually a java games section here, I think it is under other. Also there is actually a fairly active java game forum, but I don't recall the url for it atm. You will have far better chances of getting a response in one of those more appropriate places.
    JSG

  • Use mouse for first person game

    I have programed one first person game using Java 3D and am working on a new idea and I hope to be able to run it through a web browser.
    The problem I am having is using the mouse in the game were it does not leave the applet window when moved and I can keep track of how much movement it makes so I can make it function like a normal FPS (the mouse is moved in a certain direction and the character turns that direction the amount the mouse was moved). If someone could point me toward a class or of anyway this can be done that would be great. Thanks.

    Java does not have built-in support for direct polling of the mouse.
    One hack that I've used to get around that is in the Robot class.
    If the mouse exits the applet window from the left side, I can use Robot.moveMouse(int x, int y) to move the cursor back to the right side. This let's me force the mouse to be within the applet window at all times.
    Its pretty hacky, and I believe you're going to have to get the user to sign some special permissions to use this in an applet, but there's not much alternative.
    good luck
    -Cuppo

  • Wolf Shoe / Episode 1 from Dramatic Java Games

    Hi all,
    Our first episode will launch soon...
    For the first time europes best author, Morten Hjerl-Hansen and the superb graphics wiz Danni Tell brings together europes best actors on the Java platform.
    We're also entering in the Java Game Developers contest with this episode. Please try it and vote for us, but only if you absolutely loose your heart. We promise a historic breakthrough because we've invented a whole new game genre.
    * Never seen before graphics quality
    * Drama in games
    * Danger
    * Double player concept
    * Revives the adventure game genre by getting rid of puzzles once and for all
    Best regards
    The Creators
    Dramatic Java Games
    http://www.dramaticjavagames.com

    Thanks for you interest!
    Wolf Shoe is up in beta 1 and we made it to the dead line of the first JDC Game contest!
    Good luck!
    br
    www.dramaticjavagames.com
    PS The temporary server will be replaced soon. It's slow and unstable. We apologize for the inconvenience.

  • How can I download java game?

    Hi everyone, sorry for my english, it is not my native language.
    I have Game.Jar file, which is java game for Nokia ,and I uploaded this file into database.
    Now I have a filed, type of byte[] (array of bites)
    next, I generate URL like http://site.com/getfile.xxx?id=10, and then user go to this URL via WAP, and trying to send him byte[] array with java game data.
    But I don't know which Content-Type i must send :(
    I trying to send Content-Type: application/jar , but after downloading game into mobile phone, the game doesnt open :(((
    please help me!

    excuse me, it's actually application/java-archive
    This works for me (PHP) but unfortunately you have to rename the downloaded file to .jar:
    <?php
    $file = fopen("MimeTest.jar","r");
    header("Content-Type: application/java-archive");
    $text = fread($file,filesize("MimeTest.jar"));
    print $text;
    fclose($file);
    ?>You can try it out here: http://woogley.net/misc/MimeTest.php
    Download that and rename it to .jar and see if the data stayed in tact..

  • Help with first java app!

    Hello all. I'm very new to java, and I'm trying to create my first GUI app. The idea behind this app is for the user to enter number of hours worked and the rate of pay, and then it will mutliply them together and give you the result.
    I have my main class which sets up the frame then calls my panel class
    Inside my panel class I have two panels, one for the twi input textfields (hours and rate of pay) and one panel for the button and the result text field.
    I cannot figure out how to do get the value of both text fields and mutliply them together when the botton is clicked. Here's my code:
    import javax.swing.*;
    public class FirstProject
         public static void main (String[] args)
              //Sets up the frame
              JFrame frame = new JFrame ("My first Java app");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(300, 200); frame.setVisible(true);
              //Foreground panel class
              foreground fg = new foreground();
              //Add stuff
              frame.getContentPane().add(fg);
              frame.setVisible(true);
              frame.pack();
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.xml.bind.Marshaller.Listener;
    public class foreground extends JPanel implements ActionListener
         public foreground()
              //Setup the layout
              setLayout (new BoxLayout (this, BoxLayout.Y_AXIS));
              //Setup input panel
              JPanel input = new JPanel();
              input.setBackground(Color.white);
              input.setBorder(BorderFactory.createLineBorder(Color.black, 1));
              //Setup output panel
              JPanel output = new JPanel();
              output.setBackground(Color.white);
              output.setBorder(BorderFactory.createLineBorder(Color.black, 1));
              //Add main media
              add(input);
              add(output);
              //--**INPUT BOX**--\\
              //Setup the hours label
              JLabel hour = new JLabel("Number of hours worked: ");
              //Setup the rate of pay label
              JLabel pay = new JLabel("Enter your rate of pay: ");
              //Setup the rate of pay text field
              TextField paytext = new TextField("20", 3);
              //Setup the hour text field
              TextField hrtext = new TextField("40", 0);
              //Add objects for input
              input.add(hour);
              input.add(hrtext);
              input.add(pay);
              input.add(paytext);
              //--**OUTPUT BOX**--\\          
              //Set up objects in output panel
              JButton calculate = new JButton("Calculate!");
              calculate.addActionListener(this);
              calculate.setActionCommand("Calculate");
              //Add calculate text field
              TextField calculatetext = new TextField(2);
              //Add objects for output
              output.add(calculate);
              output.add(calculatetext);
    }Thanks in advance!!
    P.S. I'm using eclispe btw.

    Your problem is related to your ActionListener.
    public class foreground extends JPanel implements ActionListener
    calculate.addActionListener(this);You have it set up so the Foreground panel is listening to the calculate button's clicks, but it's not doing anything with the clicks.
    I would strongly suggest dropping the "implements ActionListener" bit and implementing a separate ActionListener, like so:
      JButton calculate = new JButton("Calculate!");
      ActionListener buttonListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          // do whatever you want with the
          // paytext.getText ...
          // hrtext.getText ...
      calculate.addActionListener(buttonListener);
      // and you don't need this:  calculate.setActionCommand("Calculate");rh

  • My First Java Mapping in PI 7.1

    Hi, i'm having a problem with my first Java Mapping in PI 7.1
    I was reading examples and i create a class that extends "AbstractTransformation", there's a "transform" method and it request two params with "TransformationInput" type.
    I created a main method to test it, but i have a problem converting the InputStream to TransformationInput.
    Anybody had this problem?
    Regards,
    Sebastián.

    Hi Sebastian,
       Trasform method is like a main method in JAVA Mapping,the execution starts from the trasform method,TrasformationInput method reads the input from Input stream reader,and TrasformtionOut write out in in output stream.
    public class FirstJavaMap extends AbstractTransformation {
         public void transform(TransformationInput in,TransformationOutput out)
          throws StreamTransformationException {
    try{
    your logic...
    }catch(Exception e)..........
    like that
    refer below link ,it helps you...
    http://help.sap.com/saphelp_nwpi71/helpdata/EN/43/bc2fd4da1e1bbce10000000a1553f7/content.htm
    Regards,
    Raj

  • Just finished my first Java application. What's next?

    Thanks to the kind help from everyone on this forum and some intensive labor for the last couple of months, I've finally given birth to my first Java application. I used Netbeans as my IDE of choice. During the development stages I would run my project directly from the IDE. In the project folder, a total of five folders were created: build, dist, nbproject, src, and test as well as two files build.xml and manifest.mf.
    Being a newbie in this field, I was wondering about the remaining steps needed to distribute the application. Here are some questions that come to mind:
    1) I know I can simply just double-click the project's *.jar* file to get it work. Is that the norm with Java applications or do I need to create a different file? I'm used to seeing *.exe* files. I'm also used to seeing an installation process, which brings me to my next question.
    2) Do you simply just zip the entire project folder and allow people to download it on their computer hoping they know how to access the *.jar* file?
    3) Seeing that I've only been testing the application in Netbeans, will there be file path or classpath problems if I run it on other computers? Are there necessary steps I need to follow to avoid such problems?
    4) Do you take any precautionary steps to protect your code? Do you lock the folders?
    5) In the future, if I decide to add a small fee to download the application, how hard would it be to add a password activation feature? (I know this could get pretty complex)
    Thanks in advance for all your suggestions.

    mohogany wrote:
    Thanks to the kind help from everyone on this forum and some intensive labor for the last couple of months, I've finally given birth to my first Java application. I used Netbeans as my IDE of choice. During the development stages I would run my project directly from the IDE. In the project folder, a total of five folders were created: build, dist, nbproject, src, and test as well as two files build.xml and manifest.mf.
    Being a newbie in this field, I was wondering about the remaining steps needed to distribute the application. Here are some questions that come to mind:
    1) I know I can simply just double-click the project's *.jar* file to get it work. Is that the norm with Java applications or do I need to create a different file? I'm used to seeing *.exe* files. I'm also used to seeing an installation process, which brings me to my next question.It's quite common to provide a shell script (batch file, etc) to launch the app.
    2) Do you simply just zip the entire project folder and allow people to download it on their computer hoping they know how to access the *.jar* file?You can do. There are also installation utilities around. InstallAnywhere is the only one I've ever used, but others do exist.
    3) Seeing that I've only been testing the application in Netbeans, will there be file path or classpath problems if I run it on other computers? Are there necessary steps I need to follow to avoid such problems?Probably. The best way to avoid them is to test them, and to not ever depend on the CLASSPATH environment variable. That's a portability nightmare.
    4) Do you take any precautionary steps to protect your code? Do you lock the folders? Nope.
    5) In the future, if I decide to add a small fee to download the application, how hard would it be to add a password activation feature? (I know this could get pretty complex) Don't bother. Unless you've got something amazing, in which case you'll be needing lawyers, it's not worth the trouble of charging for it. No offence, but your first Java app is hardly going to set the world on fire anyway.
    No matter what you try and do to stop people stealing your code, they'll manage it. Or, alternatively, just steal your idea instead.

  • Java Game not working on phone

    Hello, Im using mpp sdk to compile and emulate java code. It works fine but when I download it to my phone, it doesnt work.
    Im sure the problem is somthing in the code that my doesnt support that the emulator does, I just dont know what it is.
    My phone is a sony ericsson k500i but Im hoping that this code will work on any phone with a jvm.
    The code is here
    http://www.geocities.com/ed72678954/Life.java
    http://www.geocities.com/ed72678954/LifeCanvas.java
    Thanks very much...

    No- I have a couple of java games apart from this one- but all other work fine. I even downloaded a free ad version of this game from Nokia store and even that gives the same problem. Why Cant Nokia check for compatibility before adding any app in its app store? Same is the case with quick office pro 7 which has compatibility issues with belle as agreed by quickoffice itself. Then why does the app continue to be available in store that too at a price?
    In Love With My C6-01:Now running on Nokia Belle!

  • First Java Project - Document Management and Workflow

    We are about to embark on our first java project around document management and workflow.
    I would be interested to know how others have approached similar projects – Open Source applications or other tools/APIs.
    It would also be good to know of any issues encountered along the way.
    Thanks,
    Steve

    Hi Husein,
    I appreciate your interest in procuring a Document Management/Workflow solution for your AP department...its a very smart move toward streamling that process!
    I sent an email today to Richard Braddock about our solutions. I would be happy to discuss them with you.
    My office phone number is 215-646-8000
    -Martin

  • Sound in a java game

    hy,
    is it possible to create a sound in a handy java game(J2ME)
    mfg pg

    In the MIDP 1.0 specification sound is not supported. You can only use the device specific API. The Siemens SL45i has its own classes for sound output. But when you use them, your program will not work on other devices.

Maybe you are looking for

  • Cant login in my macbook pro

    When i try login in my mackbook pro  it accepts and everything but then this white background with a circle on the middle appears. What should i do??

  • Ordered my Mac Mini

    Well, I finally did it. But looking back... About two months ago I picked up a PowerMac G3 Blue & White (400 MHz) off eBay and sank a little money into it. I loaded Panther on it and never looked back. So now it's onto something a bit newer and maybe

  • Can we write case statement

    Hi, Can we write CASE statement in Where clause of select statement... I searched on net, i found that case statement can be written in the having clause.. But how about in the where clause....

  • Importing black & white raw photos doesn't work from a Canon Rebel XT

    I have a Canon rebel XT digital SLR camera. I usually take pictures in RAW format and they import fine to iphoto but recently I decided to change the settings on the the camera to take in black and white. When I import these RAW (cr2) black and white

  • TS1363 iPhone (4S) not recognized by computer (PC, Windows 7).  Previously connected and able to sync.

    Seeking help to sync iPhone with Windows 7.  Previously able to do this with mophy.  Need help identifying and correcting problem.