private void updateScreen() { //Setting up the canvas every time to allow for dynamic screen width DrawWindow.Width = this.Width - 15; DrawWindow.Height = this.Height - 15; screenWidth = DrawWindow.Width; screenHeight = DrawWindow.Height; sPicture = new Bitmap(screenWidth, screenHeight); sCanvas = Graphics.FromImage(sPicture); canvas = DrawWindow.CreateGraphics(); //Reset the canvas (mainly in case of moving images so its not super important here (I don't like the idea of having thousands of the same square drawn in the same space even though it makes no difference to the code or performance whatsoever) sCanvas.Clear(Color.FromArgb(29, 17, 66)); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; sCanvas.DrawString(attemptsRemaining.ToString(), tFont, tBrush, screenWidth - 60, 60, sf); //Cheaty Cheaty sCanvas.DrawString("Totally not " + word.getWord(), smallTFont, tBrush, 10, 10); //Draw all the stuff int charX = 40; int charY = 80; foreach (char c in attemptedChars) { sCanvas.DrawString(c.ToString(), tFont, tBrush, charX, charY, sf); if (charX >= screenWidth - 180) { charX = 40; charY += 60; } else { charX += 60; } } for (int i = 1; i < word.length() + 1; i++) { letterX[i - 1] = (screenWidth / 2) - ((textWidth + textPadding) * i) + (((textWidth + textPadding) * word.length() / 2) + textPadding / 2); letterY[i - 1] = screenHeight - 50; sCanvas.FillRectangle(tBrush, letterX[i - 1], screenHeight - 50, textWidth, 4); //Draw attempts remaining and the succeeded letters sCanvas.DrawString(buildingChars[word.length() - i].ToString(), tFont, tBrush, letterX[i - 1] + 30, letterY[i - 1] - 30, sf); } if (attemptsRemaining < 10) { try { State = Image.FromFile(@"Assets\Step" + (10 - attemptsRemaining) + ".png"); } catch { } sCanvas.DrawImage(State, screenWidth / 2 - 250, screenHeight / 2 - 350, 500, 500); } canvas.DrawImage(sPicture, 0, 0, screenWidth, screenHeight); }
private void reset() { //Graphics setup screenWidth = DrawWindow.Width; screenHeight = DrawWindow.Height; sPicture = new Bitmap(screenWidth, screenHeight); sCanvas = Graphics.FromImage(sPicture); canvas = DrawWindow.CreateGraphics(); //Word and text recording setup word.PickNew(); textWidth = 60; textPadding = 10; buildingChars = new char[word.length()]; attemptedChars = new List <char>(); attemptsRemaining = 10; //Letter underline X and Y letterX = new int[word.length()]; letterY = new int[word.length()]; updateScreen(); }