View Game: ApoPush4k

ApoPush4k (http://www.apo-games.de/apoPush4k/)

By ApoGames, submitted on Dec 2, 2012
Min JRE version: 1.6
2035 downloads.
This game was submitted in the Java4K 2013 Competition.
Source code available! Show source code

(Click on game for focus)

Sorry, your Browser doesn't support Applets
You need Java installed to play this game.
You may use the button below to get it.

Get Java


Description

ApoPush4k a clever but tricky match 3 game.

Your goal is to clear the gray fields.
Match 3 or more tiles to remove them.
Push the tiles from up, down, left or right into the field.

Instructions

Play the game with the mouse.

User Comments

No comments have been made.

You need be logged in to write comments. If you need to register click here.

Source code

Note: We recommend you copy+paste this to a better editor. Some special character encoding may have been lost.

* All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.applet.Applet; import java.awt.Color; import java.awt.Event; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; public class B extends Applet implements Runnable { /** * p[0] == X-Wert Maus * p[1] == Y-Wert Maus * p[2] == aktuelles Level * p[3] == aktuelle Moveanzahl * p[4] == Spiel gestartet * p[5] == maximale Anzahl unterschiedlicher Figuren * p[6] == Punkte * p[7] == Maustaste gedrückt * p[8] == Level Up */ private final float[] p = new float[9]; /** * erste 4 = level * zweite 4 = change X * dritte 4 = muss noch verändert werden (0 nein, 1 ja) * vierte 4 = change Y */ private final float[][] level = new float[16][4]; public void start() { new Thread(this).start(); } public void run() { setSize(300, 370); // für den AppletViewer // Graphische Grundlagen für das Double Buffering BufferedImage screen = new BufferedImage(300,370,BufferedImage.TYPE_INT_RGB); Graphics2D g = screen.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Graphics2D appletGraphics = (Graphics2D)getGraphics(); // Variablen zum Zeitmessen und genau Timen wann geupdatet werden soll long lastTime = System.nanoTime(); long think = lastTime; float next = -1; float curNext = -1; level[0][0] = -1; p[4] = 0; // Game loop. while (true) { long now = System.nanoTime(); long delta = now - lastTime; think += delta; // Update / think // Wenn 10 ms vergangen sind, dann denke nach while (think >= 10000000L) { think -= 10000000L; if (p[4] > 0) { if (p[8] > 0) { if (p[7] > 0) { p[8] = 0; } } else if (level[0][0] < 0) { for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { level[y][x] = 0; level[y+4][x] = 0; level[y+12][x] = 0; level[y+8][x] = 1; } } p[5] = (int)(4 + p[2]); next = (int)(Math.random() * p[5] + 1); curNext = (int)(Math.random() * p[5] + 1); if (next > 12) { next = (int)(Math.random() * 11 + 1); } if (curNext > 12) { curNext = (int)(Math.random() * 11 + 1); } } else { boolean bMove = false; boolean bReady = false; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { if (level[y+4][x] < 0) { bMove = true; level[y+4][x] += 3.0f; if (level[y+4][x] >= 0) { level[y+4][x] = 0; bReady = true; } } else if (level[y+4][x] > 0) { bMove = true; level[y+4][x] -= 3.0f; if (level[y+4][x] <= 0) { level[y+4][x] = 0; bReady = true; } } if (level[y+12][x] < 0) { bMove = true; level[y+12][x] += 3.0f; if (level[y+12][x] >= 0) { level[y+12][x] = 0; bReady = true; } } else if (level[y+12][x] > 0) { bMove = true; level[y+12][x] -= 3.0f; if (level[y+12][x] <= 0) { level[y+12][x] = 0; bReady = true; } } } } if (bReady) { // fertig mit Bewegung, testen ob löschen for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { if (level[y+4][x] != 0) { bReady = false; } if (level[y+12][x] != 0) { bReady = false; } } } if (bReady) { boolean[][] delete = new boolean[4][4]; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { int value = (int)(level[y][x]); if (value > 0) { if (x - 2 >= 0) { if ((level[y][x-2] == value) && (level[y][x-1] == value)) { delete[y][x-2] = true; delete[y][x-1] = true; delete[y][x] = true; p[6] += 10 + p[2] * 2; } } if ((x - 1 >= 0) && (x + 1 < 4)) { if ((level[y][x-1] == value) && (level[y][x+1] == value)) { delete[y][x+1] = true; delete[y][x-1] = true; delete[y][x] = true; p[6] += 10 + p[2] * 2; } } if (x + 2 < 4) { if ((level[y][x+2] == value) && (level[y][x+1] == value)) { delete[y][x+1] = true; delete[y][x+2] = true; delete[y][x] = true; p[6] += 10 + p[2] * 2; } } if (y - 2 >= 0) { if ((level[y-2][x] == value) && (level[y-1][x] == value)) { delete[y-2][x] = true; delete[y-1][x] = true; delete[y][x] = true; p[6] += 10 + p[2] * 2; } } if ((y - 1 >= 0) && (y + 1 < 4)) { if ((level[y-1][x] == value) && (level[y+1][x] == value)) { delete[y+1][x] = true; delete[y-1][x] = true; delete[y][x] = true; p[6] += 10 + p[2] * 2; } } if (y + 2 < 4) { if ((level[y+2][x] == value) && (level[y+1][x] == value)) { delete[y+1][x] = true; delete[y+2][x] = true; delete[y][x] = true; p[6] += 10 + p[2] * 2; } } } } } boolean bOver = false; boolean bFull = true; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { if (delete[y][x]) { level[y+8][x] = 0; level[y][x] = 0; } if (level[y+8][x] > 0) { bOver = true; } if (level[y][x] <= 0) { bFull = false; } } } if (!bOver) { p[6] += 100 + p[2] * 20; p[2] += 1; level[0][0] = -1; p[8] = 1; } else if (bFull) { p[4] = 0; } } } else if ((!bMove) && (p[7] > 0)) { // Maus gedrückt int x = (int)(p[0] - 50) / 50; int y = (int)(p[1] - 120) / 50; if (p[0] < 50) { x = -1; } else if (p[0] > 250) { x = 4; } else if (p[1] < 220) { y = -1; if (x < 0) { y = 0; } } else { y = 4; if (x > 3) { y = 3; } } boolean bNew = false; int count = 0; if (x == -1) { for (int i = 3; i >= 0; i--) { if (level[y][i] == 0) { count += 1; } else if (count > 0) { level[y][i + count] = level[y][i]; level[y][i] = 0; level[y + 4][i + count] = -count * 50; } } if (count > 0) { level[y][0 + count - 1] = curNext; level[y+4][0 + count - 1] = -count * 50; bNew = true; } } else if (x == 4) { if (y < 0) { y = 0; } for (int i = 0; i < 4; i++) { if (level[y][i] == 0) { count += 1; } else if (count > 0) { level[y][i - count] = level[y][i]; level[y][i] = 0; level[y + 4][i - count] = count * 50; } } if (count > 0) { level[y][4 - count] = curNext; level[y+4][4 - count] = count * 50; bNew = true; } } else if (y == -1) { for (int i = 3; i >= 0; i--) { if (level[i][x] == 0) { count += 1; } else if (count > 0) { level[i + count][x] = level[i][x]; level[i][x] = 0; level[i + count + 12][x] = -count * 50; } } if (count > 0) { level[-1 + count][x] = curNext; level[-1 + count + 12][x] = -count * 50; bNew = true; } } else if (y == 4) { for (int i = 0; i < 4; i++) { if (level[i][x] == 0) { count += 1; } else if (count > 0) { level[i - count][x] = level[i][x]; level[i][x] = 0; level[i - count + 12][x] = count * 50; } } if (count > 0) { level[4 - count][x] = curNext; level[4 - count + 12][x] = count * 50; bNew = true; } } if (bNew) { p[6] += p[2] + 1; curNext = next; next = (int)(Math.random() * p[5] + 1); if (next > 12) { next = (int)(Math.random() * 11 + 1); } } } } } else if ((p[0] >= 70) && (p[0] <= 230) && (p[1] >= 310) && (p[1] <= 350)) { if (p[7] > 0) { // Spiel starten p[4] = 1; level[0][0] = -1; think = 10000000L; p[2] = 0; p[3] = 0; p[6] = 0; p[8] = 0; } } p[7] = 0; } lastTime = now; // Renderabschnitt // Hintergrund malen g.setColor(Color.WHITE); g.fillRect(0, 0, 300, 370); g.setColor(Color.BLACK); g.drawRect(0, 0, 299, 369); if (p[4] <= 0) { g.drawLine(0, 155, 300, 155); g.drawLine(0, 215, 300, 215); g.setColor(Color.BLACK); g.setFont(g.getFont().deriveFont(50f).deriveFont(1)); String s = "ApoPush4k"; int w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 205); if (p[6] > 0) { s = "Points: "+String.valueOf((int)(p[6])); w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 125); } g.setFont(g.getFont().deriveFont(15f).deriveFont(1)); s = "Your task is to clear the gray fields"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 240); s = "Match 3 or more tiles to remove them"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 260); s = "Push the tiles from up, down,"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 280); s = "left or right into the field"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 300); g.setFont(g.getFont().deriveFont(30f).deriveFont(1)); s = "start"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 340); if ((p[0] >= 70) && (p[0] <= 230) && (p[1] >= 310) && (p[1] <= 350)) { g.setColor(Color.YELLOW); } g.drawRoundRect(70, 310, 160, 40, 15, 15); } else { g.setFont(g.getFont().deriveFont(17f).deriveFont(1)); String s = "ApoPush4k"; int w = g.getFontMetrics().stringWidth(s); g.drawString(s, 150 - w/2, 40); g.setFont(g.getFont().deriveFont(15f).deriveFont(1)); g.drawString("level: "+String.valueOf((int)(p[2] + 1)), 10, 55); g.drawString("points: "+String.valueOf((int)(p[6])), 10, 30); g.drawString("next: ", 215, 40); g.drawLine(0, 65, 300, 65); for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { if (level[y+8][x] > 0) { g.setColor(Color.GRAY); } else { g.setColor(new Color(230, 230, 230)); } g.fillRect(53 + x * 50, 70 + 53 + y * 50, 44, 44); if (p[8] > 0) { g.setColor(Color.BLACK); int f = (y * 4 + x) % 16; g.drawString("moretilewillcome".substring(f, f + 1), 70 + x * 50, 70 + 85 + y * 50); } } } if (p[8] <= 0) { for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { int changeX = 0; int changeY = 0; int max = 1; if (((x == 0) && (y == 0)) || ((x == 1) && (y == 0))) { max = 2; } int value = (int)level[y][x]; for (int k = 0; k < max; k++) { if (k > 0) { if (x == 0) { changeX = 200 - (int)(level[y+4][x]); changeY = -110 - (int)(level[y+12][x]); value = (int)next; } else { if ((p[0] < 50) || (p[0] > 250)) { if (p[0] < 50) { changeX = -100 - (int)(level[y+4][x]); } else { changeX = 150 - (int)(level[y+4][x]); } if (p[1] < 170) { changeY = - (int)(level[y+4][x]); } else if (p[1] < 220) { changeY = 50 - (int)(level[y+4][x]); } else if (p[1] < 270) { changeY = 100 - (int)(level[y+4][x]); } else { changeY = 150 - (int)(level[y+4][x]); } } else { if (p[1] < 220) { changeY = -50 - (int)(level[y+4][x]); } else { changeY = 200 - (int)(level[y+4][x]); } if (p[0] < 100) { changeX = -50 - (int)(level[y+4][x]); } else if (p[0] < 150) { changeX = (int)(level[y+4][x]); } else if (p[0] < 200) { changeX = 50 - (int)(level[y+4][x]); } else { changeX = 100 - (int)(level[y+4][x]); } } value = (int)curNext; } } if (value > 0) { if ((value == 1) || (value == 5) || (value == 9)) { g.setColor(Color.YELLOW); if (value == 1) { g.setColor(Color.GREEN); } else if (value == 5) { g.setColor(Color.RED); } g.fillPolygon(new int[] {50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 25 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 45 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 25 + x * 50 + (int)(level[y+4][x])}, new int[] {70 + changeY + 75 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 75 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 95 + y * 50 + (int)(level[y+12][x])}, 4); g.setColor(Color.BLACK); g.drawPolygon(new int[] {50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 25 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 45 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 25 + x * 50 + (int)(level[y+4][x])}, new int[] {70 + changeY + 75 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 75 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 95 + y * 50 + (int)(level[y+12][x])}, 4); } else if ((value == 2) || (value == 6) || (value == 10)) { g.setColor(Color.BLUE); if (value == 2) { g.setColor(Color.MAGENTA); } else if (value == 6) { g.setColor(Color.PINK); } g.fillPolygon(new int[] {50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 25 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 45 + x * 50 + (int)(level[y+4][x])}, new int[] {70 + changeY + 95 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 95 + y * 50 + (int)(level[y+12][x])}, 3); g.setColor(Color.BLACK); g.drawPolygon(new int[] {50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 25 + x * 50 + (int)(level[y+4][x]), 50 + changeX + 45 + x * 50 + (int)(level[y+4][x])}, new int[] {70 + changeY + 95 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 95 + y * 50 + (int)(level[y+12][x])}, 3); } else if ((value == 3) || (value == 7) || (value == 11)) { g.setColor(Color.WHITE); if (value == 3) { g.setColor(Color.CYAN); } else if (value == 7) { g.setColor(Color.ORANGE); } g.fillOval(50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 40, 40); g.setColor(Color.BLACK); g.drawOval(50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 40, 40); } else if ((value == 4) || (value == 8) || (value == 12)) { g.setColor(Color.DARK_GRAY); if (value == 4) { g.setColor(Color.BLUE.brighter().brighter()); } else if (value == 8) { g.setColor(Color.YELLOW.darker().darker()); } g.fillPolygon(new int[] {50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 75 + changeX + x * 50 + (int)(level[y+4][x]), 50 + changeX + 45 + x * 50 + (int)(level[y+4][x])}, new int[] {70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 95 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x])}, 3); g.setColor(Color.BLACK); g.drawPolygon(new int[] {50 + changeX + 5 + x * 50 + (int)(level[y+4][x]), 75 + changeX + x * 50 + (int)(level[y+4][x]), 50 + changeX + 45 + x * 50 + (int)(level[y+4][x])}, new int[] {70 + changeY + 55 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 95 + y * 50 + (int)(level[y+12][x]), 70 + changeY + 55 + y * 50 + (int)(level[y+12][x])}, 3); } } } } } } else { g.setColor(Color.BLACK); g.drawString("Click the mouse to start the next level", 10, 365); } } // Render das Ganze auf den Bildschirm appletGraphics.drawImage(screen, 0, 0, null); try { Thread.sleep(10); } catch (Exception e) { /** nicht schön aber selten */ } ; if (!isActive()) { return; } } } public boolean handleEvent(Event e) { switch (e.id) { case Event.KEY_PRESS: case Event.KEY_ACTION: break; case Event.KEY_RELEASE: if (e.key == Event.ESCAPE) { if (p[4] == 1) { p[4] = 0; } } break; case Event.MOUSE_DOWN: // mouse button pressed p[7] = 1; break; case Event.MOUSE_UP: // mouse button released break; case Event.MOUSE_MOVE: p[0] = e.x; p[1] = e.y; break; case Event.MOUSE_DRAG: p[0] = e.x; p[1] = e.y; break; } return false; } }