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 4 of 4

Thread: Need help with a Java Assignment regarding enums and arrays

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Need help with a Java Assignment regarding enums and arrays

    I have an assignment to make a game of breakthrough by creating a class that links provided classes together and makes the game playable.

    The enum class is provided below.

    I have just started, but I'm having trouble with some basics. First off, there is an enum class which I need to relate to but don't know how,
    as I need to be able to make a method "public Piece getTurn()" in my class which relates to this enum class. The "getTurn()" method needs to be able
    to give the player their turn (return Piece.WHITE or Piece.Black, white player starts or black player starts respectively). The rules are white
    starts, and then you take turn from there.

    I also need to write another method "startGame()" which generates the board via a 2d array with either WHITE, BLACK, or NONE spaces (as shown in the code pasted).
    Its a 4x6 board like this : (B = Black piece, W = White piece, N = empty space)

    W W W W
    W W W W
    N N N N
    N N N N
    B B B B
    B B B B

    How do I do this and generate the array so that other methods may do checks on it too? I managed to make an array that does this board but its created completely
    within the method so other methods can't access the same array again.

    Please help



    package com1003.breakthrough;
     
    public enum Piece {
    	NONE, 
    	WHITE, 
    	BLACK;
     
    	// This method returns the direction of travel of the piece in terms of increasing or
    	// decreasing row numbers.
    	// A white piece moves 'down' the board, e.g. from (0, 1) to (0, 2), thus its direction is 1,
    	// whereas a black piece moves 'up' the board, e.g. from (0, 4) to (0, 3), thus its direction is -1.
    	public int getDirection() {
    		if (this == WHITE) {
    			return 1;
    		} else if (this == BLACK) {
    			return -1;
    		} else {
    			return 0;
    		}
    	}
     
    	public Piece getOpponent() {
    		if (this == WHITE) {
    			return BLACK;
    		} else if (this == BLACK) {
    			return WHITE;
    		} else {
    			return NONE;
    		}
    	}
    }


  2. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need help with a Java Assignment regarding enums and arrays

    How come nobody can help, I thought this would be easy for some of the advanced programmers, as this is only an assignment mid-way through a first year course..

  3. #3
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Need help with a Java Assignment regarding enums and arrays

    Slice your original question up and only leave a short, fruitful and direct question (not plural) and any errors you get.

    I need this and that to happen isn't the best way to structure a question.
    Something to the point attracts more helpers.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need help with a Java Assignment regarding enums and arrays

    Quote Originally Posted by Kranti1992 View Post
    How come nobody can help, I thought this would be easy for some of the advanced programmers, as this is only an assignment mid-way through a first year course..
    Please keep in mind that a couple hours is not a very long wait for free help, especially on a weekend. We're doing this in our spare time, for free, so some patience would be appreciated. Also, making multiple posts and bumping your own threads will actually decrease your chances of getting help. The best way to get help is to follow the directions in the link in my signature on asking questions the smart way, provide an SSCCE, and ask a specific technical question. It's pretty hard to answer "how do I do this" type questions other than to point you to the basic tutorials and google.

    The OP did create another post, although it still contains "how do I do this" type questions: http://www.javaprogrammingforums.com...-question.html

    I'm locking this thread now to avoid duplicating answers, so please continue discussion in the other thread.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. enums..
    By imsuperman05 in forum Object Oriented Programming
    Replies: 3
    Last Post: December 29th, 2011, 10:37 PM
  2. [SOLVED] A little assignment involving arrays.
    By Melawe in forum What's Wrong With My Code?
    Replies: 39
    Last Post: May 1st, 2011, 10:43 PM
  3. [SOLVED] Java assignment, concerning Arrays and Loops
    By trejorchest in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 17th, 2011, 12:59 PM
  4. How To Use Enums
    By Json in forum Java Programming Tutorials
    Replies: 6
    Last Post: October 16th, 2009, 04:17 PM
  5. How To Use Enums
    By Json in forum Java Code Snippets and Tutorials
    Replies: 6
    Last Post: October 16th, 2009, 04:17 PM

Tags for this Thread