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

Thread: [need help] I have problem with game algorithm

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [need help] I have problem with game algorithm

    diamonddash1.jpg
    I want to create games like this. And now I can check nearly of block click by user.(I use algorithm name "Floodfill")
    But when it disappear I can't check which block must fall replace that block.

    If you don't understand my explanation. Please see the picture on top. when I click purple block at (1,2). It will be floodfill to block at (1,3).
    And all of them will be disappear. BUT ! I can't coding to dismount the blue block add(1,1) to (1,3).

    Ps. I come from country where don't use English is Official language.
    If I use wrong word or wrong tense. Please provide me a correct word.

    Thank you


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: [need help] I have problem with game algorithm

    Quote Originally Posted by Tlipre View Post
    Ps. I come from country where don't use English is Official language.
    Welcome to the forum
    Happy to see you here no matter where you are from.

    Quote Originally Posted by Tlipre View Post
    I can't coding to dismount the blue block add(1,1) to (1,3).
    How does the program store these objects? Post the code?

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [need help] I have problem with game algorithm

    void floodfill(int x, int y, int color) {
    int[] left = { x - 1, y };
    int[] right = { x + 1, y };
    int[] up = { x, y - 1 };
    int[] down = { x, y + 1 };
    past.add(new Point(x, y));
    if (block[x][y].getColor() == color) {
    past_temp.add(new Point(x, y));
    count++;
    if (left[0] != -1 && !isInList(left[0], left[1])) {
    floodfill(left[0], left[1], color);
    }
    if (right[0] != 10 && !isInList(right[0], right[1])) {
    floodfill(right[0], right[1], color);
    }
    if (up[1] != -1 && !isInList(up[0], up[1])) {
    floodfill(up[0], up[1], color);
    }
    if (down[1] != 10 && !isInList(down[0], down[1])) {
    floodfill(down[0], down[1], color);
    }
    }
    }
    I have Global arrayList to keep beside of block what user click (beside and same color).In this code it name "pastTemp"

    Ps. The arrayList name "past" is build for keep block what I recursive to check. you can ignore them.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: [need help] I have problem with game algorithm

    A two dimensional array would provide the access to the objects more suited to your needs:

    [0,0] [0,1] [0,2] [0,3]
    [1,0] [1,1] [1,2] [1,3]
    [2,0] [2,1] [2,2] [2,3]
    [3,0] [3,1] [3,2] [3,3]

    With this you can easily move blocks side to side, or up and down

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: [need help] I have problem with game algorithm

    This thread has been cross posted here:

    http://www.java-forums.org/advanced-java/81414-need-help-i-have-problem-game-algorithm.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    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!

  6. The Following User Says Thank You to KevinWorkman For This Useful Post:

    jps (September 9th, 2013)

Similar Threads

  1. ArrayIndexOutOfBoundsException problem in decryption algorithm
    By aesguitar in forum What's Wrong With My Code?
    Replies: 10
    Last Post: July 13th, 2012, 03:49 PM
  2. Replies: 2
    Last Post: May 9th, 2012, 10:32 PM
  3. Euler Paths with dfs algorithm problem
    By claudio.r in forum Algorithms & Recursion
    Replies: 18
    Last Post: March 22nd, 2012, 04:39 PM
  4. CONNECT FOUR GAME-MINIMAX TO ALPHABETA ALGORITHM
    By AJreal in forum Algorithms & Recursion
    Replies: 0
    Last Post: March 6th, 2011, 02:30 PM
  5. I have algorithm problem
    By Newoor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 11th, 2009, 07:11 PM