id
stringlengths
36
36
text
stringlengths
1
1.25M
5f0520c6-e377-4af2-827e-2a11935995e4
public void setWebStranica(Resource webStranica) { this.webStranica = webStranica; }
fdb1e627-c3ff-4677-b1ba-f33a92f15884
public int getMax() { return max; }
e176359b-7ade-4311-9f30-23f7b97ced67
public void setMax(int max) { this.max = max; }
691e144e-37ee-4e57-8c5b-74578efd0289
public String getNazivSpremista() { return nazivSpremista; }
a2617cef-ecef-43b1-a65c-1e7aeb52484e
public void setNazivSpremista(String nazivSpremista) { this.nazivSpremista = nazivSpremista; }
c52bf4f4-b5fe-4d8d-bda2-53fa9ffb27d4
public Cache getC() { return c; }
b0f2bdd0-2bec-4b60-8ab3-1aee0efa9f09
public void setC(Cache c) { this.c = c; }
b26d8595-4e8a-447a-8168-3a673aed8024
public int getInterval() { return interval; }
6cb6c3c0-5694-4dcc-98b7-f39e25559eee
public void setInterval(int interval) { this.interval = interval; }
9fc95bd8-6af0-4cf0-8ee1-c86bf1136fa3
public boolean isOcisti() { return ocisti; }
5cb99a1c-14c5-4e03-a35e-6103e0f638c9
public void setOcisti(boolean ocisti) { this.ocisti = ocisti; }
c6f5a5f2-d010-4056-99e8-4042ed5fe183
public int getOgranicenje() { return ogranicenje; }
1e305f4d-e50b-4125-a86f-b36a7d47ad53
public void setOgranicenje(int ogranicenje) { this.ogranicenje = ogranicenje; }
f350e102-6262-49dc-92a5-9cef7af2c48e
public boolean isKb() { return kb; }
7e1bd684-cc93-4e5e-b1da-393a39a20e9c
public void setKb(boolean kb) { this.kb = kb; }
ba8558c9-7726-417b-b5dd-8c6e590cd202
public boolean isStrategija() { return strategija; }
4575de98-f34c-457f-8637-d1761c6ff635
public void setStrategija(boolean strategija) { this.strategija = strategija; }
4726d67d-7c24-4f0a-84b5-3b29cda5ebb2
public View(Model model) { this.m = model; }
9a454b64-ecd7-40ba-8cfb-e13732acb676
public void ispisiUpute() { System.out.println("----------KOMANDE-------------"); System.out.println("-I - ispis adresa poveznica s rednim brojem"); System.out.println("-J n - prijelaz na poveznicu s rednim brojem n te ucitavanje web stranice"); System.out.println("-S - prikaži sadrzaj spremista"); System.out.println("-E - prazni spremiste"); System.out.println("-Q - prekid rada programa"); System.out.println("------------------------------"); }
43220b83-c3de-452e-a6cc-7614c3f3983d
public void ispisPoveznica() { m.dohvatiListupoveznica(); System.out.println("---------POVEZNICE-------------"); ispisiLinije(m.getMax()); for (int i = 0; i < m.getWebStranica().getListaURLa().size(); i++) { System.out.print("| " + (i + 1) + "."); ispisipraznineBroja((Integer.toString(m.getWebStranica().getListaURLa().size()).length() - Integer.toString(i + 1).length()) + 1); System.out.print("| " + m.getWebStranica().getListaURLa().get(i)); ispisipraznineURLa(m.getMax() - m.getWebStranica().getListaURLa().get(i).toString().length()); ispisiLinije(m.getMax()); } }
92c3fbf0-47b1-42c8-8a03-e877b113523d
public void ispisiLinije(int broj) { for (int a = 0; a < broj + 12; a++) { System.out.print("-"); } System.out.println(""); }
f76f0bae-5baf-4f53-b0d9-e9751978b0da
public void ispisipraznineURLa(int broj) { for (int a = 0; a < broj; a++) { System.out.print(" "); } System.out.println(" |"); }
b3d5c637-e278-4306-8eaf-6e328e9f52d7
public void ispisipraznineBroja(int broj) { for (int a = 0; a < broj; a++) { System.out.print(" "); } }
2836cb89-fea4-4b38-99f7-65937201675d
public void novaStranica(String redniBroj) { m.promjeniStranicu(redniBroj); System.out.println("---------------Nova stranica------------"); System.out.println(Ztintor_zadaca_4.pocetniLink.toString()); }
9778806f-173c-4851-8e0e-2d2a0105394d
public void ispisiStatistiku() { Resource r; System.out.println("--------------STATISTIKA--------------"); System.out.println(m.getNazivSpremista()); for (int i = 0; i < cac.getLista().size(); i++) { r = (Resource) cac.getLista().get(i); if (r.isSpremljen()) { if (m.getWebStranica().getNaziv().equals(r.getNaziv())) { System.out.println((i + 1) + ". " + r.getNaziv() + " " + r.getBrojKoristenja() + " " + "Koristi se"); } else { System.out.println((i + 1) + ". " + r.getNaziv() + " " + r.getBrojKoristenja() + " " + r.getZadnjeKoistenje()); } } } System.out.println("--------------------------------------"); }
dc4c96f3-8268-4165-aaa8-a0987f704913
public void izadi() { System.out.printf("Serijalizirani podatci spremljeni u: " + m.getNazivSpremista() + "\\serijalizacija.ser"); m.serijaliziraj(); }
81759458-4f06-443c-9c32-15f488c61f1a
public void brisiNaZahtjev() { m.setOcisti(true); m.brisiSpremiste(); System.out.println("Obrisano spremiste " + m.getNazivSpremista()); }
90998cb3-7542-4c6d-8ea3-7d303c8716c3
public Cache getCac() { return cac; }
a7ca1b17-4bf9-47e4-a114-3364e5e73c7e
public void setCac(Cache cac) { this.cac = cac; }
f7e684ea-7c8c-4852-97cc-bc4a89a3b627
@Override public void update(Observable o, Object arg) { System.out.println(arg); }
2d81bd6c-cc5a-436a-9d0b-121cfff2db0b
public Controller(View view) { this.v = view; }
9758108d-6178-4895-bc9a-f724d228644f
public void provjeriUnos() { Console c = System.console(); if (c == null) { System.exit(1); } v.ispisiUpute(); petlja = true; while (petlja) { input = c.readLine(); String split[] = input.split(" "); switch (split[0]) { case "-I": v.ispisPoveznica(); break; case "-J": v.novaStranica(split[1]); petlja = false; break; case "-S": v.ispisiStatistiku(); break; case "-E": v.brisiNaZahtjev(); break; case "-Q": v.izadi(); break; } } }
343b8835-176c-4280-90c8-c8629cdf4517
public Board(int width, int height) { this.width = width; this.height = height; starfield = new Starfield(this.width, this.height, 50); // Start listening for key input addKeyListener(new TAdapter()); // Prepare JPanel setFocusable(true); setDoubleBuffered(true); setBackground(Color.black); setSize(width, height); setPreferredSize(new java.awt.Dimension(width, height)); setVisible(true); // Load all resources into RAM loadResources(); // Set variables to their default values resetGame(); // Start the game loop - it goes on forever!!! :D (should work like 30FPS but needs improvement) timer = new Timer(33, this); timer.start(); }
d4c8ae0f-1d5b-4b66-8dd7-dfea48352e4f
private void loadResources() { ClassLoader classLoader = getClass().getClassLoader(); // Load images rock32Image = new ImageIcon(classLoader.getResource("resources/asteroid2-32.png")).getImage(); rock48Image = new ImageIcon(classLoader.getResource("resources/asteroid2-48.png")).getImage(); rock64Image = new ImageIcon(classLoader.getResource("resources/asteroid2-64.png")).getImage(); shipImage = new ImageIcon(classLoader.getResource("resources/spaceship2-64.png")).getImage(); bulletImage = new ImageIcon(classLoader.getResource("resources/bullet2-6x12.png")).getImage(); for(int i = 0; i <= 17; i++) { explosionImages.add(new ImageIcon(classLoader.getResource("resources/explosion/ex"+i+".png")).getImage()); } // Load bounds for images rock32Bounds = ObjectBounds.parseFromFile(classLoader.getResource("resources/asteroid2-32.txt")); rock48Bounds = ObjectBounds.parseFromFile(classLoader.getResource("resources/asteroid2-48.txt")); rock64Bounds = ObjectBounds.parseFromFile(classLoader.getResource("resources/asteroid2-64.txt")); shipBounds = ObjectBounds.parseFromFile(classLoader.getResource("resources/spaceship2-64.txt")); bulletBounds = ObjectBounds.parseFromFile(classLoader.getResource("resources/bullet2-6x12.txt")); // Load sounds explosionSound = Helper.fileToByteArray(classLoader.getResource("resources/explosion.wav")); }
0ba66e62-cf52-41e0-9156-338852d85d10
private void resetGame() { // Reset movements moveLeft = false; moveRight = false; moveUp = false; moveDown = false; isFiring = false; enterPressed = false; // Re-created game objects ship = new Ship(shipImage, shipBounds, width, height); rocks = new ArrayList<Rock>(); bullets = new ArrayList<Bullet>(); explosions = new ArrayList<Explosion>(); // Reset environment variables score = 0; bulletFiringRate = 250; rockCreatingRate = 500; // Re-create timings gameStartedAt = new Date(); lastBulletFiredAt = new Date(); lastRockCreatedAt = new Date(); lastRockCreatedAt.setTime(lastRockCreatedAt.getTime() - 15000); selectedMenuItem = 0; menuControlsBuffer = new Queue<Integer>(); }
0d0632d0-0dab-4d37-a0b2-418ce525b637
private void doLogic() { starfield.doLogic(); if(gameState == 0) { // Main Menu doMenuLogic(); } else if(gameState == 1) { // Game Play doGameLogic(); } else { // Game Over doGameOverLogic(); } }
94086911-d910-4a5d-84a4-9110bc6fe493
private void doMenuLogic() { if(menuControlsBuffer.isEmpty()) { return; } int key = 0; try { key = menuControlsBuffer.dequeue(); } catch (InterruptedException e) { e.printStackTrace(); } if(key == KeyEvent.VK_UP) { if(selectedMenuItem == 0) { selectedMenuItem = 2; } else { selectedMenuItem--; } } else if(key == KeyEvent.VK_DOWN) { if(selectedMenuItem == 2) { selectedMenuItem = 0; } else { selectedMenuItem++; } } else if(key == KeyEvent.VK_ENTER) { if(selectedMenuItem == 0) { // Start button resetGame(); gameState = 1; } else if(selectedMenuItem == 1) { // Settings button // TODO: Create the settings menu } else { // Exit button timer.stop(); //Spaceship.spaceship.dispose(); } } }
5f661682-c236-4600-90f8-cf687ed461a8
private void doGameLogic() { handleObjectCreations(); handleObjectMovements(); handleObjectCollisions(); handleObjectEndings(); handleExplosions(); }
1acb8c81-f7d8-49b9-8077-197d1fc8a306
private void handleObjectCreations() { Date now = new Date(); // Create new rock if possible if(now.getTime() - lastRockCreatedAt.getTime() > rockCreatingRate) { int rnd = GameObject.randomWithRange(2, 4); Image imageToPass = null; ObjectBounds boundsToPass = null; if(rnd == 2) { imageToPass = rock32Image; boundsToPass = (ObjectBounds)rock32Bounds.clone(); } else if(rnd == 3) { imageToPass = rock48Image; boundsToPass = (ObjectBounds)rock48Bounds.clone(); } else if(rnd == 4) { imageToPass = rock64Image; boundsToPass = (ObjectBounds)rock64Bounds.clone(); } rocks.add(new Rock(rnd, imageToPass, boundsToPass, width, height)); lastRockCreatedAt = now; } // Create a bullet if possible if(now.getTime() - lastBulletFiredAt.getTime() > bulletFiringRate && isFiring) { // left side bullet bullets.add(new Bullet(ship.getX()+3, ship.getY()+20, this.width, this.height, bulletImage, (ObjectBounds)bulletBounds.clone())); // right side bullet bullets.add(new Bullet(ship.getX()+ship.getWidth()-8, ship.getY()+20, this.width, this.height, bulletImage, (ObjectBounds)bulletBounds.clone())); // center bullet int x = (int)(ship.getX() + (ship.getWidth() / 2)) - (bulletImage.getWidth(null) / 2); bullets.add(new Bullet(x, ship.getY(), this.width, this.height, bulletImage, (ObjectBounds)bulletBounds.clone())); lastBulletFiredAt = now; } }
06c5c969-7877-435f-bcb1-7df7a521a57e
private void handleObjectMovements() { for(Rock rock : rocks) { rock.advanceY(Direction.DOWN); } for(Bullet bullet : bullets) { bullet.advanceY(Direction.UP); } if(moveUp) { ship.advanceY(GameObject.Direction.UP); } if(moveDown) { ship.advanceY(GameObject.Direction.DOWN); } if(moveLeft) { ship.advanceX(GameObject.Direction.LEFT); } if(moveRight) { ship.advanceX(GameObject.Direction.RIGHT); } }
0bebecbd-16c4-4b3c-b8a3-1ef338cfb7b3
private void handleObjectCollisions() { for(Rock rock : rocks) { if(rock.getBounds().isInside(ship.getBounds())) { // Collision with ship detected gameState = 2; break; } for(Bullet bullet : bullets) { if(rock.getBounds().isInside(bullet.getBounds())) { rocks.remove(rock); bullets.remove(bullet); explosions.add(new Explosion(rock.getX(), rock.getY(), rock.getWidth())); Helper.playSoundFromByteArray(explosionSound); score += 50; handleObjectCollisions(); return; } } } }
60455845-a7ca-4ee3-bf1a-d6bd1afbb1d6
private void handleObjectEndings() { for(Rock rock : rocks) { if(rock.isOutsideScreen(Direction.DOWN)) { rocks.remove(rock); handleObjectEndings(); return; } } for(Bullet bullet : bullets) { if(bullet.isOutsideScreen(Direction.UP)) { bullets.remove(bullet); handleObjectEndings(); return; } } }
8f173001-828a-428a-aacb-33e4d846a6e9
private void handleExplosions() { handleExplosionRemoval(); for(Explosion explosion : explosions) { explosion.stepInto(); } }
a71c7074-b227-4349-9d6b-e92743d4a1bc
private void handleExplosionRemoval() { for(Explosion explosion : explosions) { if(explosion.isDone()) { explosions.remove(explosion); handleExplosionRemoval(); return; } } }
87f8a4c3-13c7-4d80-9695-98ca1cd458a2
private void doGameOverLogic() { if(enterPressed) { resetGame(); gameState = 1; } }
da434900-a618-4c53-bbeb-93e654b9bc7a
@Override public void paintComponent(Graphics g) { super.paintComponent(g); starfield.draw(g); //g.drawImage(backgroundImage, 0, 0, width, height, null); if(gameState == 0) { // Main Menu paintMenu(g); } else if(gameState == 1) { // Game Play paintGame(g); } else { // Game Over paintGame(g); paintGameOver(g); } }
20e3269b-a005-4734-be67-866a9f6f9869
private void paintMenu(Graphics g) { String menuStartName= "START"; Rectangle2D menuStartBounds = g.getFontMetrics().getStringBounds(menuStartName, g); String menuSettingsName = "SETTINGS"; Rectangle2D menuSettingsBounds = g.getFontMetrics().getStringBounds(menuSettingsName, g); String menuExitName = "QUIT"; Rectangle2D menuExitBounds = g.getFontMetrics().getStringBounds(menuExitName, g); int padding = 30; int middleY = (int)(height / 2); g.setColor(Color.WHITE); g.setFont(new Font("Helvetica", Font.PLAIN, 24)); int startX = (int)((width / 2) - (menuStartBounds.getWidth())); int startY = middleY - padding - (int)(menuStartBounds.getHeight()); int settingsX = (int)((width / 2) - (menuSettingsBounds.getWidth())); int settingsY = middleY - (int)(menuSettingsBounds.getHeight() / 2); int exitX = (int)((width / 2) - (menuExitBounds.getWidth())); int exitY = middleY + padding; // Display START button g.drawString(menuStartName, startX, startY); // Display SETTINGS button g.drawString(menuSettingsName, settingsX, settingsY); // Display EXIT button g.drawString(menuExitName, exitX, exitY); // Draw a line under the selected menu item if(selectedMenuItem == 0) { g.drawLine(startX, startY+5, startX + (int)menuStartBounds.getWidth()*2, startY+5); } else if(selectedMenuItem == 1) { g.drawLine(settingsX, settingsY+5, settingsX + (int)menuSettingsBounds.getWidth()*2, settingsY+5); } else if(selectedMenuItem == 2) { g.drawLine(exitX, exitY+5, exitX + (int)menuExitBounds.getWidth()*2, exitY+5); } }
e1ea3cc7-0bd1-40f2-b6f0-364b45834693
private void paintGame(Graphics g) { for(Rock rock : rocks) { Image img = null; if(rock.getType() == GameObject.Type.ROCK32) { img = rock32Image; } else if(rock.getType() == GameObject.Type.ROCK48) { img = rock48Image; } else if(rock.getType() == GameObject.Type.ROCK64) { img = rock64Image; } g.drawImage(img, rock.getX(), rock.getY(), rock.getWidth(), rock.getHeight(), null); if(drawObjectBorders) { g.setColor(Color.WHITE); for(Point point : rock.getBounds().getPoints()) { g.drawLine(point.getX()+rock.getX(), point.getY()+rock.getY(), point.getX()+rock.getX(), point.getY()+rock.getY()); } } } for(Explosion explosion : explosions) { g.drawImage(explosionImages.get(explosion.getAnimationStep()), explosion.getX(), explosion.getY(), explosion.getSize(), explosion.getSize(), null); } for(Bullet bullet : bullets) { g.setColor(Color.BLUE); //g.fillRect(bullet.getX(), bullet.getY(), bullet.getWidth(), bullet.getHeight()); g.drawImage(bullet.getImage(), bullet.getX(), bullet.getY(), bullet.getWidth(), bullet.getHeight(), null); } // Draw the spaceship g.drawImage(shipImage, ship.getX(), ship.getY(), ship.getWidth(), ship.getHeight(), null); if(drawObjectBorders) { g.setColor(Color.WHITE); for(Point point : ship.getBounds().getPoints()) { // Draw the border of the spaceship g.drawLine(point.getX()+ship.getX(), point.getY()+ship.getY(), point.getX()+ship.getX(), point.getY()+ship.getY()); } } g.setColor(Color.blue); g.setFont(new Font("Helvetica", Font.PLAIN, 18)); // Calculate position of score text String score = "SCORE: " + this.score; int scoreWidth = (int)g.getFontMetrics().getStringBounds(score, g).getWidth(); int startX = this.width - scoreWidth - 10; int startY = 20; // Draw player score g.drawString(score, startX, startY); // Draw the amount of time elapsed since the game started g.drawString("Time elapsed: " + (int)((new Date().getTime() - gameStartedAt.getTime()) / 1000), 10, 20); }
9941d058-8feb-4f6e-8111-12733214b708
private void paintGameOver(Graphics g) { g.setColor(Color.WHITE); g.setFont(new Font("Helvetica", Font.PLAIN, 48)); String gameOverText = "GAME OVER"; Rectangle2D gameOverBounds = g.getFontMetrics().getStringBounds(gameOverText, g); int startX = (int)((width / 2) - (gameOverBounds.getWidth() / 2)-2); int startY = (int)((height / 2) + (gameOverBounds.getHeight() / 2)-2); g.drawString(gameOverText, startX, startY); g.setColor(Color.BLUE); g.setFont(new Font("Helvetica", Font.PLAIN, 48)); gameOverBounds = g.getFontMetrics().getStringBounds(gameOverText, g); startX = (int)((width / 2) - (gameOverBounds.getWidth() / 2)); startY = (int)((height / 2) + (gameOverBounds.getHeight() / 2)); g.drawString(gameOverText, startX, startY); g.setColor(Color.BLUE); g.setFont(new Font("Helvetica", Font.PLAIN, 24)); gameOverText = "PRESS ENTER TO RESTART"; gameOverBounds = g.getFontMetrics().getStringBounds(gameOverText, g); startX = (int)((width / 2) - (gameOverBounds.getWidth() / 2)); startY = (int)((height / 2) + (gameOverBounds.getHeight() / 2) + 50); g.drawString(gameOverText, startX, startY); }
a91bc0d9-34fc-4da4-9b34-0ea8b71e606d
@Override public void actionPerformed(ActionEvent e) { Date loopStart = new Date(); doLogic(); repaint(); Date loopEnd = new Date(); if(gameTicks.size() < 30) { gameTicks.add(loopEnd.getTime() - loopStart.getTime()); } else { Long total = new Long(0L); for(Long one : gameTicks) { total += one; } System.out.println("Game tick averages at about: " + (total / gameTicks.size()) + " milliseconds"); gameTicks.clear(); } }
187dd206-fbc0-4b61-895d-f279db13bddd
@Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if(gameState == 0) { // Main Menu menuControlsBuffer.enqueue(key); return; } if(key == KeyEvent.VK_LEFT) { moveRight = false; moveLeft = true; } else if(key == KeyEvent.VK_RIGHT) { moveLeft = false; moveRight = true; } else if(key == KeyEvent.VK_UP) { moveDown = false; moveUp = true; } else if(key == KeyEvent.VK_DOWN) { moveUp = false; moveDown = true; } else if(key == KeyEvent.VK_F) { isFiring = true; } else if(key == KeyEvent.VK_ENTER) { enterPressed = true; } }
22494799-f915-4cc6-9c15-5b8d65e4d9a3
@Override public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if(key == KeyEvent.VK_LEFT) { moveLeft = false; } else if(key == KeyEvent.VK_RIGHT) { moveRight = false; } else if(key == KeyEvent.VK_UP) { moveUp = false; } else if(key == KeyEvent.VK_DOWN) { moveDown = false; } else if(key == KeyEvent.VK_F) { isFiring = false; } else if(key == KeyEvent.VK_ENTER) { enterPressed = false; } }
3013aa5a-3ea3-4c04-9375-619181a35866
public Starfield(int width, int height, int density) { this.width = width; this.height = height; this.density = density; this.stars = new ArrayList<Star>(); for(int i = 0; i < density; i++) { this.stars.add(Star.createRandomWithin(width, height)); } }
7c850984-3536-4b63-9bf5-190e901570af
public void doLogic() { handleStarCreation(); handleStarMovement(); handleStarRemoval(); }
97fe86fb-f012-4d4b-897c-b98962d450c1
public void handleStarCreation() { for(int i = stars.size(); i < density; i++) { stars.add(Star.createRandomWithin(width, 5)); } }
8885d2fa-dac1-4e6c-b223-fbde150fcc50
public void handleStarMovement() { for(Star star : stars) { star.move(); } }
2922d10d-8c86-46d2-b1d0-6e725f69a03b
public void handleStarRemoval() { for(Star star : stars) { if(star.isOutside(width, height)) { stars.remove(star); handleStarRemoval(); return; } } }
2d509649-f109-4283-aea0-81f0e6a84223
public void draw(Graphics g) { for(Star star : stars) { g.setColor(Color.WHITE); g.fillOval(star.getX(), star.getY(), star.getSize(), star.getSize()); //g.drawLine(star.getX(), star.getY(), star.getX(), star.getY()); } }
272968b8-2300-4467-b2d0-cd3190eb3835
public static final byte[] fileToByteArray(URL fileUrl) { try { // Create instances to start reading File file = new File(fileUrl.toURI()); FileInputStream fileInputStream = new FileInputStream(new File(fileUrl.toURI())); // Create a temporary byte array byte[] tmpByteArray = new byte[(int)file.length()]; // Read file into temporary byte array fileInputStream.read(tmpByteArray); fileInputStream.close(); // Return the temporary byte arrays return tmpByteArray; }catch(Exception e){ e.printStackTrace(); } return null; }
81aeb68a-c0cc-4606-a959-1c2a8aa8cbb8
public static final void playSoundFromByteArray(byte[] soundBytes) { try { // Open an audio input stream from the soundBytes array AudioInputStream inputStream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(soundBytes)); // Create a sound clip from the audio input stream, and play the sound Clip clip = AudioSystem.getClip(); clip.open(inputStream); inputStream.close(); clip.start(); } catch (Exception e) { e.printStackTrace(); } }
1a5a8a25-5e45-49bd-ad53-b3b4c6a92f00
public ObjectBounds(ArrayList<Point> points) { this.points = points; }
084e1b55-b622-4b56-a6dc-de219a225bd4
public void setXElevation(int xElevation) { this.xElevation = xElevation; }
c97ff733-9717-4690-9993-0994d34be3ea
public int getXElevation() { return this.xElevation; }
ef872439-4abe-4f2b-9cd7-a04e9f156d4b
public void setYElevation(int yElevation) { this.yElevation = yElevation; }
fb32622d-999f-44d2-b791-4e9acc0dbc58
public int getYElevation() { return this.yElevation; }
80748019-cc12-44dd-b627-b19bebf2d5d0
public void setElevation(int xElevation, int yElevation) { this.xElevation = xElevation; this.yElevation = yElevation; }
e88c3daa-a69a-49f0-b27b-0a11dea2edee
public ArrayList<Point> getPoints() { return this.points; }
42a02231-cd8d-4857-a2a7-7a9ddd364e63
public boolean isInside(ObjectBounds objectBounds2) { for(Point point : points) { for(Point point2 : objectBounds2.getPoints()) { if(point.getX() + xElevation == point2.getX() + objectBounds2.xElevation) { if(point.getY() + yElevation == point2.getY() + objectBounds2.yElevation) { return true; } } } } return false; }
29744373-a2ea-4f5b-adc1-e2ee11d37581
public static ObjectBounds parseFromFile(URL fileUrl) { try { ArrayList<Point> points = new ArrayList<Point>(); BufferedReader bReader = new BufferedReader(new InputStreamReader(fileUrl.openStream())); String fileContent = bReader.readLine(); String[] rawPoints = fileContent.split("\\|"); for(String rawPoint : rawPoints) { String[] splittedPoint = rawPoint.split(","); int x = Integer.parseInt(splittedPoint[0]); int y = Integer.parseInt(splittedPoint[1]); points.add(new Point(x, y)); } bReader.close(); return new ObjectBounds(points); } catch(Exception ex) { ex.printStackTrace(); } return null; }
bee90fa2-e741-4cff-9215-ef018a5fdea5
public Object clone() { try { return super.clone(); } catch(Exception ex) { ex.printStackTrace(); } return null; }
f330016e-53f8-4ad2-b8e1-22960cdb60cc
public Ship(Image image, ObjectBounds bounds, int panelWidth, int panelHeight) { setPanelSize(panelWidth, panelHeight); setType(GameObject.Type.SHIP); setImage(image); setBounds(bounds); setSizeByImage(); setSpeed(5); // Position the spaceship at the bottom center of the screen setX((int)((panelWidth / 2) - (getWidth() / 2))); setY(panelHeight - getHeight()); getBounds().setElevation(getX(), getY()); limitToScreenBounds(true); }
6dd4b033-4bd0-4a32-a0e1-d810b114620c
public Star() { this(0, 0, 1, 1); }
10bf6f45-d222-4b70-9b1a-71542d9db688
public Star(int x, int y, int size, int speed) { this.x = x; this.y = y; this.size = size; this.speed = speed; }
44610193-e2f5-4668-8c88-6f073bbe6e9e
public int getX() { return this.x; }
aceb10ff-8c90-4391-b9b6-612683ffc87c
public void setX(int x) { this.x = x; }
e8308f68-233b-4ecd-bfa1-af375aa66825
public int getY() { return this.y; }
0d51a8b1-5434-47ae-a03d-7a572b539bb7
public void setY(int y) { this.y = y; }
97125d6e-5743-4ba7-8519-3c65174c6f67
public int getSize() { return this.size; }
5ef04ff6-210b-43a3-9685-d319c4565cd9
public void setSize(int radius) { this.size = radius; }
f30fedcc-4be3-4dd3-842c-9d838fbd6a91
public int getSpeed() { return this.speed; }
101a0d09-1e22-4c01-99c3-0066334c16e7
public void setSpeed(int speed) { this.speed = speed; }
458f9019-9d61-406e-938d-2dccf36daba9
public void move() { this.y += speed; }
0b150adf-4c62-4976-b2df-75710d3f95cc
public boolean isOutside(int width, int height) { if(this.y > height) { return true; } return false; }
3bbf65f7-3b6f-4d48-8204-c11930d2192b
public static Star createRandomWithin(int width, int height) { int ranRadius = GameObject.randomWithRange(1, 2); int ranX = GameObject.randomWithRange(0, width-1-(ranRadius*2)); int ranY = GameObject.randomWithRange(0, height-1-(ranRadius*2)); int ranSpeed = ranRadius; return new Star(ranX, ranY, ranRadius, ranSpeed); }
7994eb4d-0584-4764-a00f-50409a611602
public Spaceship() { setTitle("Spaceship Game by Erik Kralj"); setSize(WIDTH, HEIGHT); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); add(new Board(getContentPane().getWidth(), getContentPane().getHeight())); }
c8401844-f2bb-4884-9d93-d824dcfc3447
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new Spaceship(); } }); }
fb345b95-77f9-4540-9463-4d7f2dec55a0
@Override public void run() { new Spaceship(); }
83715a06-a510-435c-b984-42cde58b2c21
public Explosion(int locationX, int locationY, int size) { this.locationX = locationX; this.locationY = locationY; this.size = size; }
80e5889a-be24-4283-8bb2-e1e1afbc1c9e
public int getX() { return this.locationX; }
3535a102-2f32-4e6d-80b6-accc3f4c6a05
public int getY() { return this.locationY; }
62d8fcf8-e4c9-43e5-82e9-699c2fc8bb3d
public int getSize() { return this.size; }
9f893dc5-4488-4f27-bbc9-29c6cfc336b6
public boolean isDone() { return this.done; }
0736f406-7e4f-4bfb-b8c3-9c48a111563f
public void stepInto() { if(animationStep == animationStopAt) { done = true; return; } animationStep++; }
d730ca20-ef4d-49e9-92ab-16feb2933681
public int getAnimationStep() { return this.animationStep; }
dfce595f-96b2-467b-8a11-607d0e33dc38
public Rock(int type, Image image, ObjectBounds bounds, int panelWidth, int panelHeight) { setPanelSize(panelWidth, panelHeight); setType(GameObject.Type.values()[type]); setImage(image); setBounds(bounds); setSizeByImage(); setSpeed(3); setX(GameObject.randomWithRange(0, panelWidth - getWidth())); setY(-getHeight()); limitToScreenBounds(false); }
12908fba-c071-4783-8552-c97879482916
public Bullet(int locationX, int locationY, int panelWidth, int panelHeight, Image image, ObjectBounds bounds) { setPanelSize(panelWidth, panelHeight); setType(GameObject.Type.BULLET); setX(locationX); setY(locationY); setImage(image); setBounds(bounds); setSizeByImage(); setSpeed(8); getBounds().setElevation(getX(), getY()); limitToScreenBounds(false); }
55815a3c-7dbf-4a6a-a636-7e7b3999b742
public Type getType() { return this.type; }
726711f2-09cb-45c2-905e-2943e0b3c87e
public void setType(Type type) { this.type = type; }
8805e3bd-7c6c-48e2-be17-d3ac1d043e10
public int getX() { return this.x; }
587a5223-823a-4a7c-8f5a-ff58699d19ff
public void setX(int x) { this.x = x; }