Skip to content
Snippets Groups Projects
Commit b7a6477c authored by bionic85's avatar bionic85
Browse files

PlayerController is Finished

parent 07519ff0
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,9 @@ namespace PuzzlePlayer_Namespace
drawFactor = 1;
// init all 2D array's
Reset(size);
lastGeneratedBoard = GetClearBoard(size);
description = "The maze is played on a square grid where each cells has walls. You need to navigate through the maze until you reach the end. Use the arrow keys or WASD to move the blue square to the end goal";
}
private void Reset(int size)
......@@ -52,6 +55,7 @@ namespace PuzzlePlayer_Namespace
boardState = GetClearBoard(size);
mazeState = GetClearBoard(size);
visitedCells = GetClearBoard(size);
playerPos = new Point(0,0);
}
// two funcions to go from number to walls and back
......@@ -112,6 +116,8 @@ namespace PuzzlePlayer_Namespace
// draw the space blue if the player has visited it
if (boardState[i, j] == 1)
gr.FillRectangle(Brushes.Blue, currentRect);
if(i == playerPos.X && j == playerPos.Y)
gr.FillRectangle(Brushes.DarkBlue, currentRect);
// draw board outline
gr.DrawRectangle(Pens.LightGray,currentRect);
......@@ -130,13 +136,8 @@ namespace PuzzlePlayer_Namespace
}
// draw an indication of where the start and end from the maze are
gr.FillRectangle(Brushes.Blue, r.X, r.Y, tilesize.Width, tilesize.Height);
// draw an indication of where the end of the maze is
gr.FillRectangle(Brushes.Red, r.X + tilesize.Width*(boardState.GetLength(0)-1), r.Y + tilesize.Height * (boardState.GetLength(1)-1), tilesize.Width, tilesize.Height);
//gr.DrawString("START", SettingForm.mainFont, Brushes.Red, r.Left, r.Top + tilesize.Height/2);
//gr.DrawString("END", SettingForm.mainFont, Brushes.Red, r.Right - tilesize.Width / 4, r.Bottom - tilesize.Height / 2);
}
// this methode generates a Maze starting with an empty board
......@@ -368,23 +369,28 @@ namespace PuzzlePlayer_Namespace
public override void TileInput(Point? p, Keys key)
{
(bool top, bool right, bool bottom, bool left) = getWallsFromNumber(mazeState[((Point)p).X,((Point)p).Y]);
boardState[playerPos.X, playerPos.Y] = 1; //dw
(bool top, bool right, bool bottom, bool left) = getWallsFromNumber(mazeState[playerPos.X,playerPos.Y]);
switch (key)
{
case Keys.Up | Keys.W:
case Keys.Up:
case Keys.W:
if (!top)
playerPos.Y++;
playerPos.Y--;
break;
case Keys.Down | Keys.S:
case Keys.Down:
case Keys.S:
if (!bottom)
playerPos.Y--;
playerPos.Y++;
break;
case Keys.Right | Keys.D:
case Keys.Right:
case Keys.D:
if (!right)
playerPos.X++;
break;
case Keys.Left | Keys.A:
case Keys.Left:
case Keys.A:
if (!left)
playerPos.X--;
break;
......
......@@ -65,6 +65,7 @@ namespace PuzzlePlayer_Namespace
};
this.Resize += (object o, EventArgs ea) => UpdateUI();
this.Move += (object o, EventArgs ea) => this.Focus();
this.PreviewKeyDown += (object o, PreviewKeyDownEventArgs e) => e.IsInputKey = true;
this.KeyDown += (object o, KeyEventArgs kea) => Input(kea.KeyCode);
this.MouseClick += (object o, MouseEventArgs mea) =>
{
......@@ -177,7 +178,6 @@ namespace PuzzlePlayer_Namespace
solvebutton.Location = new Point(boardspace.Right + 30, 190);
restartbutton.Location = new Point(boardspace.Right + 30, 270);
UPDATEBUTTON.Location = new Point(boardspace.Right + 30, 350);
informationbox.Text = Convert.ToString(boardspace.Size);
this.Invalidate();
}
public static Size FitBoard(Size gamesize, Size maxboardsize, int drawfactor) //returns the largest rectangle smaller than MaxBoardSize that fits the given GameSize well
......@@ -207,7 +207,7 @@ namespace PuzzlePlayer_Namespace
MessageBox.Show("Hint: geef op");
this.Invalidate();
return;
case Keys.S:
case Keys.Space:
Board.Solve(false);
this.Invalidate();
return;
......@@ -215,7 +215,12 @@ namespace PuzzlePlayer_Namespace
case Keys.Left:
case Keys.Right:
case Keys.Down:
case Keys.W:
case Keys.A:
case Keys.S:
case Keys.D:
Board.TileInput(null, k);
this.Invalidate();
return;
}
Point tile = GetTile(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), boardspace, Control.MousePosition);
......
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