Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by 1 ( 14 years ago )
package Gracz;
/**
*
* @author michal
*/
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.lang.Integer;
public class Zolnierz extends Gracz{
private final static int ZYCIE = 100;
private final static int SZYBKOSC = 100;
private final static int WYMIARY[] = {20,10};
private final static String BRONIE[] = {"Glock","Granat"};
private List<Object> bron = null;
private int szybkosc;
private int aBron;
public Zolnierz(int x, int y) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException, SecurityException, NoSuchMethodException {
super(Zolnierz.ZYCIE, x, y);
this.szybkosc = Zolnierz.SZYBKOSC;
this.aBron = 0;
bron = new ArrayList<Object>();
try {
for(String tmp : Zolnierz.BRONIE){
bron.add( Class.forName("Gracz."+tmp).newInstance());
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List<String> getListaBroni(){
List<String> tmp = new ArrayList<String>();
for (Object x : bron){
tmp.add(bron.indexOf(x)+". " + x.getClass().getName());
}
return tmp;
}
public int addBron(Object obj) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
int i = -1;
for (Object x : this.bron){
if(x.getClass().getName() == obj.getClass().getName()){
i = this.bron.indexOf(x);
break;
}
}
if(i==-1){
this.bron.add(obj);
}
else{
Method m = this.bron.get(i).getClass().getMethod("getAmunicja");
Method m1 = this.bron.get(i).getClass().getMethod("addAmunicja",Integer.class);
m1.invoke(this.bron.get(i), m.invoke(this.bron.get(i)));
}
return 0;
}
public Object delBron(int id){
String tmp = this.bron.get(this.aBron).getClass().getName();
Object toRemove = this.bron.get(id);
this.bron.remove(id);
aBron = 0;
for (Object x : this.bron){
if(x.getClass().getName() == tmp){
aBron = this.bron.indexOf(x);
break;
}
}
return toRemove;
}
public void strzelaj() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
Method m1 = this.bron.get(this.aBron).getClass().getMethod("getMoc");
System.out.println(m1.invoke(this.bron.get(this.aBron)));
}
public void zmienBron(int id){
this.aBron = id;
}
public int ileAmunicji() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
Method m1 = this.bron.get(this.aBron).getClass().getMethod("getAmunicja");
return (Integer) m1.invoke(this.bron.get(this.aBron));
}
}
Revise this Paste
Children: 45257