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 8256391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:51:03+00:00 2026-06-08T01:51:03+00:00

For some odd reason when I attempt to move my character in the game,

  • 0

For some odd reason when I attempt to move my character in the game, the array swapping for “movement” will not work and when I try to print the current position of the character for the first two moves in the game, nothing shows. It’s just acting odd in general. Could someone explain to me possibly what I’m doing wrong or at least how I can do it better? Thank.

Code:

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class Adventure {
    private Scanner in_file;
    private int x_size, y_size, px, py, dx, dy;
    private char[][] level;
    private boolean game;
    public Adventure() {
        x_size = y_size = 20;
        level = new char[x_size][y_size];
        px = py = 1;
        dx = dy = 0;
        game = true;
    }
    public static void main(String []args) {
        Adventure adv = new Adventure();
        adv.load_game();
        adv.main_game();
        System.out.println("ADVENTURE");
    }
    public void load_game() {
        try {
            in_file = new Scanner(new File("level.txt"));
        } catch (FileNotFoundException e) {
            System.err.println("ERROR: Level could not be loaded!");
            System.exit(1);
        }
        for (int i = 0; i < level.length; i++ ) {
            for (int j = 0; j < level[i].length; j++) {
                if (in_file.hasNextInt()) {
                    int nextInt = in_file.nextInt();
                    if (nextInt == 0) 
                        level[i][j] = '-';
                    else if (nextInt == 1)
                        level[i][j] = '#';
                }
            }
        }
        in_file.close();
    }
    public void new_game() { 

    }
    public void main_game() {
        Scanner key = new Scanner(System.in);
        Adventure adv_move = new Adventure();
        level[px][py] = 'Q';
        while (game) {
            for (int i = 0; i < level.length; i++) {
                for (int j = 0; j < level[i].length; j++) {
                    System.out.print(level[i][j]);
                }
                System.out.println();
            }
            System.out.println();
            System.out.print("Enter a letter choice to move ->");
            String temp = key.nextLine();
            if (temp.equals("w")) {
                dx = -1;
                dy = 0;
            }
            else if (temp.equals("a")) {
                dy = -1;
                dx = 0;
            }
            else if (temp.equals("s")) {
                dx = 1;
                dy = 0;
            }
            else if (temp.equals("d")) {
                dy = 1; 
                dx = 0;
            }
            else
                dx = dy = 0;
            System.out.println();
            adv_move.move_check();
        }
    }
    public void move_check() { //DYSFUNCTIONAL ARRAY!!!!
        System.out.println(level[px][py]);
    //  System.out.println(level[px+dx][py+dy]);
        if (level[px+dx][py+dy] != '#') {
            level[px][py] = '-';
            px += dx;
            py += dy;
            level[px][py] = 'Q';
        }   
        else 
            System.out.print("Move invalid.\n");
    }
    public void save_game() {

    }
}
  • 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-08T01:51:05+00:00Added an answer on June 8, 2026 at 1:51 am

    The issue you’re having is that in the main_game() method, you are creating a new Adventure object and calling move_check() on that, which doesn’t have any of your level data, which you loaded into the adv variable in main(). Therefore it is always referencing an empty char array and giving you unintended results.

    Removing the new object declaration and just calling move_check() itself should get you back on track.

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

Sidebar

Related Questions

I'm receiving this error for some odd reason: Fatal error: Class 'crud_model' not found
OK, I'm not super new to java but for some odd reason I can't
For some odd reason... Rackmonkey::CGI.pm is not being picked up... what am I doing
For some odd reason IE no longer will remember previously typed in usernames/passwords on
For some odd reason NSOrderedSet does not appear to be implemented in iOS. Is
So, I have a little code that doesn't work for some odd reason. It's
For some odd reason, the whatis command in my Unix shell (cygwin) is not
For some odd reason if a user tries to send an email to themselves,
For some odd reason the part where objects are shown and hidden in my
For some odd reason, my application likes to break on me when I switch

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.