Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Two chickens face each other on a 10x10 grid. One chicken is controlled by the computer. One chicken starts in the upper left corner

JAVA

Two chickens face each other on a 10x10 grid. One chicken is controlled by the computer. One chicken starts in the upper left corner and the other in the lower right corner. The chicken can move or shoot, but not both. The way the chicken moves is the way the chicken is pointed. It can change its direction, but this is one turn. The base chicken class can only move two squares in the direction it faces. The chicken can only shoot two squares away in a straight line the way it is facing. The chicken will have variables to store the Hit points. Hit points represent how many times it can be hit before it dies. I.E. if a chicken has 10 hit points and it is hit for 1 damage point it will have 9 hit points left. The amount of damage could change depending on which sub chicken is firing at it.

A turn consists of: Chicken 1 Move: Pick a direction and update square 2 spaces in that direction. If the chicken is at the end of the grid it can only go that far. Or Chicken 1 fire: Fire two squares away in the direction the chicken is facing. Check to see if chicken 2 is there, if so, deduct point(s) from chicken 2s hit points. If chicken 2s hit points are zero game is over. If not, chicken two takes turn. Or Chicken 1 will change directions and prepare to move or fire the next turn.

Using the following code , an interface for the chicken class.

--------------------------------------------------------------------------------------------------------------------------------------

public interface IChicken {

public void move_left();

public void move_right();

public void move_up();

public void move_down();

public int[] fire();

public void change_direction(int direction);

public int[] get_location();

public void hit(int damage);

public boolean is_alive();

public int set_vars(int min, int max,int var);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions