Example #1
0
 public SkullToken(Board board, int row, int column)
 {
     piece = new TokenPiece[1];
     Cell cell = new Cell();
     cell.color = CellColor.SKULL;
     piece[0] = new TokenPiece(board, row, column, cell);
 }
Example #2
0
 public TokenPiece(Board board, int row, int column, Cell cell)
 {
     this.board = board;
     this.row = row;
     this.column = column;
     this.cell = cell;
 }
Example #3
0
 public BombToken(Board board, int row, int column)
 {
     piece = new TokenPiece[1];
     Cell cell = new Cell();
     cell.color = CellColor.BOMB;
     piece[0] = new TokenPiece(board, row, column, cell);
 }
Example #4
0
 public Cell(Cell other)
 {
     this.color = other.color;
     this.locked = other.locked;
     this.loose = other.loose;
     this.matched = other.matched;
     this.visited = other.visited;
 }
Example #5
0
        public Board()
        {
            rowOffset = 0;
            columnOffset = 0;

            entries = new Cell[Constants.ROWS, Constants.COLUMNS];
            for (int i = 0; i < Constants.ROWS; i++) {
                for (int j = 0; j < Constants.COLUMNS; j++) {
                    entries[i, j] = new Cell();
                }
            }
        }
Example #6
0
 public TwoPieceToken(Board board, int row, int column, CellColor color1, CellColor color2)
 {
     piece = new TokenPiece[2];
     Cell cell1 = new Cell();
     Cell cell2 = new Cell();
     cell1.color = color1;
     cell2.color = color2;
     cell1.direction = Cell.Direction.RIGHT;
     cell2.direction = Cell.Direction.LEFT;
     piece[0] = new TokenPiece(board, row, column, cell1);
     piece[1] = new TokenPiece(board, row, column + 1, cell2);
     orientation = 0;
 }
 public ThreePieceElbowToken(Board board, int row, int column, CellColor color1, CellColor color2, CellColor color3)
 {
     piece = new TokenPiece[3];
     Cell cell1 = new Cell();
     Cell cell2 = new Cell();
     Cell cell3 = new Cell();
     cell1.color = color1;
     cell2.color = color2;
     cell3.color = color3;
     cell1.direction = Cell.Direction.RIGHT;
     cell2.direction = Cell.Direction.LEFT | Cell.Direction.DOWN;
     cell3.direction = Cell.Direction.UP;
     piece[0] = new TokenPiece(board, row, column, cell1);
     piece[1] = new TokenPiece(board, row, column + 1, cell2);
     piece[2] = new TokenPiece(board, row + 1, column + 1, cell3);
     orientation = 0;
 }
Example #8
0
        public void DrawCell(Cell cell, CellColor color, Rectangle targetRect, SpriteBatch spriteBatch)
        {
            int x = 0;
            int y = 0;
            switch (cell.direction) {
                case Cell.Direction.DOWN | Cell.Direction.RIGHT: { x = 0; y = 0; break; }
                case Cell.Direction.UP | Cell.Direction.DOWN | Cell.Direction.RIGHT: { x = 0; y = 2; break; }
                case Cell.Direction.UP | Cell.Direction.RIGHT: { x = 0; y = 4; break; }
                case Cell.Direction.DOWN | Cell.Direction.LEFT | Cell.Direction.RIGHT: { x = 2; y = 0; break; }
                case Cell.Direction.UP | Cell.Direction.LEFT | Cell.Direction.DOWN | Cell.Direction.RIGHT: { x = 2; y = 2; break; }
                case Cell.Direction.UP | Cell.Direction.LEFT | Cell.Direction.RIGHT: { x = 2; y = 4; break; }
                case Cell.Direction.DOWN | Cell.Direction.LEFT: { x = 4; y = 0; break; }
                case Cell.Direction.UP | Cell.Direction.LEFT | Cell.Direction.DOWN: { x = 4; y = 2; break; }
                case Cell.Direction.UP | Cell.Direction.LEFT: { x = 4; y = 4; break; }

                case Cell.Direction.RIGHT: { x = 6; y = 0; break; }
                case Cell.Direction.RIGHT | Cell.Direction.LEFT: { x = 7; y = 0; break; }
                case Cell.Direction.LEFT: { x = 8; y = 0; break; }

                case Cell.Direction.DOWN: { x = 10; y = 0; break; }
                case Cell.Direction.UP | Cell.Direction.DOWN: { x = 10; y = 1; break; }
                case Cell.Direction.UP: { x = 10; y = 2; break; }

                case Cell.Direction.NONE: { x = 6; y = 2; break; }
            }
            if (cell.locked) {
                x = 8;
                y = 2;
            }
            x *= 65;
            y *= 65;

            Color highlight = (cell.matched ? Color.Gray : Color.White);

            Rectangle sourceRect;
            sourceRect.X = x;
            sourceRect.Y = y;
            sourceRect.Width = 64;
            sourceRect.Height = 64;

            spriteBatch.Draw(colorTextures[color].GetTexture(), targetRect, sourceRect, highlight);
        }
Example #9
0
        public void DrawCell(Cell cell, Rectangle targetRect, SpriteBatch spriteBatch)
        {
            if (cell.color == CellColor.BLACK) {
                return;
            }

            if (cell.color == CellColor.BOMB) {
                DrawCell(cell, CellColor.RED, targetRect, spriteBatch);
                spriteBatch.Draw(textures[SpriteHook.BOMB].GetTexture(), targetRect, Color.White);
                return;
            }

            if (cell.color == CellColor.SKULL) {
                DrawCell(cell, CellColor.PURPLE, targetRect, spriteBatch);
                spriteBatch.Draw(textures[SpriteHook.SKULL].GetTexture(), targetRect, Color.White);
                return;
            }

            DrawCell(cell, cell.color, targetRect, spriteBatch);
        }
Example #10
0
 public FourPieceZToken(Board board, int row, int column, CellColor color1, CellColor color2, CellColor color3, CellColor color4)
 {
     piece = new TokenPiece[4];
     Cell cell1 = new Cell();
     Cell cell2 = new Cell();
     Cell cell3 = new Cell();
     Cell cell4 = new Cell();
     cell1.color = color1;
     cell2.color = color2;
     cell3.color = color3;
     cell4.color = color4;
     cell1.direction = Cell.Direction.RIGHT;
     cell2.direction = Cell.Direction.LEFT | Cell.Direction.DOWN;
     cell3.direction = Cell.Direction.UP | Cell.Direction.RIGHT;
     cell4.direction = Cell.Direction.LEFT;
     piece[0] = new TokenPiece(board, row, column, cell1);
     piece[1] = new TokenPiece(board, row, column + 1, cell2);
     piece[2] = new TokenPiece(board, row + 1, column + 1, cell3);
     piece[3] = new TokenPiece(board, row + 1, column + 2, cell4);
     orientation = 0;
 }
Example #11
0
 public void Draw(Rectangle rect, bool focused, SpriteBatch spriteBatch)
 {
     if (focused) {
         Global.Sprites.DrawLayer(SpriteHook.SCREEN_80_LAYER, rect, spriteBatch);
     }
     int x = rect.Left;
     int y = rect.Top + 10;
     for (int i = 0; i < items.Count; ++i) {
         MenuItem item = items[i];
         Rectangle itemRect;
         itemRect.X = x + 55;
         itemRect.Y = y;
         itemRect.Width = rect.Width - 55;
         itemRect.Height = 30;
         item.Draw(itemRect, spriteBatch);
         if (i == selected) {
             Cell cell = new Cell();
             cell.color = focused ? CellColor.ORANGE : CellColor.ORANGE;
             Rectangle cellRect;
             cellRect.X = x + 28;
             cellRect.Y = y + 4;
             cellRect.Width = (Constants.CELL_SIZE * 2) / 3;
             cellRect.Height = (Constants.CELL_SIZE * 2) / 3;
             Global.Sprites.DrawCell(cell, cellRect, spriteBatch);
         }
         if (!item.IsEnabled()) {
             itemRect.X = x;
             itemRect.Width = rect.Width;
             Global.Sprites.DrawLayer(SpriteHook.SCREEN_80_LAYER, itemRect, spriteBatch);
         }
         y += 30;
     }
     if (!focused) {
         Global.Sprites.DrawLayer(SpriteHook.SCREEN_80_LAYER, rect, spriteBatch);
     }
 }
Example #12
0
 public Value Shuffle(Random random)
 {
     if (type != Type.PATTERN) {
         throw new Exception("Tried to shuffle an integer.");
     }
     List<Cell> pattern = new List<Cell>(patternValue.Count);
     for (int j = 0; j < patternValue.Count; ++j) {
         pattern.Add(patternValue[j]);
     }
     for (int i = 0; i < pattern.Count - 1; ++i) {
         int other = random.Next(i, pattern.Count);
         Cell temp = pattern[i];
         pattern[i] = new Cell(pattern[other]);
         pattern[other] = new Cell(temp);
     }
     return new Value(pattern);
 }
Example #13
0
 public Value Add(Value other)
 {
     if (type == Type.INT && other.type == Type.INT) {
         return new Value(intValue + other.intValue);
     } else if (type == Type.PATTERN && other.type == Type.PATTERN) {
         List<Cell> pattern = new List<Cell>(patternValue.Count + other.patternValue.Count);
         for (int i = 0; i < patternValue.Count; ++i) {
             Cell cell = new Cell();
             cell.color = patternValue[i].color;
             cell.locked = patternValue[i].locked;
             pattern.Add(cell);
         }
         for (int i = 0; i < other.patternValue.Count; ++i) {
             Cell cell = new Cell();
             cell.color = other.patternValue[i].color;
             cell.locked = other.patternValue[i].locked;
             pattern.Add(cell);
         }
         return new Value(pattern);
     } else {
         throw new Exception("Invalid addition: " + type + " + " + other.type);
     }
 }
Example #14
0
 public Value(CellColor color)
 {
     patternValue = new List<Cell>();
     Cell cell = new Cell();
     cell.color = color;
     cell.locked = true;
     patternValue.Add(cell);
     type = Type.PATTERN;
 }
Example #15
0
 public void SetCell(int row, int column, Cell cell)
 {
     while (row < 0)
         row += Constants.ROWS;
     while (column < 0)
         column += Constants.COLUMNS;
     entries[(row + rowOffset) % Constants.ROWS, (column + columnOffset) % Constants.COLUMNS].color = cell.color;
     entries[(row + rowOffset) % Constants.ROWS, (column + columnOffset) % Constants.COLUMNS].direction = cell.direction;
 }
