TicCeption (http://apo-games.de/ticCeption/)
By ApoGames, submitted on Feb 27, 2014 |
(Click on game for focus) |
TicCeption is a TicTacToe game in a TicTacToe game.
The objective of this game is to be the first to win three tic-tac-tow games lying in a row, column, or diagonal within the greater-square.
Play the game with the mouse.
Rules of Play:
1. The first player place an "X" in any cell within any mini-square on the board.
2. The selected cell position within this mini-square corresponds to the mini-square position within the greater-square where the second player must then place an "O"
3. Thereafter, the two players take turns placing their mark on any unfilled cell within the mini-square dictated by the cell position marked by the previous player. For the first player, this mini-square will be outlined in red.
4. If a player is sent to a mini-square that has already been won, or in which all the cells are already filled, then the player may next place his mark in any unfilled cell in any other mini-board.
No comments have been made.
You need be logged in to write comments. If you need to register click here.
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.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Event; import java.awt.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; public class T extends Applet implements Runnable { private int mouseX; private int mouseY; private boolean bMouseClick; 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(480,530,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; int state = 0; int i = 0; int x = 0; int y = 0; int w = 0; final int[] testField = new int[8]; int curX = -1; int curY = -1; int curTile = -1; int curField = 4; int turn = 1; int winner = -1; int[] level = new int[90]; int time = 500; int waitTime = 1000; final BasicStroke strokeThick = new BasicStroke(3); final BasicStroke strokeThin = new BasicStroke(1); final Color blue = new Color(100, 150, 255); final Color red = new Color(255, 100, 100); // 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 (state == 0) { if (this.bMouseClick) { state = 1; turn = 1; level = new int[90]; curField = 4; winner = -1; } } else if (state == 1) { time -= 10; if (time < -500)="" {="" time="1000;" }="" curx="-1;" cury="-1;" boolean="" test="false;" computer="" if="" (turn="=" 2)="" {="" waittime="" -="10;" if="" (waittime="">< 0)="" {="" waittime="(int)(Math.random()" *="" 1000);="" }="" }="" if="" ((turn="=" 1)="" ||="" (turn="=" 2))="" {="" if="" ((this.mousey=""> 50) && (this.mouseY < 530))="" {="" x="this.mouseX" -="" (this.mousex="" 160)="" *="" 160;="" if="" ((x="">= 5) && (x < 155))="" {="" curx="(x" -="" 5)="" 50;="" }="" y="(this.mouseY" -="" 50)="" -="" ((this.mousey="" -="" 50)="" 160)="" *="" 160;="" if="" ((y="">= 5) && (y < 155))="" {="" cury="(y" -="" 5)="" 50;="" }="" curtile="this.mouseX" 160="" +="" ((this.mousey="" -="" 50)="" 160)="" *="" 3;="" if="" (((curtile="" !="curField)" &&="" (curfield="">= 0)) || (curX < 0)="" ||="" (cury="">< 0)="" ||="" (level[curtile="" *="" 9="" +="" curx="" +="" cury="" *="" 3]=""> 0) || (level[81 + curTile] > 0)) { curTile = -1; } } if ((this.bMouseClick) && (curX >= 0) && ((curTile == curField) || (curField == -1)) && (level[curTile * 9 + curX + curY * 3] == 0) && (level[81 + curTile] == 0)) { level[curTile * 9 + curX + curY * 3] = turn; turn += 1; if (turn > 2) { turn = 1; } test = true; time = 1000; } } if (test) { // test horizontal, vertical and diagonal for (i = 0; i < 3;="" i++)="" {="" for="" (x="0;" x="">< 8;="" x++)="" {="" if="" (i="=" 0)="" {="" if="" (x="">< 3)="" {="" testfield[x]="level[curTile" *="" 9="" +="" x="" *="" 3];="" }="" else="" if="" (x="">< 6)="" {="" testfield[x]="level[curTile" *="" 9="" +="" (x="" -="" 3)];="" }="" if="" (x="=" 6)="" {="" testfield[x]="level[curTile" *="" 9];="" }="" if="" (x="=" 7)="" {="" testfield[x]="level[curTile" *="" 9="" +="" 2];="" }="" }="" if="" (i="" !="0)" {="" if="" (x="">< 3)="" {="" if="" (testfield[x]="" !="level[curTile" *="" 9="" +="" i="" +="" x*3])="" {="" testfield[x]="-1;" }="" }="" else="" if="" (x="">< 6)="" {="" if="" (testfield[x]="" !="level[curTile" *="" 9="" +="" i="" *="" 3="" +="" (x="" -="" 3)])="" {="" testfield[x]="-1;" }="" }="" if="" (x="=" 6)="" {="" if="" (testfield[x]="" !="level[curTile" *="" 9="" +="" i="" *="" 4])="" {="" testfield[x]="-1;" }="" }="" if="" (x="=" 7)="" {="" if="" (testfield[x]="" !="level[curTile" *="" 9="" +="" 2="" +="" i="" *="" 2])="" {="" testfield[x]="-1;" }="" }="" }="" }="" }="" for="" (x="0;" x="">< 8;="" x++)="" {="" if="" (testfield[x]=""> 0) { level[81+curTile] = testField[x]; } test = true; for (y = 0; y < 9;="" y++)="" {="" if="" (level[x="" *="" 9="" +="" y]=""><= 0)="" {="" test="false;" }="" }="" if="" (test)="" {="" level[81+curtile]="3;" }="" }="" curfield="curX" +="" 3="" *="" cury;="" if="" (level[81="" +="" curfield]=""> 0) { curField = -1; } // test horizontal, vertical and diagonal (for all) for (i = 0; i < 3;="" i++)="" {="" for="" (x="0;" x="">< 8;="" x++)="" {="" if="" (i="=" 0)="" {="" if="" (x="">< 3)="" {="" testfield[x]="level[81" +="" x="" *="" 3];="" }="" else="" if="" (x="">< 6)="" {="" testfield[x]="level[81" +="" (x="" -="" 3)];="" }="" if="" (x="=" 6)="" {="" testfield[x]="level[81];" }="" if="" (x="=" 7)="" {="" testfield[x]="level[81" +="" 2];="" }="" }="" if="" (i="" !="0)" {="" if="" (x="">< 3)="" {="" if="" (testfield[x]="" !="level[81" +="" i="" +="" x*3])="" {="" testfield[x]="-1;" }="" }="" else="" if="" (x="">< 6)="" {="" if="" (testfield[x]="" !="level[81" +="" i="" *="" 3="" +="" (x="" -="" 3)])="" {="" testfield[x]="-1;" }="" }="" if="" (x="=" 6)="" {="" if="" (testfield[x]="" !="level[81" +="" i="" *="" 4])="" {="" testfield[x]="-1;" }="" }="" if="" (x="=" 7)="" {="" if="" (testfield[x]="" !="level[81" +="" 2="" +="" i="" *="" 2])="" {="" testfield[x]="-1;" }="" }="" }="" }="" }="" for="" (x="0;" x="">< 8;="" x++)="" {="" if="" (testfield[x]=""> 0) { state = 0; winner = testField[x]; curX = -1; time = -1; } } if (winner < 0)="" {="" test="true;" for="" (x="0;" x="">< 9;="" x++)="" {="" if="" (level[81="" +="" x]=""><= 0)="" {="" test="false;" }="" }="" if="" (test)="" {="" winner="0;" state="0;" curx="-1;" time="-1;" }="" }="" }="" }="" this.bmouseclick="false;" }="" lasttime="now;" alphacomposite="" composite="(AlphaComposite)(g.getComposite());" renderabschnitt="" hintergrund="" malen="" g.setcolor(color.white);="" g.fillrect(0,="" 0,="" 480,="" 530);="" g.setcolor(color.light_gray);="" g.drawrect(0,="" 0,="" 479,="" 529);="" g.setfont(new="" font(font.monospaced,="" font.bold,="" 50));="" for="" (i="0;" i=""></=>< 9;="" i++)="" {="" if="" ((level[81+i]="=" 1)="" ||="" (i="=" 0))="" {="" g.setcolor(red);="" if="" (level[81+i]="=" 1)="" {="" g.fillrect(0="" +="" i="" %="" 3="" *="" 160,="" i="" 3="" *="" 160="" +="" 50,="" 160,="" 160);="" }="" if="" (i="=" 0)="" {="" g.fillrect(2,="" 2,="" 46,="" 46);="" g.setcolor(color.black);="" g.setstroke(strokethick);="" g.drawline(4,="" 5,="" 44,="" 45);="" g.drawline(44,="" 5,="" 4,="" 45);="" g.setstroke(strokethin);="" }="" }="" if="" ((level[81+i]="=" 2)="" ||="" (i="=" 0))="" {="" g.setcolor(blue);="" if="" (level[81+i]="=" 2)="" {="" g.fillrect(0="" +="" i="" %="" 3="" *="" 160,="" i="" 3="" *="" 160="" +="" 50,="" 160,="" 160);="" }="" if="" (i="=" 0)="" {="" g.fillrect(432,="" 2,="" 46,="" 46);="" g.setcolor(color.black);="" g.setstroke(strokethick);="" g.drawoval(434,="" 5,="" 40,="" 40);="" g.setstroke(strokethin);="" }="" }="" if="" (level[81+i]="=" 0)="" {="" for="" (x="0;" x="">< 3;="" x++)="" {="" for="" (y="0;" y="">< 3;="" y++)="" {="" if="" ((level[i*9+y*3+x]=""> 0) || ((x == curX) && (y == curY) && (curTile == i))) { if (level[i*9+y*3+x] == 1) { g.setColor(red); } if (level[i*9+y*3+x] == 2) { g.setColor(blue); } if ((x == curX) && (y == curY) && (curTile == i) && (level[i*9+y*3+x] == 0)) { g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(0.6f))); g.setColor(red); if (turn == 2) { g.setColor(blue); } } g.fillRect(5 + x * 50 + i%3 * 160, 55 + y * 50 + i / 3 * 160, 50, 50); g.setComposite(composite); } } } } } g.setColor(Color.BLACK); for (i = 0; i < 2;="" i++)="" {="" g.fillrect(158="" +="" i="" *="" 160,="" 50,="" 5,="" 479);="" g.fillrect(0,="" 208="" +="" i="" *="" 160,="" 479,="" 5);="" }="" for="" (x="0;" x="">< 3;="" x++)="" {="" for="" (y="0;" y="">< 3;="" y++)="" {="" for="" (i="0;" i="">< 2;="" i++)="" {="" g.fillrect(54="" +="" i="" *="" 50="" +="" x="" *="" 160,="" 55="" +="" y="" *="" 160,="" 2,="" 150);="" g.fillrect(5="" +="" x="" *="" 160,="" 105="" +="" y="" *="" 160="" +="" i="" *="" 50,="" 150,="" 2);="" }="" if="" (((curfield="=" y="" *="" 3="" +="" x)="" ||="" ((curfield="=" -1)="" &&="" (level[81+x+y*3]=""><= 0)))="" &&="" (time=""> 0)) { g.setColor(blue); if (turn == 1) { g.setColor(red); } g.setStroke(strokeThick); g.drawRect(2 + x * 160, 52 + y * 160, 155, 155); g.setColor(Color.BLACK); g.setStroke(strokeThin); } } } for (i = 0; i < 9;="" i++)="" {="" for="" (x="0;" x="">< 3;="" x++)="" {="" for="" (y="0;" y="">< 3;="" y++)="" {="" if="" ((level[i*9+y*3+x]=""> 0) || ((x == curX) && (y == curY) && (curTile == i))) { g.setStroke(strokeThick); if ((x == curX) && (y == curY) && (curTile == i) && (level[i*9+y*3+x] == 0)) { g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(0.6f))); } if ((level[i*9+y*3+x] == 1) || ((x == curX) && (y == curY) && (curTile == i) && (turn == 1))) { g.drawLine(9 + x * 50 + i%3 * 160, 60 + y * 50 + i / 3 * 160, 49 + x * 50 + i%3 * 160, 100 + y * 50 + i / 3 * 160); g.drawLine(49 + x * 50 + i%3 * 160, 60 + y * 50 + i / 3 * 160, 9 + x * 50 + i%3 * 160, 100 + y * 50 + i / 3 * 160); } if ((level[i*9+y*3+x] == 2) || ((x == curX) && (y == curY) && (curTile == i) && (turn == 2))) { g.drawOval(9 + x * 50 + i%3 * 160, 60 + y * 50 + i / 3 * 160, 40, 40); } g.setComposite(composite); g.setStroke(strokeThin); } } } } String s = "TicCeption"; w = g.getFontMetrics().stringWidth(s); g.drawString(s, 240 - w/2, 40); if (state == 0) { g.setFont(g.getFont().deriveFont(25f).deriveFont(1)); s = "The tictactoe game in"; g.setColor(Color.WHITE); w = g.getFontMetrics().stringWidth(s); g.fillRect(240 - w/2 - 10, 90, w + 20, 115); g.setColor(Color.LIGHT_GRAY); g.drawString(s, 240 - w/2, 123); g.setColor(Color.BLACK); g.drawString(s, 240 - 1 - w/2, 122); g.drawRect(240 - w/2 - 10, 90, w + 20, 115); s = "a tictactoe game"; w = g.getFontMetrics().stringWidth(s); g.setColor(Color.LIGHT_GRAY); g.drawString(s, 240 - w/2, 148); g.setColor(Color.BLACK); g.drawString(s, 240 - 1 - w/2, 149); s = "Play with the mouse"; w = g.getFontMetrics().stringWidth(s); g.setColor(Color.LIGHT_GRAY); g.drawString(s, 240 - w/2, 195); g.setColor(Color.BLACK); g.drawString(s, 240 - 1 - w/2, 194); if (winner >= 0) { s = "And the winner is"; if (winner == 0) { s = "It's a draw!"; } w = g.getFontMetrics().stringWidth(s); g.setColor(Color.WHITE); g.fillRect(240 - w/2 - 10, 240, w + 20, 93); g.setColor(Color.BLACK); g.drawRect(240 - w/2 - 10, 240, w + 20, 93); if (winner == 0) { g.drawString(s, 240 - w/2, 290); } if (winner > 0) { g.drawString(s, 240 - w/2, 270); g.setStroke(strokeThick); if (winner == 1) { g.setColor(red); g.drawLine(220, 285, 260, 325); g.drawLine(260, 285, 220, 325); } if (winner == 2) { g.setColor(blue); g.drawOval(220, 285, 40, 40); } g.setStroke(strokeThin); } } s = "Press a mousebutton to start"; w = g.getFontMetrics().stringWidth(s); g.setColor(Color.WHITE); g.fillRect(240 - w/2 - 10, 483, w + 20, 30); g.setColor(Color.LIGHT_GRAY); g.drawString(s, 240 - w/2, 510); g.setColor(Color.BLACK); g.drawRect(240 - w/2 - 10, 483, w + 20, 30); g.drawString(s, 240 - 1 - w/2, 509); } // 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.MOUSE_DOWN: // mouse button pressed this.bMouseClick = true; break; case Event.MOUSE_MOVE: case Event.MOUSE_DRAG: this.mouseX = e.x; this.mouseY = e.y; break; } return false; } }</=></=>