id
stringlengths
36
36
text
stringlengths
1
1.25M
0da0aff5-69de-4096-8b60-e2be9774e8f5
@Override public void keyReleased(KeyEvent e) { switch(e.getKeyCode()){ case KeyEvent.VK_LEFT: case KeyEvent.VK_RIGHT: movement.clearKey(); break; case KeyEvent.VK_UP: thrustersOn = false; break; } ...
e4832b84-3427-46f6-a5d4-ceecfc9f4a90
@Override public void keyTyped(KeyEvent e) {}
8690dda2-fd7a-4014-bc5c-78b5316d6639
public Asteroids() { // Use a static instance so that we can check state if (Asteroids.instance == null) { Asteroids.instance = this; } setBackground(Color.BLACK); setPreferredSize(new Dimension(w, h)); font = new Font("Monospaced", Font.PLAIN, 14); ...
a548938a-0cd0-48fb-8761-0b0f24fae929
public static Asteroids getInstance() { return instance; }
84f3720c-0c6c-4c8e-afa5-43b551055031
private void newGame() { satellites = new Vector<>(); player = getNewPlayer(); pGenerator = ParticleGenerator.getInstance(); bGenerator = BulletGenerator.getInstance(); pGenerator.reset(); bGenerator.reset(); running = true; score = 0; lives = 3;...
a2cd5c17-e3a3-4637-973a-12f41b3d8680
private void showSplash() { while (isSplash) { repaint(); } }
f42cb53e-292e-4da2-b28f-027a18b160c6
public void startGame() { showSplash(); gameLoop(); }
b74bc6f9-c329-4fcf-a50f-c934c6a0bd3b
private void gameLoop() { while (running) { long start = System.nanoTime(); synchronized(this) { tick(); // Check if all satellites have been destroyed, if so, new // level if (satellites.isEmpty()) { l...
37f99fed-5d50-4d56-be20-30e8e09ab504
private void tick() { // Move game entities player.tick(); for (Satellite s : satellites) { s.move(); } pGenerator.tick(); bGenerator.tick(); // Check for collisions Vector<Satellite> deadSatellites = new Vector<>(); Vector<Satellite> newSatellites = new ...
749609b7-5bcc-437c-9e9a-203c758ed30d
private Ship getNewPlayer() { double x = getPreferredSize().getWidth() / 2; double y = getPreferredSize().getHeight() / 2; for (Satellite s : satellites) { if (playerArea.contains((int) s.getPosition().x, (int) s.getPosition().y)) { return player; // Return the old, ...
845c9eae-ec10-4a28-97be-9dab446fb838
private void setLivesString() { livesStr = ""; for (int i = 0; i < lives; i++) { livesStr += "* "; } }
94bbe976-0914-4078-97f2-e8053d432af1
private void drawScoreboard(Graphics g) { g.setColor(Color.WHITE); g.setFont(font); g.drawString(score.toString(), 10, 20); g.drawString(livesStr, 10, 35); }
06e2898a-33da-4228-8fc7-8204c335a376
private void drawSplash(Graphics g) { g.setColor(Color.WHITE); g.setFont(new Font("Monospaced", Font.PLAIN, 32)); g.drawString("POLY SHOOTER", 10, 50); g.setFont(new Font("Monospaced", Font.PLAIN, 20)); g.drawString("Press Space to Start", 45, 80); }
e4d62da1-6450-43c4-ba9c-1f26861987ec
public void paint(Graphics g) { super.paint(g); if (isSplash) { drawSplash(g); return; } Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (Satellite s : satellites) { s....
b690c7d9-70a9-451f-98b0-354735154b4b
private void generateSatellites(int level) { int total = 3 + level; Random rand = new Random(); while (total > 0) { // Spawn a satellite 6-sided satellite, but outside of the player // area // TODO: The playerArea will need to move at the start of new ...
7b1e3a88-a389-458c-bfab-23f07c15e7f6
@Override public void keyPressed(KeyEvent e) { synchronized(this) { if (isSplash && e.getKeyCode() == KeyEvent.VK_SPACE) { isSplash = false; } else if (!player.isDead()) { player.keyPressed(e); } } }
f414a659-260a-49d5-9988-02e331cab600
@Override public void keyReleased(KeyEvent e) { synchronized(this) { if (!player.isDead()) player.keyReleased(e); } }
1c5e31cf-9a35-41bc-9b85-1229dd37c60c
@Override public void keyTyped(KeyEvent e) {}
53b8d3ca-6c56-434e-871d-3bab171e02bf
private BulletGenerator() { bullets = new Vector<Bullet>(); }
b9b2f1fb-fd04-455b-ada9-1074e4bc8b15
public static final BulletGenerator getInstance() { if (instance == null) { instance = new BulletGenerator(); } return instance; }
5fc7b1c4-13d6-4083-8c61-92762e826eb9
public void reset() { bullets.clear(); }
4308e44d-c97b-489c-b7e8-a7d7046779c2
public final Vector<Bullet> getBullets() { return bullets; }
d11467f3-7555-4f36-93c7-7f791ea07dc6
public void tick() { for (Bullet b : bullets) { b.move(); b.tick(); } cullBullets(); }
ed40306e-ad05-4201-bc6e-4cebc7080bb4
public void cullBullets() { Vector<Bullet> deadBullets = new Vector<Bullet>(); for (Bullet b : bullets) { if (b.dead) { deadBullets.add(b); } } bullets.removeAll(deadBullets); }
b54fe34a-c972-4bfd-9004-f32651d81c31
public void shootBullet(double x, double y, double rot) { Vector2 velocity = new Vector2(0.0, -15.0); velocity.rotate(rot); bullets.add(new Bullet(x, y, velocity.x, velocity.y)); }
07b1f069-3646-480e-bfd9-d5e9643d0a46
public void drawBullets(Graphics2D g) { for (Bullet b : bullets) { b.draw(g); } }
fe9aee12-c0a6-4994-b7d4-f9da27c3e520
public Bullet(double x, double y, double vx, double vy) { velocity = new Vector2(vx, vy); position = new Vector2(x, y); dead = false; tick = ticktoDead; }
8ab3b643-94c2-47b2-a532-a648347b5335
public boolean collided(Entity e) { return e.getShape().getBounds().contains((int) position.x, (int) position.y); }
d96865c5-4d08-4de8-8929-48122eb70c31
public void kill() { dead = true; }
fa37a753-6622-4234-8fc9-495cb1f09548
public void tick() { tick--; if (tick == 0) { dead = true; } }
b148a82a-cbb4-45e0-b6bd-626fee8f1d84
public void draw(Graphics2D g) { g.setColor(Color.WHITE); g.drawLine((int) position.x, (int) position.y, (int) position.x, (int) position.y); }
b8413cff-fb23-4b16-ad0b-8fba855125b5
abstract public void draw(Graphics2D g);
431f5f33-6c33-458d-91ec-24c930c9c76d
abstract public boolean collided(Entity e);
a00918de-ec92-4f14-a808-83b978388882
public final Shape getShape() { GeneralPath p = new GeneralPath(entityPolygon); AffineTransform a = new AffineTransform(); a.translate(position.x, position.y); a.rotate(Math.toRadians(facing)); return p.createTransformedShape(a); }
c411a128-a5c1-43c3-a7f1-ddfcbf0bcafa
public void move() { Dimension d = Asteroids.getInstance().getSize(); if (velocity.x > SPEED_LIMIT || velocity.x < -SPEED_LIMIT) { velocity.setX(SPEED_LIMIT * Math.signum(velocity.x)); } if (velocity.y > SPEED_LIMIT || velocity.y < -SPEED_LIMIT) { velocity.setY(...
bc036ad8-ae33-429e-86b9-ca3a1d77cd28
private ParticleGenerator() { particles = new Vector<Particle>(); }
4f9ccc6d-fe61-4d13-b025-e38642302d8d
public static final ParticleGenerator getInstance() { if (instance == null) { instance = new ParticleGenerator(); } return instance; }
b4c0f9e4-4d4b-4b15-908e-93828c8999a6
public void reset() { particles.clear(); }
42046a3b-578c-4ca3-979f-86168f228c18
public void tick() { for (Particle p : particles) { p.move(); p.tick(); } cullParticles(); }
3aba48d3-cca8-4487-8667-47fa3aaead83
public void cullParticles() { Vector<Particle> deadParticles = new Vector<Particle>(); for (Particle p : particles) { if (p.isDead()) { deadParticles.add(p); } } particles.removeAll(deadParticles); }
8d77dde5-78f9-493d-8b54-85f847b7f488
public void drawParticles(Graphics2D g) { for (Particle p : particles) { p.draw(g); } }
be5fcdd3-ea4e-43b8-babc-fdd7407e7bd4
public void generateParticle(Vector2 position, Vector2 velocity) { particles.add(new Particle(position, velocity)); }
3963fc09-cf2f-4d2a-bccc-659f84d0fd96
public void generateExplosion(Entity source) { Vector2 acceleration = new Vector2(0.0, 1.0); acceleration.rotate(-source.facing); double rot = 45.0 / NUM_PARTS_EXPLOSION; for (int i = 0; i < NUM_PARTS_EXPLOSION; i++) { Vector2 velocity = source.velocity.copy(); ac...
e332b786-ccd3-44e1-8da2-2358aaf17f4b
public Particle(Vector2 position, Vector2 velocity) { this.velocity = velocity; this.position = position; dead = false; tickToDead = tickToDeadMin + (int) (Math.random() * (tickToDeadMax - tickToDeadMin)); tick = tickToDead; }
0f43ff0f-0a1a-4e43-84e3-93e1411a31c2
public boolean isDead() { return dead; }
f5b1fb63-566c-4575-8548-b120ccf7cdbe
public void kill() { dead = true; }
5584e0b3-a0ef-4ac4-9111-9ca568683e4c
public void tick() { tick--; if (tick == 0) { kill(); } // Decelerate velocity.x *= 0.99; velocity.y *= 0.99; }
c7bf99dc-5c5f-4369-a948-437addbc55f6
public void draw(Graphics2D g) { g.setColor(new Color(255 - (tickToDead - tick), Math.random() > 0.5 ? 0 : 165, 0)); g.drawLine((int)position.x, (int)position.y, (int)position.x, (int)position.y); }
3514770f-c501-4aa0-9e32-a2357fc4c444
public boolean collided(Entity e) { return false; }
3e2067ed-3f38-4d29-9ca2-b1624feded6b
public static void main(String[] args) { JFrame window = new JFrame("Poly Shooter"); Asteroids game = new Asteroids(); window.add(game); window.addKeyListener(game); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setResizable(false); window.pack();...
cac60d43-c2c0-47b9-a9f7-141303cdfc70
public Vector2(double x, double y) { this.x = x; this.y = y; }
f27ebdce-354f-4da0-a9d9-fab79878d1b3
public void set(double x, double y) { this.x = x; this.y = y; }
f742d8f2-2575-4a89-8697-0d123669a084
public void setX(double x) { this.x = x; }
b3fb322b-8d01-4aa7-b77a-4be9be12134c
public void setY(double y) { this.y = y; }
b4f21f7b-9520-4899-bfd0-2aaac40c29d1
public Vector2 add(Vector2 v) { x = x + v.x; y = y + v.y; return this; }
6f35feb1-b218-448f-b7e0-faa750098ed8
public Vector2 sub(Vector2 v) { x = x - v.x; y = y - v.y; return this; }
81895120-5efa-45a6-87f5-1372bf8c8bef
public Vector2 rotateRad(double rad) { double curX = x; double curY = y; x = (curX * Math.cos(rad)) - (curY * Math.sin(rad)); y = (curX * Math.sin(rad)) + (curY * Math.cos(rad)); return this; }
16aa857f-6ee9-432d-8d92-ad54d36d480c
public Vector2 rotate(double deg) { double rad = deg * (Math.PI / 180); return rotateRad(rad); }
78ca21d5-44fd-4b55-82c5-62598d20e7e3
public double getAngleRad() { return Math.atan2(y, x); }
fd2f15cd-e2dc-4c0c-9336-a67877f3c9c0
public double dist(Vector2 other) { return Math.sqrt( Math.pow(Math.abs(this.x - other.x), 2) + Math.pow(Math.abs(this.y - other.y), 2) ); }
6cddd1b4-9e79-4484-a214-756706fdeeb6
public Vector2 copy() { return new Vector2(this.x, this.y); }
b7ce27e8-1ed2-400e-99ec-af8cd3294e02
public Controller() { key = Keys.NONE; }
80688118-171c-4114-83a7-5a83a33820f9
public void setKey(Keys key) { this.key = key; }
a29e0d09-c1e1-4219-80d0-83b5749fc458
public void clearKey() { key = Keys.NONE; }
4d7284fc-4117-4d29-8201-732a2d13979c
public final Keys getKey() { return key; }
76658655-2351-4a25-a4aa-980288249b04
public abstract T transact(Session session);
211c6139-916e-4943-be84-7fcee4bbf561
public T run() { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); T retval = transact(session); session.getTransaction().commit(); return retval; } catch (HibernateException e) { sess...
897a2ac1-5ef6-45fd-87dd-aefdc835a3c9
public static SessionFactory getSessionFactory() { return sessionFactory; }
2bd59b36-c6e2-4fd7-9564-bd9153ea2e3f
@Test public void testRun() throws Exception { Supply supply = new Transactor<Supply>() { @Override public Supply transact(Session session) { return (Supply) session.createQuery("from Supply where quantity = 200").iterate().next(); } }.run(); ...
b3aa36ff-6c20-421d-a248-2bbd510b7623
@Override public Supply transact(Session session) { return (Supply) session.createQuery("from Supply where quantity = 200").iterate().next(); }
ee63d7f0-dcc2-4707-825f-157339d3d4d6
@Test public void testInsert() throws Exception { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Object sID = null; Transaction transaction = null; Supplier supplier = new Supplier("S7", "BOBBY", 50, "LONDON"); try { ...
eef26aed-8f20-4fdd-81c2-8f46745bc978
@Test public void testTestDataExists() throws Exception { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); List suppliers = session.createQuery("FROM Supplier").list(); ...
92243b6e-3cb4-4c1c-bbd3-53149d1779dc
@Test public void testQuery() throws Exception { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); List suppliers = session.createQuery("FROM Supplier WHERE status = 10")...
40abeabf-30d3-43d0-acd5-ab6e6f5a0269
@Test public void testGetSupplier() throws Exception { String firstSupplierID = new Transactor<String>() { @Override public String transact(Session session) { return getFirstSupply(session).getSupplier().getId(); } }.run(); assertEquals("S...
c7bdf445-6997-42a0-b5c1-374f38af4676
@Override public String transact(Session session) { return getFirstSupply(session).getSupplier().getId(); }
046c842d-1493-468f-9a29-60d20c016011
public Supply getFirstSupply(Session session) { return (Supply) session.createQuery("from Supply where quantity = 200").iterate().next(); }
f0f1ff67-0881-4ec2-930d-ddceb8f8e170
@Test public void testGetFirstSupply() throws Exception { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); assertEquals(200, getFirstSupply(session).getQuantity()); } finally { session.close(); }...
731b1de3-24bb-464d-8495-947a717d4f6f
public int pedirNumeroConsola() { Scanner sc=new Scanner(System.in); int valorObtener; valorObtener=sc.nextInt(); return valorObtener; }
6244b57e-640e-47cb-9eb3-ba1b93df1b35
public int tamanioTablero();
084db47a-aa51-46b0-a69a-661a2d3bf97f
public String[][] cargarTablero();
204f8d79-68b3-458f-89e7-d7eb8b47f850
public String[][] dibujarTablero();
0a88c856-f782-4dc4-b938-d764698091a0
public void elegirContinuarConjuego();
a53a1d84-ba3d-4ec6-a97a-46c52a304802
public void elegirCelda(String tablero[][], int var);
f2fabf18-cce7-4be2-8507-976f8f132d21
public static ITablero getITablero (String tipo){ if(tipo.equalsIgnoreCase("consola")){ return new TableroConsola(); } return null; }
fbb2da4f-69cc-4d2e-b34f-9f9f2cec6166
public static IUsuario getIUsuario(String tipo){ if(tipo.equalsIgnoreCase("consola")){ return new UsuarioConsola(); } return null; }
936995ae-5474-4ed1-9f5f-52a52eb8b0e7
public static void main(String[] args) { ITablero t= FactoryTablero.getITablero(args[0]); IUsuario u=FactoryUsuario.getIUsuario(args[0]); int var=t.tamanioTablero(); String tablero[][]= new String[var][var]; tablero=t.cargarTablero(); t.dibujarTablero(); u.elegirCelda(tablero,var); ...
9e17168f-ec03-4025-ba2d-9d79ec2de7d2
public AcServiceException() { super(); }
4b47ef7f-6d91-4123-b4fd-8a0629b31cb6
public AcServiceException(String message, Throwable cause) { super(message, cause); }
23be3258-3d18-49ac-afa3-15b34398d61e
public AcServiceException(String message) { super(message); }
a037feed-f506-4dee-97c4-23611a7250cb
public AcServiceException(Throwable cause) { super(cause); }
05a6aab1-2743-4974-841b-df33d4c8dc24
User getUserByToken(String authToken) throws AcServiceException;
430b976a-b7e2-44af-8e04-36f0410140de
boolean isValidUser(String authToken) throws AcServiceException;
d232630b-a882-4e6a-9f95-43b558fa615c
boolean isAnonymousUser(String authToken) throws AcServiceException;
293f1bce-23f4-4841-b62a-07b463e7dd71
List<Attribute> getUserAttributes(String authToken, String authority, String key) throws AcServiceException;
2a95c37e-4553-4340-a3ac-3f538474e40c
boolean canReadResource(String authToken, String resourceId) throws AcServiceException;
4f93e746-edc0-40da-82da-93b67a4e5593
User createUser(String authToken, long expDate, List<Attribute> attributes) throws AcServiceException;
105675ab-5e9b-40e1-9f21-30ffefd66ff6
boolean removeUser(String authToken) throws AcServiceException;
9eb1a7a2-60d6-431e-80a4-34314e18356c
void updateUser(long userId, String authToken, Long expTime, List<Attribute> attributes) throws AcServiceException;
be2e2b7a-7221-40c7-96fe-3674373525e1
String createSessionToken(long userId, Long expTime) throws AcServiceException;
1ff2242b-4ad6-42e0-b74d-5d8294aba5ad
String generateAuthToken() throws AcServiceException;