Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Matching Game

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Matching Game

    Hello i have been having trouble trying to create a Matching game using classes and methods can you please help


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Matching Game

    Do you have any specific questions about your assignment?
    Please post your code and any questions about problems you are having.

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Matching Game

    Sorry, I forgot to ask you to use code tags.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    What are your questions?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please Help Finish Project Memory Matching Game

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Matching Game

    what do you mean to wrap the code with code tags

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Matching Game

    To wrap your code with code tags:
    [code=java] <<<<<<<<<<<<< THIS goes before the code

    <YOUR CODE HERE>

    [/code] <<<<<<<<<<<< THIS goes after the code

    --- Update ---

    What is your problem with the code in post#9?

    How can that code be compiled and executed for testing?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Matching Game

    To wrap your code with code tags:
     <<<<<<<<<<<<< THIS goes before the code
     
    import java.util.*; 
    public class Cards {
     
     
     
    	private char label;
    	private int cardNum;
     
    	public Cards (int num)
    	{
    		cardNum = num;     //making CardNum Equal to Intiger num1 
    		reset();
    	}
     
     
    	public void reset()
    	{
    		label = '*';
    	}
    	public boolean flipCard()
    	{
    		if(label == '*')
    		{
    			label = convertToChar();
    			return true;
    		}
    		else
    			return false;
    	}
     
    	public char convertToChar()
    	{
    		String temp = cardNum + "";
    		return temp.charAt(0);
    	}
     
     
     
    	public char getLabel()
    	{
    		return label;
    	}
    	public String toString()
    	{
    		return "" + label;
    	}
    	public boolean equals(Cards other)
    	{
    		return other.label == this.label;
    	}
     
    	public static void main(String[] args)
    	{
    		Cards p1 = new Cards(0);
    		System.out.println("Card p1 = " + p1);
     
     
    		System.out.println("We try and place a new card.");
    		if(p1.flipCard())
    			System.out.println("Successful attempt! ");
    		else
    		{
    			System.out.println("Failed attempt! ");
    		}
     
    		System.out.println("Card p1 = " + p1);
     
     
    		System.out.println("We try to flip the card, but it's already flipped");
    		if(p1.flipCard())
    			System.out.println("Successful attempt! ");
    		else
    			System.out.println("Failed attempt! ");
     
    		System.out.println("Card p1 = " + p1);
    		System.out.println("We reset p1.");
    		p1.reset();
    		System.out.println("Card p1 = " + p1);
    	}
    }
    <<<<<<<<<<<< THIS goes after the code

    --- Update ---

    and i have 2 more

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Matching Game

    Sort of a waste of time if you delete all the posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Matching Game

     <<<<<<<<<<<<< THIS goes before the code
     
    import java.util.*; 
    public class Board {
     
     
     public static void Board(){
             Cards [][] c = new Cards[4][4];
     
             c[0][0]=new Cards(1);
             c[0][1]=new Cards(2);
           {
     
             }        
          }
     
     
     
     
     
     }
    <<<<<<<<<<<< THIS goes after the code

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please Help Finish Project Memory Matching Game

    import java.util.*;
    public class Cards {

    // Cards

    //instance variables
    private char label;
    private int cardNum;
    //constructor
    public Card (int num);
    {
    cardNum = num; //making CardNum Equal to Intiger num1
    reset();
    }

    //mutator methods
    public void reset()
    {
    label = '*';
    }
    public boolean flipCard()
    {
    if(label == '*')
    {
    label = convertToChar();
    return true;
    }
    else
    return false;
    }

    public char convertToChar()
    {
    String temp = cardNum + "";
    return temp.charAt(0);
    }

    //accessor methods

    public char getLabel()
    {
    return label;
    }
    public String toString()
    {
    return "" + label;
    }
    public boolean equals(Card other)^
    {
    return other.label == this.label;
    }

    public static void main(String[] args)
    {
    Card p1 = new Card();
    System.out.println("Card p1 = " + p1);

    //Place a new card on the blank p1
    System.out.println("We try and place a new card.");
    if(p1.flipCard())
    System.out.println("Successful attempt! ");
    else
    {
    System.out.println("Failed attempt! ");
    }

    System.out.println("Card p1 = " + p1);

    //Place a new card on the taken p1
    System.out.println("We try to flip the card, but it's already flipped");
    if(p1.flipCard())
    System.out.println("Successful attempt! ");
    else
    System.out.println("Failed attempt! ");

    System.out.println("Card p1 = " + p1);
    System.out.println("We reset p1.");
    p1.reset();
    System.out.println("Card p1 = " + p1);
    }
    }



    [code=Java]

    public class MainMemory {

    static Scanner input = new Scanner(System.in);
    static int i=0;
    static char[][] clearBoard = new char[4][4];
    static char[][] letterBoard = new char[4][4];
    public static void main(String[] args){
    drawBoard();


    }

    public static void drawMenu(){
    System.out.println("Welcome to the Match Up game! \n");
    System.out.println("Please select from the following: ");
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~");
    System.out.println("1. New Game");
    System.out.println("2. Quit");
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~");
    int optionSelect = input.nextInt();
    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~");
    while(optionSelect!=1 && optionSelect !=2){
    System.out.println("Please enter 1 (New Game) or 2(Quit)");
    optionSelect = input.nextInt();}
    if (optionSelect == 1)
    System.out.print("START GAME HERE********");
    else if (optionSelect == 2)
    System.out.println("Thanks for playing! Have a great day.");
    }


    public static void drawBoard(){
    for(int row1 = 0; row1 < 4; row1++) {
    System.out.println(""); // this will create a new line for each new row
    for(int col1 = 0; col1 < 4; col1++) {
    clearBoard[row1][col1]='.'; // this will print out the 4 row variable values
    }
    }

    System.out.format(" %2s %2s %2s %2s \n",'A','B','C','D');
    System.out.format(" %2s %2s %2s %2s \n",'-','-','-','-');
    System.out.format("1 |%2s %2s %2s %2s \n",clearBoard[0][0],clearBoard[0][1],clearBoard[0][2],clearBoard[0][3]);
    System.out.format("2 |%2s %2s %2s %2s \n",clearBoard[1][0],clearBoard[1][1],clearBoard[1][2],clearBoard[1][3]);
    System.out.format("3 |%2s %2s %2s %2s \n",clearBoard[2][0],clearBoard[2][1],clearBoard[2][2],clearBoard[2][3]);
    System.out.format("4 |%2s %2s %2s %2s \n",clearBoard[3][0],clearBoard[3][1],clearBoard[3][2],clearBoard[3][3]);


    System.out.println("Please enter a column (A,B,C, or D) and row (1,2,3,or 4). Ex: A3 : ");
    String userInput = input.nextLine();
    userInput = userInput.toUpperCase().trim();


    }

    }



    [code=java]


    public class Board {


    }
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Matching Game

    To wrap your code with code tags:
     <<<<<<<<<<<<< THIS goes before the code
     
    import java.util.*;
     
    public class MainMemory {
     
        public static void main  (String[] args)
        {
     
        }
     
     
     
     
     
     
       }
    <<<<<<<<<<<< THIS goes after the cod

    --- Update ---

    I think i did it right?

    --- Update ---

    i sent off the whole problem but i have been trying to get board right but i have no idea how to start it and finish it by the way im a new bee

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Matching Game

    Good luck.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] pattern matching
    By shenaz in forum Java Theory & Questions
    Replies: 3
    Last Post: April 8th, 2013, 10:03 AM
  2. matching game random number problem
    By nubshat in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 7th, 2013, 08:58 AM
  3. Matching Game Help
    By nubshat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2013, 03:15 PM
  4. Matching Pairs game - something's not right?
    By sambar89 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 9th, 2011, 02:54 PM