Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:52:15+00:00 2026-06-14T08:52:15+00:00

Object is supposed to change mode (movement algorithm) depending on the time elapsed (switch

  • 0

Object is supposed to change mode (movement algorithm) depending on the time elapsed (switch between chase or scatter). I created a while loop but the object moves only in one mode (chase) and that is strange since I set it to be scatter initially.

private static int seconds=0;
private static boolean ghostalive;

protected static final int chaseMode = 0;
protected static final int scatterMode = 1;
protected static final int frightenedMode = 2;

static int mode; //initially ghost start in scatterMode

public Ghost(int x, int y, Maze maze){
    super(x, y, maze);
    futureDirection = 0;
    timer = 0;
    mode = getMode();
}     

public static int getMode(){
    mode=setMode();
    return mode;
}

//LEVEL 1
//scatter for 7s 
//chase for 20s 
//scatter for 7s 
//chase for 20s 
//scatter for 5s 
//chase for 20s
//scatter for 5s 
//chase indefinite

public static int setMode(){

while(ghostalive){

    mode = scatterMode;
    if(seconds>7)
        mode = chaseMode;//chaseMode=true;
    if(seconds>27)
        mode = scatterMode;
    if(seconds>34)
        mode = chaseMode;
    if(seconds>54) 
        mode = scatterMode;
    if(seconds>59) 
        mode = chaseMode;
    if(seconds>79)
        mode = scatterMode;
    if(seconds>84)
        mode = chaseMode;

    seconds++;      
   }    
       return mode;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:52:16+00:00Added an answer on June 14, 2026 at 8:52 am

    Your comment says it starts in scatterMode, but you don’t set the mode to anything when it’s declared. So, it actually defaults to chaseMode. Because you don’t initialize the boolean ghostAlive, it defaults to false, meaning your loop never happens, which means the mode doesn’t get set to scatterMode, which means it always stays in chaseMode.

    To begin to fix this, you should initialize ghostAlive to true. Then, for all the ifs, you can put a ghostAlive = false statement to end the loop. I’m not exactly sure what your objective is with this method in context of your whole project, but that bit of knowledge should help you out either way. You have to make ghostAlive false inside the loop somehow to get out of the loop.

    Not sure why you’re using all these static methods and fields, though. Seem unnecessary for what you’ve posted.

    Additionally, it’s good practice to put if statements, even single statement ones, in curly brackets. This will help curb any errors if you have to later add some (as it appears you will have to here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This function is supposed to change the background color of the object being clicked
Possible Duplicate: Submit a form using jQuery $('#form') Supposed the jQuery Object of the
Is the first parameter supposed to be an object? A tutorial I'm following has
Is there a way to change a valid and existing Hadoop Path object into
I'm having a hard time understanding how DataList select/unselect is supposed to work. I
I am writing an client application in C# which will be supposed to change
I have an Extension method which is supposed to filter a Queryable object (IQueryable)
I'm supposed to change the frmPersonnelVerified code behind to get the values from the
I'm importing a plist into an NSDictionary object and want to change the contents
My app has a custom object that contains an NSDate. I want to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.