-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapaVista.java
127 lines (77 loc) · 1.97 KB
/
MapaVista.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.FileReader;
import java.util.Observable;
import java.util.Observer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class MapaVista extends JPanel implements Observer
{
private PacmanMain main;
private MapaModelo mapa;
private Game game;
public static int tamano= 29;
public int height;
public int width;
private Image[]mapPunto;
private Image[] mapImages;
private FileReader leer;
private String nombre="mapa.txt";
public MapaVista(MapaModelo mapa,PacmanMain main,Game game)
{
this.main = main;
this.mapa = mapa;
this.game = game;
main.add(this);
setDoubleBuffered(true);
setOpaque(true);
setBounds(0, 0, 24*24, 24*24);
mapImages = new Image[6];
try{
Toolkit tk = Toolkit.getDefaultToolkit();
for(int i=0;i<6;i++)
{
ImageIcon imagenFondo = new ImageIcon(getClass().getResource("/ImaMapa/mapa"+i+".png"));
mapImages[i] = imagenFondo.getImage();
}
}
catch (Exception e) {
System.out.print("No cargo imagenes");
}
height = mapImages[1].getHeight(null);
width = mapImages[1].getWidth(null);
}
public int height(){return height;}
public int width(){return width;
}
public void paint(Graphics g)
{
if(mapa.getWin())
{ g.setColor(Color.red);
game.setWin(true);}
if(mapa.getGameOver() && mapa.getEstado()==3)
{
g.setColor(Color.blue);
game.setgameOver(true);
}
if(mapa.getEstado() == 2 || mapa.getEstado()==1 )
{
for(int x=0;x<mapa.getFilas();x++)
for(int y=0;y<mapa.getColumnas();y++)
{
g.drawImage(mapImages[mapa.getPosicion(x, y)],y*height,x*height,this);
}
}
}
public void paint2D()
{
}
public void update(Observable arg0, Object arg1)
{
repaint();
//paintImmediately(, arg1, arg2, arg3)
main.setDatos();
}
}