public void DrawSelf(Graphics theGraphics) { if (isFalling) { final = new Rectangle(coordX, coordY, width, height); SolidBrush tempBrush = new SolidBrush(Color.White); theGraphics.FillRectangle(tempBrush, final); theGraphics.DrawString(content, font, tempBrush, contentX, contentY); tempBrush.Dispose(); final = new Rectangle(newcoordX, newcoordY, width, height); tempBrush = new SolidBrush(currentBackgroundColor); theGraphics.FillRectangle(tempBrush, final); tempBrush.Dispose(); if (visible) { tempBrush = new SolidBrush(Color.Aquamarine); } else { tempBrush = new SolidBrush(Color.White); } theGraphics.DrawString(content, font, tempBrush, newcontentX, newcontentY); tempBrush.Dispose(); contentX = newcontentX; contentY = newcontentY; coordX = newcoordX; coordY = newcoordY; } else { final = new Rectangle(coordX, coordY, width, height); GraphicsPath finalVersion = WBButton.Create(final); SolidBrush tempBrush = new SolidBrush(currentBackgroundColor); // theGraphics.FillPath(tempBrush, finalVersion); finalVersion.Dispose(); theGraphics.FillRectangle(tempBrush, final); tempBrush.Dispose(); if (visible) { tempBrush = new SolidBrush(Color.Aquamarine); } else { tempBrush = new SolidBrush(Color.White); } theGraphics.DrawString(content, font, tempBrush, contentX, contentY); tempBrush.Dispose(); } }
//Updates the values for this WBButton by comparing against the last button created public void Initializer(WBButton previousButton, int gridSize) { if (previousButton != null) { if (previousButton.column != gridSize) { coordX = previousButton.coordX + 50; row = previousButton.row; column = previousButton.column + 1; } else { coordX = 40; row = previousButton.row + 1; column = 1; } coordY = (row - 1) * 50 + 40; } else { coordX = 40; coordY = 40; row = 1; column = 1; } contentX = coordX + 13; contentY = coordY + 10; newcontentX = contentX; newcontentY = contentY; newcoordX = coordX; newcoordY = coordY; rowLower = row + 1; return; }
public WBWindow() { // First create the timer timer = new Timer(); timer.Tick += new EventHandler(timer_Tick); timer.Interval = (50) * (1); timer.Enabled = true; timer.Start(); //Creates the initial button WBButton currentButton = new WBButton(); currentButton.Initializer(null, gridSize); buttonList.Add(currentButton); //Creates the remaining buttons for (int i = 0; i < gridSize * gridSize - 1; i++) { currentButton = new WBButton(); currentButton.Initializer(buttonList[i], gridSize); buttonList.Add(currentButton); } //Finds adjacent buttons for each button foreach (WBButton theButton in buttonList) { theButton.FindAdjacent(buttonList); } //Puzzle generation, and quality check string[] puzzleA = firstWord.Split(' '); string[] puzzleB = secondWord.Split(' '); puzzles.Add(puzzleA); puzzles.Add(puzzleB); bool ok = false; bool checka = false; bool checkb = false; //int safety = 0; while (!ok) { for (int i = 0; i < puzzleA.Length; i++) { ok = false; while (!ok) { ok = buttonList[random.Next(9)].ConstructPuzzle(i, puzzleA); } } for (int i = 0; i < puzzleB.Length; i++) { ok = false; while (!ok) { ok = buttonList[random.Next(9)].ConstructPuzzle(i, puzzleB); } } ok = false; foreach (WBButton theButton in buttonList) { if (theButton.content == puzzleA[0]) { if (theButton.PuzzleCheck(0, puzzleA)) { checka = true; } } if (theButton.content == puzzleB[0]) { if (theButton.PuzzleCheck(0, puzzleB)) { checkb = true; } } } //safety++; if (checka && checkb) { ok = true; } else { foreach (WBButton theButton in buttonList) { theButton.Reset(); } checka = false; checkb = false; } } }