-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
75 lines (59 loc) · 1.6 KB
/
Main.java
File metadata and controls
75 lines (59 loc) · 1.6 KB
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
68
69
70
71
72
73
74
75
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
// CLASSE ABSTRATA
abstract class Entidade {
protected int x, y, largura = 40, altura = 40;
public Entidade(int x, int y) {
this.x = x;
this.y = y;
}
public abstract void desenhar(Graphics g);
public int getX() { return x; }
public int getY() { return y; }
public Rectangle getBounds() {
return new Rectangle(x, y, largura, altura);
}
}
// CLASSES COM HERANÇA
class Personagem extends Entidade {
private int moedas = 0;
public Personagem(int x, int y) {
super(x, y);
}
public void mover(int dx, int dy) {
x += dx;
y += dy;
}
public void coletar() { moedas++; }
public int getMoedas() { return moedas; }
public void resetarMoedas() { moedas = 0; }
@Override
public void desenhar(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(x, y, largura, altura);
}
}
class Moeda extends Entidade {
public Moeda(int x, int y) {
super(x, y);
}
@Override
public void desenhar(Graphics g) {
g.setColor(Color.YELLOW);
g.fillOval(x + 10, y + 10, 20, 20);
}
}
class Arvore extends Entidade {
public Arvore(int x, int y) {
super(x, y);
}
@Override
public void desenhar(Graphics g) {
g.setColor(new Color(34, 139, 34));
g.fillRect(x, y, largura, altura);
}
}
// Criado as classes Arvore, Moeda, Personagem, Entidade junto com Main.class