LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-20-2006, 04:28 AM   #1
linuxmandrake
Member
 
Registered: Sep 2004
Distribution: debian sarge 64bit (AMD)
Posts: 709

Rep: Reputation: 30
while loop logic (java)


Code:
while(quadrant[x][y].sector[x2][y2] instanceof GameObject || (checkQuadrant(x,y)==true && 
       (object instanceof Enemy || object instanceof Planet || object instanceof StarBase))){

 private boolean checkQuadrant(int x,int y)
    {
        for (int x2 =0;x2 >0; x2++){
            for(int y2=0; y2>0;y2++)
            {
                if (quadrant[x][y].sector[x2][y2] instanceof Romulans)
                {
                    return true;
                }
            }
        }
        return false;
    }

doesn't that say if the current sector is an instanceof game object or the current quadrant has a romulan in it and the current object is an instance of an enemy, PLanet or star base then execute the body of the while loop. Don't get confused by quadrant and sectors> Basically the idea is there a 10*10 array representing a quadrant and each element has an another 10 *10 array representing the sector.

Last edited by linuxmandrake; 04-20-2006 at 04:31 AM.
 
Old 04-20-2006, 02:33 PM   #2
shakezilla
Member
 
Registered: Jun 2005
Location: U.S.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78

Rep: Reputation: 16
yes i think so.

a few points however:
Code:
for (int x2 =0;x2 >0; x2++){
            for(int y2=0; y2>0;y2++)
Did you mean less than 10 there?

Those 2 loops do nothing. Java loops are prechecked, meaning that the stop condition is checked before the first loop. x2 starts at zero, and the check is greater than zero.

Also just my opin, name that func something like hasRomulan()


java for games huh? i must be getting old.
 
Old 04-20-2006, 02:35 PM   #3
linuxmandrake
Member
 
Registered: Sep 2004
Distribution: debian sarge 64bit (AMD)
Posts: 709

Original Poster
Rep: Reputation: 30
hehe yeah u damn right u are hehe. THey are all over the net my friend. But yeah I noticed that shortly after my post oops. Thanks anyways!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 05:17 PM
Implementing a blocking loop (Java or C) Miaire Programming 4 04-28-2005 02:22 PM
Java Stopping an Infinite loop oulevon Programming 3 10-18-2004 10:11 PM
Java window not opening when loop included nro Programming 2 09-07-2004 02:16 PM
logic h/w Programming 8 01-02-2004 04:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration