Skip to content
Snippets Groups Projects
Commit f90b4dda authored by Floris's avatar Floris
Browse files

update

parent 95f523a2
No related branches found
Tags v1.32.3
No related merge requests found
...@@ -30,12 +30,13 @@ namespace PuzzlePlayer_Namespace ...@@ -30,12 +30,13 @@ namespace PuzzlePlayer_Namespace
public override void Draw (Graphics gr, Rectangle r) //draws board in rectangle R. warning: will stretch image unless FitBoard() is used for rectangle size public override void Draw (Graphics gr, Rectangle r) //draws board in rectangle R. warning: will stretch image unless FitBoard() is used for rectangle size
{ {
Size tilesize = new Size(r.Width / boardState.GetLength(0), r.Height / boardState.GetLength(1)); Size tilesize = new Size(r.Width / boardState.GetLength(0), r.Height / boardState.GetLength(1));
gr.FillRectangle(Brushes.Gainsboro, r.X, r.Y, tilesize.Width*boardState.GetLength(0), tilesize.Height*boardState.GetLength(1)); Pen border = new Pen(Color.Black, 2);
gr.FillRectangle(Brushes.Beige, r.X, r.Y, tilesize.Width*boardState.GetLength(0), tilesize.Height*boardState.GetLength(1));
for (int i = 0; i < boardState.GetLength(0); i++) for (int i = 0; i < boardState.GetLength(0); i++)
{ {
for(int j = 0; j < boardState.GetLength(1); j++) for(int j = 0; j < boardState.GetLength(1); j++)
{ {
gr.DrawRectangle(Pens.Black, gr.DrawRectangle(Pens.LightGray,
r.X+i* tilesize.Width, r.X+i* tilesize.Width,
r.Y+j* tilesize.Height, r.Y+j* tilesize.Height,
tilesize.Width, tilesize.Width,
...@@ -47,6 +48,11 @@ namespace PuzzlePlayer_Namespace ...@@ -47,6 +48,11 @@ namespace PuzzlePlayer_Namespace
(int)(r.Y + ((double)j + 0.125) * tilesize.Height), (int)(r.Y + ((double)j + 0.125) * tilesize.Height),
tilesize.Width * 3 / 4, tilesize.Width * 3 / 4,
tilesize.Height * 3 / 4); tilesize.Height * 3 / 4);
gr.DrawEllipse(border,
(int)(r.X + ((double)i + 0.125) * tilesize.Width + border.Width/2),
(int)(r.Y + ((double)j + 0.125) * tilesize.Height + border.Width/2),
tilesize.Width * 3 / 4 - border.Width,
tilesize.Height * 3 / 4 - border.Width);
} }
if (boardState[i, j] == 1) if (boardState[i, j] == 1)
{ {
......
...@@ -31,10 +31,11 @@ namespace PuzzlePlayer_Namespace ...@@ -31,10 +31,11 @@ namespace PuzzlePlayer_Namespace
public PuzzleForm(Board b = null, Size s = default(Size)) //Takes Board and Size parameter and sets up the PuzzleForm window. public PuzzleForm(Board b = null, Size s = default(Size)) //Takes Board and Size parameter and sets up the PuzzleForm window.
{ {
if (s == default(Size)) s = new Size(800, 500); if (s == default(Size)) s = new Size(700, 420);
this.Size = s; this.Size = this.MinimumSize = s;
this.WindowState = FormWindowState.Maximized; this.WindowState = FormWindowState.Maximized;
this.BackColor = Color.Beige; this.BackColor = Color.DarkGreen;
this.Text = "top text";
graphics = this.CreateGraphics(); graphics = this.CreateGraphics();
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
generatebutton = new Button(); generatebutton = new Button();
...@@ -44,19 +45,17 @@ namespace PuzzlePlayer_Namespace ...@@ -44,19 +45,17 @@ namespace PuzzlePlayer_Namespace
boardspace = new Rectangle(220, 30, 400, 400); boardspace = new Rectangle(220, 30, 400, 400);
this.Paint += (object o, PaintEventArgs pea) => this.Paint += (object o, PaintEventArgs pea) =>
{ {
graphics.Clear(this.BackColor);
board.Draw(graphics, boardspace); board.Draw(graphics, boardspace);
//graphics.FillRectangle(Brushes.LightCoral, 220, 30, this.Width - 400, this.Height - 100); //graphics.FillRectangle(Brushes.LightCoral, 220, 30, this.Width - 380, this.Height - 100);
//graphics.FillRectangle(Brushes.DarkRed, 220, 30, boardspace.Width*Board.boardState.GetLength(0), boardspace.Height * Board.boardState.GetLength(1)); //graphics.FillRectangle(Brushes.DarkRed, boardspace);
}; };
this.Resize += (object o, EventArgs ea) => UpdateUI(); this.Resize += (object o, EventArgs ea) => UpdateUI();
Board = b; Board = b;
CreateUI(); CreateUI();
UpdateUI();
Board.boardState[1, 1] = 1; Board.boardState[1, 1] = 1;
Board.boardState[2, 2] = 0; Board.boardState[2, 2] = 0;
} }
private void CreateUI() private void CreateUI() //sets up ui elements
{ {
void CreateButton(Button b) void CreateButton(Button b)
{ {
...@@ -87,26 +86,33 @@ namespace PuzzlePlayer_Namespace ...@@ -87,26 +86,33 @@ namespace PuzzlePlayer_Namespace
Controls.Add(informationbox); Controls.Add(informationbox);
informationbox.Multiline = true; informationbox.Multiline = true;
informationbox.Size = new Size(160, 400); informationbox.Size = new Size(160, 300);
informationbox.BackColor = Color.LightGray; informationbox.BackColor = Color.LightGray;
informationbox.Text = board.description; informationbox.Text = board.description;
informationbox.Font = new Font("Verdana", 10);
UpdateUI();
} }
private void UpdateUI() private void UpdateUI() //resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size
{ {
boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0),Board.boardState.GetLength(1)),new Size(this.Width - 400, this.Height - 100),8); graphics.Clear(this.BackColor);
boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0),Board.boardState.GetLength(1)),new Size(this.Width - 380, this.Height - 100),8);
generatebutton.Location = new Point(boardspace.Right + 30, 30); generatebutton.Location = new Point(boardspace.Right + 30, 30);
hintbutton.Location = new Point(boardspace.Right + 30, 130); hintbutton.Location = new Point(boardspace.Right + 30, 130);
solvebutton.Location = new Point(boardspace.Right + 30, 230); solvebutton.Location = new Point(boardspace.Right + 30, 230);
informationbox.Location = new Point(40, 30); informationbox.Location = new Point(40, 30);
this.Invalidate(); this.Invalidate();
} }
public static Size FitBoard(Size gamesize, Size maxboardsize, int drawfactor) public static Size FitBoard(Size gamesize, Size maxboardsize, int drawfactor) //returns the largest rectangle smaller than MaxBoardSize that fits the given GameSize well
{ {
int TileLength = Math.Min(maxboardsize.Width / gamesize.Width, maxboardsize.Height / gamesize.Height)/drawfactor*drawfactor; int TileLength = Math.Min(maxboardsize.Width / gamesize.Width, maxboardsize.Height / gamesize.Height) / drawfactor * drawfactor;
return new Size(gamesize.Width*TileLength, gamesize.Height*TileLength); return new Size(gamesize.Width*TileLength, gamesize.Height*TileLength);
//After each of the divisions in this method, the value should be rounded down, //After each of the divisions in this method, the value should be rounded down,
//as the end value cannot exceed the size given by maxboardsize. //as the end value cannot exceed the size given by maxboardsize.
//however, C# rounds divisions of Int values down by default, so this does not have to be explicitly done. //however, C# rounds divisions of Int values down by default, so this does not have to be explicitly done.
} }
public static Point GetTile(Point p)
{
return p;
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment