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
| public class DrawView extends View{
Paint paint = new Paint();
private ArrayList<Case> tabLaby = new ArrayList<Case>();
public DrawView(Context context, ArrayList<Case> tablaby) {
super(context);
paint.setColor(Color.GREEN);
this.tabLaby = tablaby;
}
@Override
public void onDraw(Canvas canvas) {
int x,y;
Bitmap mur = BitmapFactory.decodeResource(getResources(), R.drawable.mur);
Bitmap arrivee = BitmapFactory.decodeResource(getResources(), R.drawable.arrivee);
Bitmap depart = BitmapFactory.decodeResource(getResources(), R.drawable.depart);
for(int i=0; i< tabLaby.size(); i++) {
x = (int) tabLaby.get(i).getX();
x*= tabLaby.get(i).getTaille();
y = (int) tabLaby.get(i).getY();
y*= tabLaby.get(i).getTaille();
switch(tabLaby.get(i).getTypeCase()) {
case MUR:
canvas.drawBitmap(mur, x, y,null);
break;
case ARRIVEE:
canvas.drawBitmap(arrivee, x, y,null);
break;
case DEPART:
canvas.drawBitmap(depart, x, y,null);
}
}
}
} |
Partager