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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:41:55+00:00 2026-06-13T11:41:55+00:00

I am writing a program that pits two tanks against each other. I have

  • 0

I am writing a program that pits two tanks against each other. I have written all the methods except the fire that would end the game. So far

public class Tank {
    Tank() {
        int xPos, yPos;
        char direction;
        boolean loaded = 0;
    }

    public void move(Tank currentPlayer) {
        if (yPos<=4 && yPos>=0) {
            if (xPos<=4 && xPos>=0) {
                if (currentPlayer.direction == 'u') {
                    currentPlayer.yPos--;
                }
                if (currentPlayer.direction == 'd') {
                    currentPlayer.yPos++;
                }
                if (currentPlayer.direction == 'l') {
                    currentPlayer.xPos--;
                }
                if (currentPlayer.direction == 'r') {
                    currentPlayer.xPos++;
                }
            }
        }
    }

    public void turn(boolean bool, Tank currentPlayer) {
        if (currentPlayer.direction == 'u') {
            currentPlayer.direction ='r';
        }
        if (currentPlayer.direction == 'd') {
            currentPlayer.direction = 'l';
        }
        if (currentPlayer.direction == 'l') {
            currentPlayer.direction ='u';
        }
        if (currentPlayer.direction == 'r') {
            currentPlayer.direction ='d';
        }
    }

    public void load(Tank currentPlayer) {
        currentPlayer.loaded=true;
    }

    public int fire(Tank currentPlayer, Tank jim) {
        // ???
    }    
}

How do I go about finishing my program? Any help would be appreciated.

  • 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-13T11:41:56+00:00Added an answer on June 13, 2026 at 11:41 am

    You need a getter for the x-position, the y-position, and the current orientation of the tank. For example:

    public int getX();
    public int getY();
    public char getOrientation();
    

    By calling these methods, you should get the x position, y position, and orientation of the tank. Then to check a hit. You know what direction you’re facing. So if you’re facing up, see if the other tank is on the same x as you, and that their y is above yours.

    int otherX = jim.getX();
    int otherY = jim.getY();
    
    switch (currentPlayer.getOrientation())
    {
        case 'u':
            //Check if you're in same x
            //Check if above player
            break;
        case ... etc.
    }
    

    Then in the case of a hit, in other words if the conditions are met. The game should end with the currentPlayer victorious.

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

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I'm writing a program that show the thread list of all opened process. With
I am currently writing a program that will eventually compare the files in two
I'm writing a program that gathers user input for two file names, and opens
I've been writing a program that serves in two primary parts- managed UI and
I have tried writing program that plays a sound file but have been unsuccessful
I'm writing a program that contains a generational garbage collector. There are just two
Writing a program that should be portable in Linux and Windows enviroments I have
I am writing a program that executes a set of tasks sequentially. Each task
I'm writing a program that handles DBs and writes any changes into ListView for

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.