Results 1 to 2 of 2

Thread: Card Game

  1. #1
    abby0910 is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Question Card Game

    Hi I am trying to make a Card game where there are 2 inputs and it decides who is the winner.. But what I am having problem with is taking an input as A or J or Q or K and assigning their respective values i.e. 14, 11,1 2, 13.. If anybody could help it would be great.

    Java Code:
    package cardGame;
    
    import javax.swing.*;
    
    
    public class cardGame {	
    
    	public static void main (String args[]){
    		int card1;
    		int card2;
    		String input;
    			
    		input = JOptionPane.showInputDialog("Enter first Card: ");
    		card1 = Integer.parseInt(input);
    		
    		input = JOptionPane.showInputDialog("Enter second Card: ");
    		card2 = Integer.parseInt(input);
    		
    		if (card1 == card2){ //Checks if 2 cards are equal
    			JOptionPane.showMessageDialog(null, "It's a Tie");
    			return;
    		}
    		double large;
    		large = Math.max(card1,card2);
    		if (card1 == large){//Checks the winner
    			JOptionPane.showMessageDialog(null, "First Player Wins");		
    		} else if (card2 == large){
    			JOptionPane.showMessageDialog(null, "Second Player Wins");
    		} 
    	}
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    an input as A or J or Q or K and assigning their respective values i.e. 14, 11,12, 13.
    One way is to have a String: "JQKA" and use the indexOf method.
    If the returned value is > -1, add 11 to it. 11 being the value of for the first char: "J"

Similar Threads

  1. please help me with this card game
    By noobinoo in forum New To Java
    Replies: 13
    Last Post: 03-28-2010, 02:07 PM
  2. 4x4 2D array card game,need solving
    By highschool in forum New To Java
    Replies: 6
    Last Post: 02-25-2010, 03:36 PM
  3. Creating a Card Game in Java
    By Natrix in forum New To Java
    Replies: 1
    Last Post: 05-05-2009, 05:55 PM
  4. card game Rummy
    By javafox in forum New To Java
    Replies: 4
    Last Post: 03-14-2009, 03:53 PM
  5. A Online Card Game
    By GonzaloP in forum Networking
    Replies: 0
    Last Post: 12-28-2008, 06:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •