public void initializePuzzle(int level, Graphics g) { this.level = level; mapBuilder = new MapBuilder(level); int[,] map = mapBuilder.getMapArray(); mapSprite = new MapSprite(level, g); // init MapSprite pieces = mapBuilder.getInventoryPuzzlePieces(); // init pieces hints = mapBuilder.getHint(); // init hints stopwatch.Start(); numberOfMoves = 0; boardHeight = 5; boardWidth = 11; currentHint = 1; }
public void fillCanvas() { circle.X = 0; circle.Y = 0; for (int i = 0; i < 11; i++) { for (int j = 0; j < 5; j++) { arr[j, i] = 0; } } for (int i = 0; i < 11; i++) { for (int j = 0; j < 5; j++) { arr[j, i] = lMap.getMapArray()[j, i]; } } pieces = lMap.getMapPuzzlePieces(); foreach (PuzzlePiece item in pieces) { Sprite2 sprite = new Sprite2(item.getLocX(), item.getLocY(), 60, item); sprite.draw(gObject); } /* foreach (PuzzlePiece item in pieces) * { * Console.WriteLine(item.getLocX()); * circle.X = item.getLocX(); * circle.Y = item.getLocY(); * bool[,] pieceArray = item.getPieceArray(); * int s = 0; * * for (int i = 0; i < 4; i++) * { * for (int j = 0; j < 4; j++) * { * if (pieceArray[i, j]) * { * * gp.AddEllipse(circle); * locXa[s] = circle.X; * locYa[s] = circle.Y; * * s++; * } * circle.X += 60; * } * circle.X -= 240; * circle.Y += 60; * } * * * gObject.DrawPath(item.getColor(), gp); * * gObject.FillPath(item.getBrush(), gp); * }*/ /* int count11 = 0; * int count9 = 0; * PuzzlePiece piece = null; * for (int i = 0; i < 11; i++) * { * circle.Y = 0; * circle.X = (i) * 60; * for (int j = 0; j < 5; j++) * { * * if (arr[j, i] == 11 && count11 == 0) * { * circle.Y = (j) * 60; * piece = new PuzzlePiece(11, 11, false); * Sprite2 sprite = new Sprite2(circle.X, circle.Y,60,piece); * sprite.drawing(gp); * count11++; * * /*PuzzlePiece piece = new PuzzlePiece(11,11,false); * gObject.DrawPath(piece.getColor(),gp); * gObject.FillPath(piece.getBrush(), gp);*/ // pieces.Add(piece); /* gObject.DrawEllipse(pink, circle); * gObject.FillEllipse(fillpink, circle); * * * } * else if (arr[j, i] == 9 &&count9 == 0) * { * circle.Y = (j) * 60; * piece = new PuzzlePiece(9, 9, false); * Sprite2 sprite = new Sprite2(circle.X, circle.Y, 60, piece); * sprite.drawing(gp); * count9++; * /*circle.Y = (j) * 60; * PuzzlePiece piece = new PuzzlePiece(9, 9, false); * Sprite2 sprite = new Sprite2(circle.X, circle.Y, 60, piece); * sprite.draw(gObject);*/ /* circle.Y = (j) * 60; * gObject.DrawEllipse(blue, circle); * gObject.FillEllipse(fillblue, circle); * * } * else if (arr[j, i] == 7) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(yellow, circle); * gObject.FillEllipse(fillyellow, circle); * * } * else if (arr[j, i] == 8) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(orange, circle); * gObject.FillEllipse(fillorange, circle); * * } * else if (arr[j, i] == 4) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(green, circle); * gObject.FillEllipse(fillgreen, circle); * * } * else if (arr[j, i] == 1) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(skyblue, circle); * gObject.FillEllipse(fillskyblue, circle); * * } * else if (arr[j, i] == 10) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(violet, circle); * gObject.FillEllipse(fillviolet, circle); * * } * else if (arr[j, i] == 3) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(darkblue, circle); * gObject.FillEllipse(filldarkblue, circle); * * } * else if (arr[j, i] == 2) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(darkred, circle); * gObject.FillEllipse(filldarkred, circle); * * } * else if (arr[j, i] == 5) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(red, circle); * gObject.FillEllipse(fillred, circle); * * } * else if (arr[j, i] == 6) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(lightgreen, circle); * gObject.FillEllipse(filllightgreen, circle); * * } * else if (arr[j, i] == 12) * { * circle.Y = (j) * 60; * gObject.DrawEllipse(turquoise, circle); * gObject.FillEllipse(fillturquoise, circle); * * } * else * { * * } * * } * * * } * circle.X = 0; * circle.Y = 0; * gObject.DrawPath(piece.getColor(),gp); * gObject.FillPath(piece.getBrush(),gp);*/ SendToBack(); }
private void panel1_MouseUp(object sender, MouseEventArgs e) { bool allAvailable = true; bool done = false; MapBuilder mapa = new MapBuilder(level); int[,] arrr = mapa.getMapArray(); if (selectedPiece < length) { int d = (sprite1[selectedPiece].getLocX()) / 60; int f = (sprite1[selectedPiece].getLocY()) / 60; int x1 = (int)d; int y1 = (int)f; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (sprite1[selectedPiece].pieceArray[i, j] && f < 5 && d < 11) { if (arrr[f, d] == -1) { allAvailable = true; } else { allAvailable = false; break; } if (!allAvailable) { break; } } d++; } d = d - 4; if (!allAvailable) { break; } f++; } if (!allAvailable && selectedPiece < length) { sprite1[selectedPiece].setLocX(locXarray[selectedPiece]); sprite1[selectedPiece].setLocY(locYarray[selectedPiece]); } else { sprite1[selectedPiece].setLocX(x1 * 60); sprite1[selectedPiece].setLocY(y1 * 60); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (sprite1[selectedPiece].pieceArray[j, i] && (x1 + i) < 11 && (y1 + j) < 5) { spriteMap2.arr[(y1 + j), (x1 + i)] = sprite1[selectedPiece].ID; } } } if (e.X > 660 || e.Y > 300) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 11; j++) { if (spriteMap2.arr[i, j] == sprite1[selectedPiece].ID) { spriteMap2.arr[i, j] = -1; } } } } } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 11; j++) { Console.Write(" | " + spriteMap2.arr[i, j]); } Console.WriteLine(); } if (selectedPiece < length) { Region rgn = new Region(sprite1[selectedPiece].gp); rgn.Union(sprite1[selectedPiece].gp); Invalidate(rgn, false); panel1.Invalidate(); sprite1[selectedPiece].draw(g); } dragging = false; if (isGameOver(spriteMap2.arr)) { int nLevel = level++; string s = label1.Text + " : " + label2.Text + " : " + label3.Text; GameOver gOver = new GameOver(nLevel, s); gOver.Show(); this.Hide(); } }