-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeapon.java
36 lines (31 loc) · 1.03 KB
/
Weapon.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package Battleships;
/*
Weapon.java
Author: Mark Ma
Class: ICS4U
Last Modified: June 23rd, 2021
This class is an abstract class that represents the weapons/ammo that is fired by ships during battle.
It contains 2 abstract methods for the attack function as well as 1 abstract method for sound effects.
*/
public abstract class Weapon { //demonstrates encapsulation and polymorphism
//instance fields
protected String name, desc, placement;
protected int cost;
//accessor method for cost of weapon
public int getCost() {
return this.cost;
}
/*String stringInfo()
returns String - the info of this weapon
no parameters
this method creates and returns a string about the info
of this weapon
*/
public String stringInfo() {
return name+": "+desc+" cost: $"+cost+"\narea hit: \n"+this.placement;
}
//abstract methods
abstract void makeSound();
abstract void p1Attack(Player p1, GameField g, int x, int y);
abstract void p2Attack(Player p2, GameField g, int x, int y);
}