View Game: ApoNurikabe4k

ApoNurikabe4k (http://www.apo-games.de/apoNurikabe4k/)

By ApoGames, submitted on Dec 2, 2012
Min JRE version: 1.6
2020 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

ApoNurikabe4k is a binary determination puzzle
published by Nikoli.

There are 4 simple rules:
1: All dark gray squares must be orthagonally
connected (not diagonally).
2: The dark gray squares cannot form a 2x2 block.
3: A square with a number represents an "island"
of empty squares, where the number indicates
the area of the island.
4: The islands are not orthagonally adjacent
(diagonally is okay).

Instructions

Play with the mouse and click on a tile to place a block or to remove it.

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 E extends Applet implements Runnable { private final String[] levels = new String[] { "000200"+ "000020"+ "300000"+ "004000"+ "010002"+ "000000", "100040"+ "020000"+ "000000"+ "000004"+ "030000"+ "002000", "502000"+ "000000"+ "000004"+ "000000"+ "020004"+ "100000", "200000"+ "000004"+ "001020"+ "200000"+ "000000"+ "000007", "020001"+ "000000"+ "050400"+ "002000"+ "000000"+ "000002", "200000"+ "000040"+ "030006"+ "000000"+ "010000"+ "000000", "000003"+ "030000"+ "200010"+ "000000"+ "030000"+ "000002", "100003"+ "020000"+ "000000"+ "000002"+ "000050"+ "200000", "000000"+ "004004"+ "000010"+ "000300"+ "000000"+ "200000", "000005"+ "000800"+ "001000"+ "000000"+ "000000"+ "700000", "00000002"+ "00020000"+ "30000000"+ "00204000"+ "00000020"+ "03000208"+ "00000000"+ "10000000", "00000307"+ "03000000"+ "00000000"+ "00100000"+ "40000200"+ "00000000"+ "00004020"+ "00000100", "00000002"+ "00007000"+ "01020300"+ "00000000"+ "00000000"+ "00000100"+ "00400000"+ "06000005", "00300001"+ "00000300"+ "02010000"+ "00000030"+ "00000000"+ "30020000"+ "02000000"+ "00000304", "00000001"+ "30000050"+ "00000000"+ "04004020"+ "00000400"+ "00000000"+ "00000000"+ "00020000", "00800000"+ "00000000"+ "00020000"+ "00007040"+ "00000000"+ "00000000"+ "20000100"+ "00020050", "00000000"+ "00004000"+ "04020000"+ "00000000"+ "00001003"+ "00100000"+ "00000200"+ "00009000", "30000000"+ "00100200"+ "00000000"+ "03000200"+ "40000070"+ "00000400"+ "00000000"+ "00300000", "01000000"+ "00000200"+ "00400040"+ "00000200"+ "00400000"+ "00000000"+ "00040000"+ "00000050", "00000006"+ "00000000"+ "00100000"+ "40002040"+ "00000000"+ "00000000"+ "05002000"+ "00200002", }; /** * p[0] == X-Wert Maus * p[1] == Y-Wert Maus * p[2] == aktuelles Level * p[3] == aktuelle Moveanzahl * p[4] == Maus gedrückt * p[5] == Maus losgelassen * p[6] == Spiel gestartet * p[7] == Level geschafft Klick */ private final int[] p = new int[8]; public void start() { new Thread(this).start(); } public void run() { // setSize(400, 400); // für den AppletViewer // Graphische Grundlagen für das Double Buffering BufferedImage screen = new BufferedImage(400,400,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 = 10000000L; int width = 5; int[][] level = new int[width][width]; level[0][0] = -1; int[][] what = new int[width][width]; int realWidth = 60; p[6] = 1; // 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 (level[0][0] == -1) { if (p[2] >= levels.length) { p[2] = 0; } if (p[2] < 0) { p[2] = levels.length - 1; } String l = levels[p[2]]; width = 5; if (l.length() == 36) { width = 6; } else if (l.length() == 64) { width = 8; } realWidth = 300 / width; level = new int[width][width]; what = new int[width][width]; for (int y = 0; y < width; y++) { for (int x = 0; x < width; x++) { level[y][x] = Integer.valueOf(l.substring(y * width + x, y * width + x + 1)); } } p[3] = 0; p[7] = 0; } else if (p[6] > 0) { if (p[4] > 0) { if (p[7] > 0) { p[2] += 1; level[0][0] = -1; think += 10000000L; } else if ((p[0] > 110) && (p[0] < 160) && (p[1] > 365) && (p[1] < 395)) { p[2] -= 1; level[0][0] = -1; think += 10000000L; } else if ((p[0] > 240) && (p[0] < 290) && (p[1] > 365) && (p[1] < 395)) { p[2] += 1; level[0][0] = -1; think += 10000000L; } else if ((p[0] > 160) && (p[0] < 240) && (p[1] > 360) && (p[1] < 395)) { level[0][0] = -1; think += 10000000L; } else { if ((p[0] > 50) && (p[0] < 350) && (p[1] > 50) && (p[1] < 350)) { int curX = (p[0] - 50) / realWidth; int curY = (p[1] - 50) / realWidth; if (level[curY][curX] <= 0) { what[curY][curX] += 1; p[3] += 1; if (what[curY][curX] >= 1) { what[curY][curX] = -1; } boolean bBreak = false; if (!bBreak) { for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (level[y][x] > 0) { if (!this.isOne(new boolean[width][width], new boolean[width][width], what, x, y, 0, level[y][x], 0)) { bBreak = true; break; } } if ((x < width - 1) && (y < width - 1)) { if ((what[y][x] < 0) && (what[y][x + 1] < 0) && (what[y + 1][x] < 0) && (what[y + 1][x + 1] < 0)) { bBreak = true; break; } } } if (bBreak) { break; } } if (!bBreak) { for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (what[y][x] < 0) { if (this.isOne(new boolean[width][width], new boolean[width][width], what, x, y, -1, 0, 0)) { p[7] = 1; } bBreak = true; break; } } if (bBreak) { break; } } } } } } } } } p[4] = 0; p[5] = 0; } lastTime = now; // Renderabschnitt // Hintergrund malen g.setColor(Color.GRAY); g.fillRect(0, 0, 400, 400); g.setFont(g.getFont().deriveFont(25f).deriveFont(1)); for (int y = 0; y < width; y++) { for (int x = 0; x < width; x++) { g.setColor(Color.LIGHT_GRAY); g.fillRect(50 + x * realWidth, 50 + y * realWidth, realWidth, realWidth); g.setColor(Color.DARK_GRAY); g.drawRect(50 + x * realWidth, 50 + y * realWidth, realWidth, realWidth); if (what[y][x] < 0) { g.fillRect(50 + x * realWidth + 1, 50 + y * realWidth + 1, realWidth - 1, realWidth - 1); } else if (level[y][x] > 0) { String s = String.valueOf(level[y][x]); int w = g.getFontMetrics().stringWidth(s); g.drawString(String.valueOf(level[y][x]), 53 + x * realWidth + realWidth/2 - w/2, 50 + y * realWidth + realWidth - 15 + (width - 6) * 3); } } } g.setColor(Color.LIGHT_GRAY); g.fillRect(0, 360, 400, 40); g.fillRect(0, 0, 400, 40); g.setColor(Color.DARK_GRAY); g.drawRect(0, 0, 399, 399); g.drawRect(0, 40, 399, 320); g.setFont(g.getFont().deriveFont(20f).deriveFont(1)); String s = "ApoNurikabe4k"; int w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 30); if (p[7] > 0) { g.setFont(g.getFont().deriveFont(15f).deriveFont(1)); s = "Congratulation!"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 377); s = "Click to start the next level!"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 396); } else { g.drawRect(110, 365, 180, 30); g.drawRect(160, 365, 80, 30); if ((p[0] > 160) && (p[0] < 240) && (p[1] > 365) && (p[1] < 395)) { g.setColor(Color.YELLOW.darker()); } s = "reset"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 200 - w/2, 388); if ((p[0] > 110) && (p[0] < 160) && (p[1] > 365) && (p[1] < 395)) { g.setColor(Color.YELLOW.darker()); } else { g.setColor(Color.DARK_GRAY); } s = "<"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 135 - w/2, 388); if ((p[0] > 240) && (p[0] < 290) && (p[1] > 365) && (p[1] < 395)) { g.setColor(Color.YELLOW.darker()); } else { g.setColor(Color.DARK_GRAY); } s = ">"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 265 - w/2, 388); g.setColor(Color.DARK_GRAY); g.setFont(g.getFont().deriveFont(15f).deriveFont(1)); s = "level: "+String.valueOf((int)(p[2] + 1))+" / "+String.valueOf(levels.length); g.drawString(s, 10, 30); s = "clicks: "+String.valueOf((int)(p[3])); w = g.getFontMetrics().stringWidth(s); g.drawString(s, 390 - w, 30); } // 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; } } } private final boolean isOne(boolean[][] isCurVisited, boolean[][] isVisited, int[][] what, int px, int py, int check, int count, int curVisited) { isVisited[py][px] = true; isCurVisited[py][px] = true; if ((curVisited > count) && (check >= 0)) { return false; } if ((px - 1 >= 0) && (what[py][px-1] == check) && (!isCurVisited[py][px-1])) { isOne(isCurVisited, isVisited, what, px - 1, py, check, count, ++curVisited); --curVisited; } if ((px + 1 < what[0].length) && (what[py][px+1] == check) && (!isCurVisited[py][px+1])) { isOne(isCurVisited, isVisited, what, px + 1, py, check, count, ++curVisited); --curVisited; } if ((py - 1 >= 0) && (what[py-1][px] == check) && (!isCurVisited[py-1][px])) { isOne(isCurVisited, isVisited, what, px, py - 1, check, count, ++curVisited); --curVisited; } if ((py + 1 < what.length) && (what[py+1][px] == check) && (!isCurVisited[py+1][px])) { isOne(isCurVisited, isVisited, what, px, py + 1, check, count, ++curVisited); --curVisited; } isCurVisited[py][px] = false; int c = 0; for (int y = 0; y < what.length; y++) { for (int x = 0; x < what[0].length; x++) { if (check == -1) { if ((what[y][x] == check) && (!isVisited[y][x])) { return false; } } else { if (isVisited[y][x]) { c += 1; } } } } if (check >= 0) { if (c != count) { return false; } } return true; } public boolean handleEvent(Event e) { switch (e.id) { case Event.KEY_PRESS: break; case Event.KEY_ACTION: case Event.KEY_RELEASE: break; case Event.MOUSE_DOWN: // mouse button pressed p[4] = 1; p[5] = 0; break; case Event.MOUSE_UP: // mouse button released p[4] = 0; p[5] = 1; 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; case Event.MOUSE_ENTER: case Event.MOUSE_EXIT: break; } return false; } }