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

Thread: Java TV Board Game/Grid + Moving objects

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java TV Board Game/Grid + Moving objects

    Hello!

    Does anyone have a tutorial or some tips on making a grid in java where it is possible to select objects via the keyboard and move them to other positions in the grid.

    And check if the move is a valid move so you have to be able to track the item on the board.

    Kind regards.
    Last edited by Massaslayer; December 12th, 2011 at 09:19 AM.


  2. #2
    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: Java TV Board Game/Grid + Moving objects

    That's a pretty specific request, so you'd be lucky to find a tutorial on exactly that. But in general, what you're talking about is two steps. The first is to write the logic for check whether a move is valid. You can do this with a command-line interface, or just by hardcoding board moves. The second step is to write the KeyListener logic.
    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!

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java TV Board Game/Grid + Moving objects

    Quote Originally Posted by KevinWorkman View Post
    That's a pretty specific request, so you'd be lucky to find a tutorial on exactly that. But in general, what you're talking about is two steps. The first is to write the logic for check whether a move is valid. You can do this with a command-line interface, or just by hardcoding board moves. The second step is to write the KeyListener logic.
    I tried to specify my "vision"

    Move in the grid using the arrow keys (up down left right) then when you get to a position you need to press "enter" to select it then the object should be highlighted and you should be able to move to another position that is "empty" place on the board and then press enter again.

    When you "drop" you need to check if your move is valid this means that you can't move to an empty space more then 2 block aways.

    I tried to draw it:



    The "O" can only be placed in place "1" and not in "2"


    All the output is via JavaTV to make it extra harder
    Attached Images Attached Images

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java TV Board Game/Grid + Moving objects

    Do you have an java source code that you are having a problem with?

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java TV Board Game/Grid + Moving objects

    Quote Originally Posted by Norm View Post
    Do you have an java source code that you are having a problem with?
    I know what to make sort of but I need examples:

    I think I need GridLayout & keyboard listener but no clue on how to select elements etc.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java TV Board Game/Grid + Moving objects

    how to select elements etc.
    What would indicate if an element is selected or not? Some components display differently when selected.

  7. #7
    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: Java TV Board Game/Grid + Moving objects

    Like I said, your first step should be to do this without a GUI at all. Use a command line interface or simply hardcode moves, and write the logic for determining whether a move is valid, what happens when a move is done, etc.

    After you have that working, only then should you worry about the GUI. Taking this approach will save you a ton of headaches in the long run.
    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. help with board game assignment
    By pjay in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 19th, 2011, 12:58 PM
  2. HELP! HOW TO PRINT A GRID IN JAVA (NO GUI...)
    By imicrothinking in forum Java Theory & Questions
    Replies: 0
    Last Post: October 19th, 2011, 08:39 AM
  3. Java applet for Fibonacci grid
    By jnapoles in forum Java Applets
    Replies: 1
    Last Post: January 27th, 2011, 01:56 AM
  4. java grid and colors/graphics
    By ajmukon in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 25th, 2011, 03:38 PM
  5. DOS board game
    By SageNTitled in forum Java Theory & Questions
    Replies: 5
    Last Post: March 4th, 2010, 03:53 PM