-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttackItems.java
67 lines (65 loc) · 1.86 KB
/
AttackItems.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
import java.util.*;
/**
* Write a description of class AttackItems here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class AttackItems extends BattleMenu
{
public int number;
public Player p;
public Enemy e;
/**
* Act - do whatever the AttackItems wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void setNum(int num)
{
number = num;
}
public AttackItems(String text, Player p1, Enemy e1)
{
GreenfootImage image = new GreenfootImage(100,20);
image.fillRect(0, 0,100, 20);
image.setColor(new Color(255, 255, 255, 100));
image.fillRect(5, 5, 90, 10);
Font font = image.getFont();
font = font.deriveFont(12);
image.setFont(font);
image.setColor(Color.WHITE);
image.drawString(text, 35, 15);
setImage(image);
p=p1;
e=e1;
}
public void act()
{
if(Greenfoot.mouseClicked(this))
{
CalculateBattle myB;
double dbl = p.accuracy[0];
if(Math.random()<p.accuracy[number])
{
myB= new CalculateBattle(p,number,e);
if(myB.x==1)
{
Battle myW = (Battle)getWorld();
myW.world.removeObject(e);
Greenfoot.setWorld(myW.world);
}
}
Random rnd = new Random();
myB = new CalculateBattle(e,rnd.nextInt(4),p);
if(myB.x==1)
{
Battle myW = (Battle)getWorld();
myW.world.removeObject(e);
Greenfoot.setWorld(myW.world);
}
}
// Add your action code here.
}
}