id
stringlengths
36
36
text
stringlengths
1
1.25M
a5987b25-aac4-47b4-b257-d028dc559ffa
public double optDouble(String key, double defaultValue) { try { return this.getDouble(key); } catch (Exception e) { return defaultValue; } }
fe90052d-d8e5-4342-9912-c8a60f1955d2
public int optInt(String key) { return this.optInt(key, 0); }
c05ce2e9-e08c-41c1-bf2d-dc218af7b0e0
public int optInt(String key, int defaultValue) { try { return this.getInt(key); } catch (Exception e) { return defaultValue; } }
2419fbb7-f2df-4410-a1cc-f7c355f5f2f6
public JSONArray optJSONArray(String key) { Object o = this.opt(key); return o instanceof JSONArray ? (JSONArray)o : null; }
86a68123-94a8-4c17-b616-6bc026e1fdf4
public JSONObject optJSONObject(String key) { Object object = this.opt(key); return object instanceof JSONObject ? (JSONObject)object : null; }
4c30c8bc-0a9e-4da4-b0b9-2f2a4161d2e3
public long optLong(String key) { return this.optLong(key, 0); }
d7fd0078-aa3b-4062-ae3b-d20b369d5656
public long optLong(String key, long defaultValue) { try { return this.getLong(key); } catch (Exception e) { return defaultValue; } }
9eaeb9ac-6b98-460c-b6ee-d14257488fda
public String optString(String key) { return this.optString(key, ""); }
b6eeca94-d757-4e58-a4e2-709ae9fc4f99
public String optString(String key, String defaultValue) { Object object = this.opt(key); return NULL.equals(object) ? defaultValue : object.toString(); }
70e5d005-297d-4443-a4cf-d4eb3d2f226b
private void populateMap(Object bean) { Class klass = bean.getClass(); // If klass is a System class then set includeSuperClass to false. boolean includeSuperClass = klass.getClassLoader() != null; Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods(); for (int i = 0; i < methods.length; i += 1) { try { Method method = methods[i]; if (Modifier.isPublic(method.getModifiers())) { String name = method.getName(); String key = ""; if (name.startsWith("get")) { if ("getClass".equals(name) || "getDeclaringClass".equals(name)) { key = ""; } else { key = name.substring(3); } } else if (name.startsWith("is")) { key = name.substring(2); } if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) { if (key.length() == 1) { key = key.toLowerCase(); } else if (!Character.isUpperCase(key.charAt(1))) { key = key.substring(0, 1).toLowerCase() + key.substring(1); } Object result = method.invoke(bean, (Object[])null); if (result != null) { this.map.put(key, wrap(result)); } } } } catch (Exception ignore) { } } }
d1bc8145-5fb2-4871-b08d-c96c970e1624
public JSONObject put(String key, boolean value) throws JSONException { this.put(key, value ? Boolean.TRUE : Boolean.FALSE); return this; }
91c5cbad-14a2-40a5-a88a-4d43a25e0bd7
public JSONObject put(String key, Collection value) throws JSONException { this.put(key, new JSONArray(value)); return this; }
d760523a-d413-4dc7-88ad-aa6296b5e838
public JSONObject put(String key, double value) throws JSONException { this.put(key, new Double(value)); return this; }
1fc73286-e4a1-4736-95df-e1a093f83ee5
public JSONObject put(String key, int value) throws JSONException { this.put(key, new Integer(value)); return this; }
c3b7a99b-8faf-40dd-9df8-359864eac7f3
public JSONObject put(String key, long value) throws JSONException { this.put(key, new Long(value)); return this; }
659038d0-7aef-40bc-8bf2-d90247c07ac4
public JSONObject put(String key, Map value) throws JSONException { this.put(key, new JSONObject(value)); return this; }
3bbc5189-b3e6-494f-9bf6-d9ac03547ef6
public JSONObject put(String key, Object value) throws JSONException { String pooled; if (key == null) { throw new JSONException("Null key."); } if (value != null) { testValidity(value); pooled = (String)keyPool.get(key); if (pooled == null) { if (keyPool.size() >= keyPoolSize) { keyPool = new HashMap(keyPoolSize); } keyPool.put(key, key); } else { key = pooled; } this.map.put(key, value); } else { this.remove(key); } return this; }
c869f335-0916-47a3-89ce-3005a6550c9c
public JSONObject putOnce(String key, Object value) throws JSONException { if (key != null && value != null) { if (this.opt(key) != null) { throw new JSONException("Duplicate key \"" + key + "\""); } this.put(key, value); } return this; }
d29beec2-23c1-4fd3-8055-6c1ba1403659
public JSONObject putOpt(String key, Object value) throws JSONException { if (key != null && value != null) { this.put(key, value); } return this; }
ba694c2f-2787-49a8-a3b3-334ff4960c39
public static String quote(String string) { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { try { return quote(string, sw).toString(); } catch (IOException ignored) { // will never happen - we are writing to a string writer return ""; } } }
89a7982b-46c5-46b4-b81f-477ebfcbffb4
public static Writer quote(String string, Writer w) throws IOException { if (string == null || string.length() == 0) { w.write("\"\""); return w; } char b; char c = 0; String hhhh; int i; int len = string.length(); w.write('"'); for (i = 0; i < len; i += 1) { b = c; c = string.charAt(i); switch (c) { case '\\': case '"': w.write('\\'); w.write(c); break; case '/': if (b == '<') { w.write('\\'); } w.write(c); break; case '\b': w.write("\\b"); break; case '\t': w.write("\\t"); break; case '\n': w.write("\\n"); break; case '\f': w.write("\\f"); break; case '\r': w.write("\\r"); break; default: if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) { w.write("\\u"); hhhh = Integer.toHexString(c); w.write("0000", 0, 4 - hhhh.length()); w.write(hhhh); } else { w.write(c); } } } w.write('"'); return w; }
dc79070f-a7aa-4e16-b6e6-5ecb5aa3069e
public Object remove(String key) { return this.map.remove(key); }
bb976def-1086-493d-bfa0-bc827fba72b6
public static Object stringToValue(String string) { Double d; if (string.equals("")) { return string; } if (string.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (string.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (string.equalsIgnoreCase("null")) { return JSONObject.NULL; } /* * If it might be a number, try converting it. * If a number cannot be produced, then the value will just * be a string. Note that the plus and implied string * conventions are non-standard. A JSON parser may accept * non-JSON forms as long as it accepts all correct JSON forms. */ char b = string.charAt(0); if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) { d = Double.valueOf(string); if (!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); if (myLong.longValue() == myLong.intValue()) { return new Integer(myLong.intValue()); } else { return myLong; } } } catch (Exception ignore) { } } return string; }
6d4967bb-eb3d-49d7-917c-6b387bac7674
public static void testValidity(Object o) throws JSONException { if (o != null) { if (o instanceof Double) { if (((Double)o).isInfinite() || ((Double)o).isNaN()) { throw new JSONException( "JSON does not allow non-finite numbers."); } } else if (o instanceof Float) { if (((Float)o).isInfinite() || ((Float)o).isNaN()) { throw new JSONException( "JSON does not allow non-finite numbers."); } } } }
1da75314-a488-4dd8-be7a-64e04bcd2753
public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
2d8f4b4e-6d7d-4d39-804b-c3924e421538
public String toString() { try { return this.toString(0); } catch (Exception e) { return null; } }
7814384f-bccf-425c-a79e-f5cc8198a916
public String toString(int indentFactor) throws JSONException { StringWriter w = new StringWriter(); synchronized (w.getBuffer()) { return this.write(w, indentFactor, 0).toString(); } }
6fc67035-fe9d-48d3-a532-3d0f9c6d479c
public static String valueToString(Object value) throws JSONException { if (value == null || value.equals(null)) { return "null"; } if (value instanceof JSONString) { Object object; try { object = ((JSONString)value).toJSONString(); } catch (Exception e) { throw new JSONException(e); } if (object instanceof String) { return (String)object; } throw new JSONException("Bad value from toJSONString: " + object); } if (value instanceof Number) { return numberToString((Number) value); } if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) { return value.toString(); } if (value instanceof Map) { return new JSONObject((Map)value).toString(); } if (value instanceof Collection) { return new JSONArray((Collection)value).toString(); } if (value.getClass().isArray()) { return new JSONArray(value).toString(); } return quote(value.toString()); }
62ee11f4-1b03-409c-933e-ffb669b176a5
public static Object wrap(Object object) { try { if (object == null) { return NULL; } if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String) { return object; } if (object instanceof Collection) { return new JSONArray((Collection)object); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { return new JSONObject((Map)object); } Package objectPackage = object.getClass().getPackage(); String objectPackageName = objectPackage != null ? objectPackage.getName() : ""; if ( objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null ) { return object.toString(); } return new JSONObject(object); } catch(Exception exception) { return null; } }
d15734cc-ed1f-48be-96d1-907ebd158a74
public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
ccf981e3-53d1-4663-9459-9d6052d5fb09
static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException { if (value == null || value.equals(null)) { writer.write("null"); } else if (value instanceof JSONObject) { ((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { new JSONObject((Map) value).write(writer, indentFactor, indent); } else if (value instanceof Collection) { new JSONArray((Collection) value).write(writer, indentFactor, indent); } else if (value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); } else if (value instanceof Number) { writer.write(numberToString((Number) value)); } else if (value instanceof Boolean) { writer.write(value.toString()); } else if (value instanceof JSONString) { Object o; try { o = ((JSONString) value).toJSONString(); } catch (Exception e) { throw new JSONException(e); } writer.write(o != null ? o.toString() : quote(value.toString())); } else { quote(value.toString(), writer); } return writer; }
a6a1e2f1-6417-42d8-be9b-b2f81ffb40e9
static final void indent(Writer writer, int indent) throws IOException { for (int i = 0; i < indent; i += 1) { writer.write(' '); } }
532fe645-e33f-494d-8100-e2572652373b
Writer write(Writer writer, int indentFactor, int indent) throws JSONException { try { boolean commanate = false; final int length = this.length(); Iterator keys = this.keys(); writer.write('{'); if (length == 1) { Object key = keys.next(); writer.write(quote(key.toString())); writer.write(':'); if (indentFactor > 0) { writer.write(' '); } writeValue(writer, this.map.get(key), indentFactor, indent); } else if (length != 0) { final int newindent = indent + indentFactor; while (keys.hasNext()) { Object key = keys.next(); if (commanate) { writer.write(','); } if (indentFactor > 0) { writer.write('\n'); } indent(writer, newindent); writer.write(quote(key.toString())); writer.write(':'); if (indentFactor > 0) { writer.write(' '); } writeValue(writer, this.map.get(key), indentFactor, newindent); commanate = true; } if (indentFactor > 0) { writer.write('\n'); } indent(writer, indent); } writer.write('}'); return writer; } catch (IOException exception) { throw new JSONException(exception); } }
6d0e17db-032b-4ca0-bcf9-d6273695647c
public JSONTokener(Reader reader) { this.reader = reader.markSupported() ? reader : new BufferedReader(reader); this.eof = false; this.usePrevious = false; this.previous = 0; this.index = 0; this.character = 1; this.line = 1; }
df7ba7f5-f6b5-4eeb-9ddb-3420e2d0fc1d
public JSONTokener(InputStream inputStream) throws JSONException { this(new InputStreamReader(inputStream)); }
85047169-058a-47d1-acdd-0a1968bc10fb
public JSONTokener(String s) { this(new StringReader(s)); }
2436d2ea-ead3-488b-9501-8500cbab3c52
public void back() throws JSONException { if (this.usePrevious || this.index <= 0) { throw new JSONException("Stepping back two steps is not supported"); } this.index -= 1; this.character -= 1; this.usePrevious = true; this.eof = false; }
f2a3d913-d5ee-4634-829f-1cb17673a6a5
public static int dehexchar(char c) { if (c >= '0' && c <= '9') { return c - '0'; } if (c >= 'A' && c <= 'F') { return c - ('A' - 10); } if (c >= 'a' && c <= 'f') { return c - ('a' - 10); } return -1; }
db1255c1-1b76-4c3b-ba4e-be35b84447b3
public boolean end() { return this.eof && !this.usePrevious; }
e46d5302-eaba-4546-a012-424ab208d2a6
public boolean more() throws JSONException { this.next(); if (this.end()) { return false; } this.back(); return true; }
3f7eef1b-6664-49c7-81ff-7fc0a5489ee4
public char next() throws JSONException { int c; if (this.usePrevious) { this.usePrevious = false; c = this.previous; } else { try { c = this.reader.read(); } catch (IOException exception) { throw new JSONException(exception); } if (c <= 0) { // End of stream this.eof = true; c = 0; } } this.index += 1; if (this.previous == '\r') { this.line += 1; this.character = c == '\n' ? 0 : 1; } else if (c == '\n') { this.line += 1; this.character = 0; } else { this.character += 1; } this.previous = (char) c; return this.previous; }
3f777e50-e418-401f-92e7-d60a728ba30e
public char next(char c) throws JSONException { char n = this.next(); if (n != c) { throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'"); } return n; }
79369501-b706-4661-a52b-664fe54040d5
public String next(int n) throws JSONException { if (n == 0) { return ""; } char[] chars = new char[n]; int pos = 0; while (pos < n) { chars[pos] = this.next(); if (this.end()) { throw this.syntaxError("Substring bounds error"); } pos += 1; } return new String(chars); }
ace27a5d-183e-41af-8c23-5913ba30a6dc
public char nextClean() throws JSONException { for (;;) { char c = this.next(); if (c == 0 || c > ' ') { return c; } } }
70d7fdf3-3571-42b7-8b89-b6af2fe316f9
public String nextString(char quote) throws JSONException { char c; StringBuffer sb = new StringBuffer(); for (;;) { c = this.next(); switch (c) { case 0: case '\n': case '\r': throw this.syntaxError("Unterminated string"); case '\\': c = this.next(); switch (c) { case 'b': sb.append('\b'); break; case 't': sb.append('\t'); break; case 'n': sb.append('\n'); break; case 'f': sb.append('\f'); break; case 'r': sb.append('\r'); break; case 'u': sb.append((char)Integer.parseInt(this.next(4), 16)); break; case '"': case '\'': case '\\': case '/': sb.append(c); break; default: throw this.syntaxError("Illegal escape."); } break; default: if (c == quote) { return sb.toString(); } sb.append(c); } } }
1839304e-2c6e-4d65-8ddc-f3a5bce091b2
public String nextTo(char delimiter) throws JSONException { StringBuffer sb = new StringBuffer(); for (;;) { char c = this.next(); if (c == delimiter || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
dd44760f-0612-4ad7-adff-ea1f73c7fd25
public String nextTo(String delimiters) throws JSONException { char c; StringBuffer sb = new StringBuffer(); for (;;) { c = this.next(); if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
16beb29d-0f42-4d05-814a-56ec524ec22b
public Object nextValue() throws JSONException { char c = this.nextClean(); String string; switch (c) { case '"': case '\'': return this.nextString(c); case '{': this.back(); return new JSONObject(this); case '[': this.back(); return new JSONArray(this); } /* * Handle unquoted text. This could be the values true, false, or * null, or it can be a number. An implementation (such as this one) * is allowed to also accept non-standard forms. * * Accumulate characters until we reach the end of the text or a * formatting character. */ StringBuffer sb = new StringBuffer(); while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { sb.append(c); c = this.next(); } this.back(); string = sb.toString().trim(); if ("".equals(string)) { throw this.syntaxError("Missing value"); } return JSONObject.stringToValue(string); }
09a04015-5e6d-44c7-865b-df5f689dcaab
public char skipTo(char to) throws JSONException { char c; try { long startIndex = this.index; long startCharacter = this.character; long startLine = this.line; this.reader.mark(1000000); do { c = this.next(); if (c == 0) { this.reader.reset(); this.index = startIndex; this.character = startCharacter; this.line = startLine; return c; } } while (c != to); } catch (IOException exc) { throw new JSONException(exc); } this.back(); return c; }
57e3e1f0-aff2-415e-8472-b4efad665ea5
public JSONException syntaxError(String message) { return new JSONException(message + this.toString()); }
380bead1-03cf-4d07-b495-e9ad827cc4c3
public String toString() { return " at " + this.index + " [character " + this.character + " line " + this.line + "]"; }
da61816b-48ab-43e4-8501-0521eb5cc98d
public static float cos(float degree) { return (float) Math.cos(degree * Math.PI / 180); }
8191fdeb-0ba8-407f-b59b-e7a4408c950e
public static float sin(float degree) { return (float) Math.sin(degree * Math.PI / 180); }
98ce7b5b-05bb-4259-9572-dd9f69cc45e9
public SimpleTest() { super("SpaceGame"); }
7b5f83e0-86ed-4616-840a-0fcbe2319de4
@Override public void init(GameContainer container) throws SlickException { this.container = container; container.setTargetFrameRate(60); int size = 5; int speed = 3; int rotation = 20; float range = 40; ship = new Ship(size, speed, rotation, range, this); List<Obj> shipList = new List<Obj>(); shipList.add(ship); bulletList = new List<Obj>(); astList = new List<Obj>(); for (int i = 0; i < 2; i++) { float[] loc = new float[2]; loc[0] = (float) (Math.random()* container.getWidth()); loc[1] = (float) (Math.random()* container.getHeight()); List<Obj> pointer = astList; while (pointer.next != null) { pointer = pointer.next; } List<Obj> wrapper = new List<Obj>(); Asteroid ast = new Asteroid(loc, (float) (Math.random() * 10 + 4), wrapper, this); wrapper.data = ast; wrapper.previous = pointer; pointer.next = wrapper; } gameList = new List<List<Obj>>(); gameList.add(bulletList); gameList.add(astList); gameList.add(shipList); }
76cd7d5c-d9be-4644-b0cf-c058e584c6b6
@Override public void update(GameContainer container, int delta) throws SlickException { //ship.update(delta); CollisionChecker.checkAll(gameList, delta); List<List<Obj>> pointer = gameList.next; while(pointer != null) { List<Obj> pointer1 = pointer.data.next; while (pointer1 != null) { pointer1.data.update(delta); pointer1 = pointer1.next; } pointer = pointer.next; } }
63f315b7-6749-43ee-83c5-e547728caba9
@Override public void keyPressed(int key, char c) { if (c == 'a') ship.rotateLeft(true); else if (c == 'd') ship.rotateRight(true); else if (c == 'w') ship.accelerate(true); else if (c == ' ') { //System.out.println(ship.location[0] + " " + ship.location[1]); ship.fire(); } else if (c == 's') ship.stop(true); }
af978eca-53c6-437c-9aeb-a60ce10c9eda
@Override public void keyReleased(int key, char c) { if (c == 'a') ship.rotateLeft(false); else if (c == 'd') ship.rotateRight(false); else if (c == 'w') ship.accelerate(false); else if (c == 's') ship.stop(false); }
aa2fe31c-b0ce-4bb5-ad41-86ec38b91a7f
@Override public void render(GameContainer container, Graphics g) throws SlickException { g.setLineWidth(.3f); //System.out.println(container.getHeight() + " " + container.getWidth()); //ship.draw(g); List<List<Obj>> pointer = gameList.next; while(pointer != null) { List<Obj> pointer1 = pointer.data.next; while (pointer1 != null) { pointer1.data.draw(g); pointer1 = pointer1.next; } pointer = pointer.next; } }
f9e159a9-c8d3-4f57-b298-d6f105ff038e
public static void main(String[] args) { try { AppGameContainer app = new AppGameContainer(new SimpleTest()); app.start(); } catch (SlickException e) { e.printStackTrace(); } }
e8d6a61e-66ba-472c-b39e-dce93adbcf01
public List() { }
38841122-4bb0-4c11-8eb4-48a3e987ff1b
public List(Thing data, List<Thing> previous) { this.data = data; this.previous = previous; }
50a1c111-f9b4-452d-8625-5b80e0ee6c72
public void remove() { previous.next = next; if (next != null) next.previous = previous; }
cdf58e19-5702-4bcd-b3cb-67d0dc4348fa
public void add(Thing a) { List<Thing> wrapper = new List<Thing>(a, null); wrapper.previous = this; wrapper.next = next; if (next != null) next.previous = wrapper; next = wrapper; }
32bbddb4-1952-4496-98ae-26561a5d0c97
public static void checkAll(List<List<Obj>> objList, int delta) { List<List<Obj>> list1 = objList.next; while(list1 != null) { List<Obj> obj1 = list1.data.next; while(obj1 != null) { List<List<Obj>> list2 = list1; List<Obj> obj2 = obj1.next; while(list2 != null) { while(obj2 != null) { if (obj2.data.shape.intersects(obj1.data.shape)) { obj2.data.collide(obj1.data, delta); obj1.data.collide(obj2.data, delta); } obj2 = obj2.next; } list2 = list2.next; if (list2 != null) obj2 = list2.data.next; } obj1 = obj1.next; } list1 = list1.next; if (list1 != null) obj1 = list1.data.next; } }
25e61cb9-3298-419f-83c4-4759b9a50a81
public static void backStep(Obj thing, int delta) { float[] speed = thing.setSpeed(null); speed[0] *= -1; speed[1] *= -1; thing.update(delta); speed[0] *= -1; speed[1] *= -1; }
8229384e-e76b-4e30-b22a-f6bf11f73c8c
public Ship (int size, int speed, int rotateSpd, float range, SimpleTest inst) { location = new float[2]; location[0] = 200; location[1] = 200; velocity = new float[2]; acceleration = new float[2]; this.speed = speed; this.size = size; this.rotateSpd = rotateSpd; this.range = range; rotation = 0; gameInst = inst; }
2ea45b81-beb5-44e2-884e-5473155b890e
public void draw(Graphics g) { float[] points = new float[6]; points[0] = (size*Helper.cos(0 + rotation) + location[0]); points[1] = (size*Helper.sin(0 + rotation) + location[1]); points[2] = (size*Helper.cos(130 + rotation) + location[0]); points[3] = (size*Helper.sin(130 + rotation) + location[1]); points[4] = (size*Helper.cos(230 + rotation) + location[0]); points[5] = (size*Helper.sin(230 + rotation) + location[1]); shape = new Polygon(points); g.setColor(Color.green); g.fill(shape); // visual representation of the range of the ship Circle circle = new Circle(location[0], location[1], range); g.draw(circle); }
8cfca300-89ed-44dc-9dd4-d2b064c53217
public void rotateLeft(boolean turn) { turnLeft = turn; }
daa73386-19b7-4c0a-9b61-058d4a418bf8
public void rotateRight(boolean turn) { turnRight = turn; }
a6747212-d984-462a-be95-36c35948e425
public void stop(boolean truth) { stop = truth; }
9c4399a5-b411-4e03-a591-00e67443e2bc
public void update(int delta) { float d = .01f*delta; if (turnRight) rotation += rotateSpd*.01f*delta; if (turnLeft) rotation -= rotateSpd*.01f*delta; if (!checkBorders() && accelerate ) { acceleration[0] = (float) Helper.cos(rotation)*speed; acceleration[1] = (float) Helper.sin(rotation)*speed; velocity[0] += acceleration[0]*delta*.01f; velocity[1] += acceleration[1]*delta*.01f; } for(int i = 0; i < 2; i++) { location[i] += velocity[i]*delta*.01f; if (stop) { velocity[i] -= velocity[i]/10 * d; } } }
e49a8a15-c529-4b97-b1f0-aae243bc4807
private boolean checkBorders() { boolean check = false; int width = gameInst.container.getWidth(); int height = gameInst.container.getHeight(); if (location[0] >= width) { check = true; if (velocity[0] > 0) velocity[0] *= -.5f; } if (location[0] <= 0) { check = true; if (velocity[0] < 0) velocity[0] *= -.5f; } if (location[1] >= height) { check = true; if (velocity[1] > 0) velocity[1] *= -.5f; } if (location[1] <= 0) { check = true; if (velocity[1] < 0) velocity[1] *= -.5f; } return check; }
826e5ee2-bbb4-4d0e-8ee1-96cf886dc956
public void fire() { int counter = 0; List<Obj> pointer = gameInst.bulletList; while (pointer.next != null) { counter++; pointer = pointer.next; } System.out.println("fire! " + counter); List<Obj> wrapper = new List<Obj>(); Bullet shot = new Bullet(location, rotation, range, wrapper); wrapper.data = shot; wrapper.previous = pointer; pointer.next = wrapper; }
29d8187c-7399-4acf-90d0-48cab19018ac
public void accelerate(boolean acc) { accelerate = acc; }
279d1d31-e59d-4388-aa2b-63f0b65bafbd
public void collide(Obj hitter, int delta) { collided = true; if (hitter instanceof Asteroid) { // forces this object to move back a step CollisionChecker.backStep(this, 2*delta); // speed of the object you are colliding into float[] hSpeed = hitter.setSpeed(null); hSpeed[0] += velocity[0] / 2; hSpeed[1] += velocity [0] / 2; velocity[0] *= -1.0/2; velocity[1] *= -1.0/2; } }
37afc692-240d-49c6-af14-431deaea01fa
abstract public void draw(Graphics g);
4c4fbfbe-cf1b-49f1-88ed-7ca77821b50c
abstract public void update(int delta);
92571c6d-b24f-4698-9e40-74ea9b7c369a
public Shape shape() { return shape; }
d6960a48-e010-4edb-9659-2c732cdfff93
public float[] setSpeed(float[] speed) { if (speed != null) velocity = speed; return velocity; }
74b280d2-4072-418d-8fd5-e879f085d882
abstract public void collide(Obj hitter, int delta);
4c38654b-aef3-4a47-8042-4183c8b93151
public Bullet(float[] location, float rotation, float range, List<Obj> inst) { width = 2f; hieght = 10f; points = makePoints(location, rotation); shape = new Polygon(points); this.rotation = rotation; this.range = range; speed = 30f; objInst = inst; }
5bac9a47-d7d3-4926-af95-6dff84b86be1
private float[] makePoints(float[] loc, float rotation) { float cos = Helper.cos(rotation); float sin = Helper.sin(rotation); float[] pts = new float[8]; // lower left pt pts[0] = loc[0] - width/2 * sin; pts[1] = loc[1] + width/2 * cos; //upper left pt pts[2] = pts[0] + hieght * cos; pts[3] = pts[1] + hieght * sin; //upper right pt pts[4] = pts[2] + width * sin; pts[5] = pts[3] - width * cos; //lower right pt pts[6] = pts[4] - hieght * cos; pts[7] = pts[5] - hieght * sin; return pts; }
5df41079-040d-49ba-abbc-a7701e2258fa
public void update(int delta) { // removes this bullet from the list if it has gone too far if (range <= 0) { objInst.remove(); } float speed = this.speed * delta * .01f; range -= speed; float cos = Helper.cos(rotation); float sin = Helper.sin(rotation); for (int i = 0; i < 8; i += 2) { points[i] += speed*cos; points[i+1] += speed*sin; } }
e53cb440-1454-4df7-8c49-8321baf16854
@Override public void draw(Graphics g) { shape = new Polygon(points); g.setColor(Color.yellow); g.fill(shape); // g.drawLine(points[0], points[1], points[2], points[3]); }
03902fb9-2f00-40e1-b003-5b10b0d8ca8a
public Shape shape() { return shape; }
912fd72f-505a-4ad7-9581-f7445ccc20e2
@Override public float[] setSpeed(float[] speed) { // TODO Auto-generated method stub return null; }
4c195d77-3430-4f43-97fe-e353a299b5f3
@Override public void collide(Obj hitter, int delta) { if (hitter instanceof Asteroid) { collided = true; objInst.remove(); } }
52c0888d-6799-4a6b-8410-176cf3a71dea
public static void main(String[] args) { // TODO Auto-generated method stub int[] arr = {6, 4, 8, 9, 3, 5, 12, 2, 7}; quickSort(arr, 0, 8); display(arr); }
345f5ed5-d8e4-4a06-ae5c-8a0e1c1cbdf1
public static void quickSort(int arr[], int left, int right) { int index = partition(arr, left, right); if (left < index - 1) quickSort(arr, left, index - 1); if (index < right) quickSort(arr, index, right); }
c2e04e76-ea32-48fc-918b-52f9ef8bd02c
public static int partition(int arr[], int left, int right) { int i = left, j = right; int tmp; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr[i] < pivot) i++; while (arr[j] > pivot) j--; if (i <= j) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; } }; return i; }
07490d33-3fa6-4b35-8875-920cee9c1bce
public static void display(int[] data) { for(int i=0;i<data.length;i++) { System.out.print(data[i]); System.out.print(" "); } }
e5d18782-7241-4714-95cf-ea0e06e7cb5f
public static void main(String[] args) { // TODO Auto-generated method stub int[] arr = {9,8,7,6,5,4,3,2,1,0}; shellSort(arr); Util util = new Util(); util.printArray(arr); }
cc4d5680-b444-4a0a-9ef4-32239421c7b8
public static void shellSort(){ int a[]={1,54,6,3,78,34,12,45,56,100}; double d1=a.length; int temp=0; while(true){ d1= d1/2;//Math.ceil(d1/2); int d=(int) d1; for(int x=0;x<d;x++){ for(int i=x+d;i<a.length;i+=d){ int j=i-d; temp=a[i]; for(;j>=0&&temp<a[j];j-=d){ a[j+d]=a[j]; } a[j+d]=temp; } } if(d==1) break; } for(int i=0;i<a.length;i++) System.out.println(a[i]); }
95c3bdc8-1f87-45b9-bdb9-85e3480125a8
public static int[] shellSort(int[] arr){ int n = arr.length; int d=n; while(true){ d = d/2; for(int i=0; i<d; i++){ for(int j=i+d; j<n; j+=d){ int tmp = arr[j]; int k=j-d; for( ; k>=0&&tmp<arr[k]; k-=d){ arr[k+d] = arr[k]; } arr[k+d] = tmp; } } if(d==1) break; } return arr; }
eef3db05-bd3a-4204-914f-04addb1029c7
public static void main(String[] args) { // TODO Auto-generated method stub int[] arr = {9,6,7,3,5,1}; bubbleSort(arr); }
2302bef2-e10b-4379-a51c-62ac8d1cd724
public static int[] bubbleSort(int[] arr){ boolean flag = true; int n = arr.length; while(flag){ for(int i=1; i<n; i++){ if(arr[i-1] > arr[i]){ int tmp = arr[i-1]; arr[i-1] = arr[i]; arr[i] = tmp; } } n--; if(n==1){ flag=false; } } return arr; }
1cae5cbf-4824-4aea-be94-669f208d70eb
public void printArray(int[] arr){ int n =arr.length; for(int i=0; i<n; i++){ System.out.print(arr[i]+","); } System.out.print("\n"); }
b907a078-c5b0-4b58-b684-135c06f39756
public JoueurIA(String nom, Jeu partie) { super(nom, partie); }
7f93594a-d24f-449d-bfae-9e68f62440a7
public CartePlusDeux(String color, int value) { super(color, value); this.type = "Carte +2"; }