Example #16
0
        public void Draw(GraphicsDevice device, SpriteBatch spriteBatch)
        {
            device.Clear(Color.Black);

            // Determine the board position.
            Rectangle boardRect = new Rectangle();
            if (player == PlayerIndex.One) {
                boardRect.X = Constants.BOARD_ONE_RECT_X;
            } else {
                boardRect.X = Constants.BOARD_TWO_RECT_X;
            }
            boardRect.Y = Constants.BOARD_RECT_Y;
            boardRect.Width = Constants.COLUMNS * Constants.CELL_SIZE;
            boardRect.Height = Constants.ROWS * Constants.CELL_SIZE;
            Sprites.DrawLayer(SpriteHook.SCREEN_80_LAYER, boardRect, spriteBatch);

            // Determine where to draw the help.
            if (singlePlayer) {
                Rectangle helpRect = new Rectangle();
                helpRect.X = Constants.BOARD_TWO_RECT_X - Constants.CELL_SIZE;
                helpRect.Y = Constants.BOARD_RECT_Y;
                helpRect.Width = (2 + Constants.COLUMNS) * Constants.CELL_SIZE;
                helpRect.Height = (Constants.ROWS + 1) * Constants.CELL_SIZE;
                Vector2 topLeft = new Vector2(helpRect.X + Constants.CELL_SIZE, helpRect.Y + Constants.CELL_SIZE);
                Sprites.DrawText(level.GetHelp(), Color.Cyan, topLeft, spriteBatch);
            }

            // Draw the stripe where the piece will be.
            Rectangle stripe;
            stripe.X = boardRect.X + Constants.CELL_SIZE * Constants.TOKEN_START_COLUMN;
            stripe.Y = boardRect.Y;
            stripe.Width = Constants.CELL_SIZE * 2;
            stripe.Height = boardRect.Height;
            Sprites.DrawLayer(SpriteHook.CLOUD_LAYER, stripe, spriteBatch);
            Sprites.DrawLayer(SpriteHook.CLOUD_LAYER, stripe, spriteBatch);
            Sprites.DrawLayer(SpriteHook.SCREEN_80_LAYER, stripe, spriteBatch);

            // Draw the board.
            board.DrawRect(boardRect, spriteBatch);

            // Draw the border around the board.
            {
                // sides.
                for (int row = 0; row < Constants.ROWS; ++row) {
                    Cell side = new Cell();
                    side.color = CellColor.WHITE;
                    side.direction = (row == 0) ? Cell.Direction.DOWN : (Cell.Direction.UP | Cell.Direction.DOWN);
                    side.DrawRect(Board.GetCellPosition(boardRect, row, -1), spriteBatch);
                    side.DrawRect(Board.GetCellPosition(boardRect, row, Constants.COLUMNS), spriteBatch);
                }
                // top and bottom.
                for (int column = 0; column < Constants.COLUMNS; ++column) {
                    Cell bottom = new Cell();
                    bottom.color = CellColor.WHITE;
                    bottom.direction = Cell.Direction.LEFT | Cell.Direction.RIGHT;
                    // bottom.DrawRect(Board.GetCellPosition(boardRect, -1, column), spriteBatch);
                    bottom.DrawRect(Board.GetCellPosition(boardRect, Constants.ROWS, column), spriteBatch);
                }
                Cell cell = new Cell();
                cell.color = CellColor.WHITE;
                // bottom left.
                cell.direction = Cell.Direction.UP | Cell.Direction.RIGHT;
                cell.DrawRect(Board.GetCellPosition(boardRect, Constants.ROWS, -1), spriteBatch);
                // bottom right.
                cell.direction = Cell.Direction.UP | Cell.Direction.LEFT;
                cell.DrawRect(Board.GetCellPosition(boardRect, Constants.ROWS, Constants.COLUMNS), spriteBatch);
                // top right.
                // cell.direction = Cell.Direction.LEFT | Cell.Direction.DOWN;
                // cell.DrawRect(Board.GetCellPosition(boardRect, -1, Constants.COLUMNS), spriteBatch);
                // top left.
                // cell.direction = Cell.Direction.RIGHT | Cell.Direction.DOWN;
                // cell.DrawRect(Board.GetCellPosition(boardRect, -1, -1), spriteBatch);
            }

            // Draw the token in play.
            if (tokenGenerator.GetCurrentToken() != null) {
                tokenGenerator.GetCurrentToken().DrawRect(boardRect, spriteBatch);
            }

            // Draw the winner/loser state.
            if (state == State.WON) {
                wonMenu.Draw(boardRect, true, spriteBatch);
                Sprites.DrawCentered(SpriteHook.WINNER, boardRect, spriteBatch);
            } else if (state == State.FAILED) {
                Sprites.DrawLayer(SpriteHook.SPLATTER_LAYER, boardRect, spriteBatch);
                if (singlePlayer) {
                    failedMenu.Draw(boardRect, true, spriteBatch);
                }
                Sprites.DrawCentered(SpriteHook.LOSER, boardRect, spriteBatch);
            }

            // Draw the next token.
            Rectangle nextRect = new Rectangle();
            int nextTokenEndX = boardRect.X + (boardRect.Width / Constants.COLUMNS) * Constants.TOKEN_START_COLUMN;
            int nextTokenStartX = nextTokenEndX - 200;
            nextRect.X = (int)(nextTokenStartX + (nextTokenEndX - nextTokenStartX) * nextTokenReadiness);
            nextRect.Y = boardRect.Y - (boardRect.Height / Constants.ROWS);
            nextRect.Width = boardRect.Width;
            nextRect.Height = boardRect.Height;
            tokenGenerator.Draw(nextRect, spriteBatch);

            // Draw the remaining locked count.
            Rectangle remainingRect = new Rectangle();
            remainingRect.X = boardRect.X - Constants.CELL_SIZE * 4;
            remainingRect.Y = nextRect.Y + Constants.CELL_SIZE * 2;
            remainingRect.Width = Constants.CELL_SIZE * 3;
            remainingRect.Height = Constants.CELL_SIZE * 2;
            Sprites.DrawNumberCentered(board.GetLockedCount(), remainingRect, spriteBatch);

            // Draw the dumps.
            Rectangle dumpRect = new Rectangle();
            dumpRect.X = boardRect.X;
            dumpRect.Y = boardRect.Y - (boardRect.Height / Constants.ROWS);
            dumpRect.Width = (boardRect.Width / Constants.COLUMNS);
            dumpRect.Height = (boardRect.Height / Constants.ROWS);
            for (int i = 0; i < Constants.COLUMNS; ++i) {
                if (dumps[i] != CellColor.BLACK) {
                    Cell piece = new Cell();
                    piece.color = dumps[i];
                    piece.DrawRect(dumpRect, spriteBatch);
                }
                dumpRect.X += (boardRect.Width / Constants.COLUMNS);
            }

            // Draw the paused overlay.
            if (paused || otherPaused) {
                Sprites.DrawLayer(SpriteHook.SCREEN_80_LAYER, boardRect, spriteBatch);
            }
            if (paused) {
                pauseMenu.Draw(boardRect, true, spriteBatch);
            }
        }