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

  • SEARCH
  • Home
  • 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 7420587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:15:52+00:00 2026-05-29T08:15:52+00:00

I want to place obstacles on a game board using a random number generator.

  • 0

I want to place obstacles on a game board using a random number generator. 5% of the board will have a pit which is defined as “*”, but the asterisk will not show unless the players lands in that spot; 10% of the board will be blocked spots indicated as “X”; the remaining 85% will be open spaces shown as “.” The game board is a 10×10 array with the letter “P” at the upper left hand corner as the starting point for the player, and a “T” at the bottom right hand corner for the ending (treasure). So far I’ve got this, and I been watching video tutorials as well as reading to try and put this all together, but still stuck:

import java.util.Scanner;
import java.util.Random;

public class Adventure {

    public static void main(String[] args) {
        char grid[][]= new char[10][10];
        Scanner move = new Scanner(System.in);
        System.out.println("Here is the current game board:");
        System.out.println("-------------------------------");

        for(int i=0; i<grid.length; i++) {          
            for(int j=0; j<grid.length; j++) {
                grid[i][j]='.';
                grid[0][0]='P';
                grid[9][9]='T';
                System.out.print(grid[i][j]);
            }
        Random obstacle = new Random();
        int obstacleNum;
        for(int k=1; k<=100; k++) {
            obstacleNum = 1+obstacle.nextInt(100);

        }
            System.out.println("");
        }
        System.out.printf("Enter your move (U/D/L/R)>");
    }
}

Not sure where to go after “obstacleNum = 1+obstacle.nextInt(100);”

  • 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-05-29T08:15:52+00:00Added an answer on May 29, 2026 at 8:15 am

    As for the actual interactivity, here is an outline:

    x = 0; //coordinates of player, location of P
    y = 0;
    

    To hide the pits, before printing, stick in and if statement:

    if(grid[i][j]=='*') {
        System.out.println("."); //looks like ordinary land
    } else {
        System.out.println(grid[i][j]);
    }
    

    Now have this run when it receives input (pseudo)

    //following if for moving left
    if(grid[y][x+1] isn't out of bounds and right key is pressed and grid[y][x+1]!='X') {
        grid[y][x] = '.'; //removes current position
        x++; //change location
    }
    //following if for moving right
    if(grid[y][x-1] isn't out of bounds and left key is pressed and grid[y][x-1]!='X') {
        grid[y][x] = '.'; //removes current position
        x--; //change location
    }
    //following if for moving down
    if(grid[y+1][x] isn't out of bounds and down key is pressed and grid[y+1][x]!='X') {
        grid[y][x] = '.'; //removes current position
        y++; //change location
    }
    //following if for moving up
    if(grid[y-1][x] isn't out of bounds and up key is pressed and grid[y-1][x]!='X') {
        grid[y][x] = '.'; //removes current position
        y--; //change location
    }
    if(grid[y][x] == '*') { //when trapped in a pit
        System.out.println("You fell in a pit. Game over.");
    } else {
        grid[y][x] = 'P'; //update grid
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to place a game board in JPanel and i'm using GridLayout 10x10
I have 5-10 independent projects that I want place under version control using Git.
I want to place 3 divs side by side using CSS. I have gone
I have this image: But i want to place text in the middle like
I have several XML tags which I want to place in four blocks (divs).
I want place ads in my website, but I'm unsure about the common practices
I want to place a table on my page. I have two tables in
I have a dialog that I want to place within another dialog and position
I have a document where I want to place an unnumbered section in my
I have the following values that I want to place into a mysql db

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.