public bool BottomLeftExists(Hexagon hex) { return BottomLeftExists (hex.X, hex.Y); }
void DrawHexagon(Hexagon h, Graphics g) { switch (h.State) { case HexagonState.Closed: g.FillPolygon (Brushes.LightGray, HexagonPoints); break; case HexagonState.Marked: g.FillPolygon (Brushes.LightGray, HexagonPoints); DrawMarker (g); break; case HexagonState.Unknown: g.FillPolygon (Brushes.LightGray, HexagonPoints); DrawStringCentered (g, "?", Color.Black); break; case HexagonState.Opened: g.FillPolygon (Brushes.Gray, HexagonPoints); if (h.SurroundingMines > 0) DrawStringCentered (g, h.SurroundingMines.ToString (), GetSurroundingMinesColor ((int)h.SurroundingMines)); break; case HexagonState.OpenedMine: g.FillPolygon (Brushes.Red, HexagonPoints); DrawMine(g); break; case HexagonState.NotMarkedButMine: g.FillPolygon (Brushes.LightGray, HexagonPoints); DrawMine(g); break; case HexagonState.MarkedWrong: g.FillPolygon (Brushes.LightGray, HexagonPoints); DrawMarker(g); var state = g.Save (); DrawCross(g, Brushes.White, true); g.Restore (state); break; } if (h.Hovered) g.FillPolygon (new SolidBrush(Color.FromArgb (45, 255, 255, 30)), HexagonPoints); if (h.Pressed && (h.State == HexagonState.Closed || h.State == HexagonState.Marked || h.State == HexagonState.Unknown)) g.FillPolygon(new SolidBrush(Color.FromArgb (90,0,0,0)), HexagonPoints); g.DrawPolygon (new Pen(Brushes.Black, 2f), HexagonPoints); }
private void OpenHexagonUntilMine_Convenience(Hexagon i) { if (i != null) //null means: Field does not exist { if (!i.IsMine && i.State != HexagonState.Opened) { i.SurroundingMines = GetSurroundingMines (i); //Remove marked mine. Was wrong btw. if (i.State == HexagonState.Marked) MarkedMinesCount++; i.State = HexagonState.Opened; ClosedHexagonsCount--; if (i.SurroundingMines == 0) OpenHexagonsUntilMine (i); } } }
public Hexagon BottomLeft(Hexagon hex) { return BottomLeft (hex.X, hex.Y); }
public bool TopRightExists(Hexagon hex) { return TopRightExists (hex.X, hex.Y); }
private void OpenHexagonsUntilMine(Hexagon h) { //Opens all fields until a mine was found. //Convenience-function removes code-duplication Hexagon i; i = TopLeft (h); OpenHexagonUntilMine_Convenience(i); i = TopRight (h); OpenHexagonUntilMine_Convenience(i); i = Right (h); OpenHexagonUntilMine_Convenience(i); i = BottomRight (h); OpenHexagonUntilMine_Convenience(i); i = BottomLeft (h); OpenHexagonUntilMine_Convenience(i); i = Left (h); OpenHexagonUntilMine_Convenience(i); }
public Hexagon TopLeft(Hexagon hex) { return TopLeft (hex.X, hex.Y); }
public Hexagon TopRight(Hexagon hex) { return TopRight (hex.X, hex.Y); }
public bool LeftExists(Hexagon hex) { return LeftExists (hex.X, hex.Y); }
public void NewGame(int width, int height, int mines) { StopTimer (); CurrentGameState = GameState.PlacingMines; Width = width; Height = height; MinesCount = mines; ClosedHexagonsCount = width * height; MarkedMinesCount = 0; Hexagons = new Hexagon[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Hexagons[x, y] = new Hexagon(x, y); } } Thread PlaceMinesThread = new Thread(PlaceMines); PlaceMinesThread.Start (); }
public void HexagonRightClick(Hexagon h) { if (h.State == HexagonState.Opened || CurrentGameState != GameState.Running) return; StartTimer (); //Other cases only happen when game has ended switch (h.State) { case HexagonState.Opened: return; case HexagonState.Closed: h.State = HexagonState.Marked; MarkedMinesCount++; return; case HexagonState.Marked: h.State = HexagonState.Unknown; MarkedMinesCount--; return; case HexagonState.Unknown: h.State = HexagonState.Closed; return; } }
public void HexagonHover(Hexagon h) { //Might be slow with big fields. Change implementation somehow? for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { Hexagons[x, y].Hovered = false; } } if (h == null) return; h.Hovered = true; Hexagon i; i = TopLeft (h); if (i != null) i.Hovered = true; i = TopRight (h); if (i != null) i.Hovered = true; i = Right (h); if (i != null) i.Hovered = true; i = BottomRight (h); if (i != null) i.Hovered = true; i = BottomLeft (h); if (i != null) i.Hovered = true; i = Left (h); if (i != null) i.Hovered = true; }
public void HexagonClick(Hexagon h) { if (CurrentGameState != GameState.Running) return; StartTimer (); //Don't open already open fields and ignore clicks that happened by accident if (h.State == HexagonState.Marked || h.State == HexagonState.Unknown || h.State == HexagonState.Opened) return; h.State = HexagonState.Opened; ClosedHexagonsCount--; if (h.IsMine) { StopTimer (); h.State = HexagonState.OpenedMine; CurrentGameState = GameState.Lost; RevealMines (); if (GameLost != null) GameLost(this, new EventArgs()); return; } h.SurroundingMines = GetSurroundingMines (h); if (h.SurroundingMines == 0) { //Open all empty fields recursively... OpenHexagonsUntilMine (h); } //Player won the game if (ClosedHexagonsCount == MinesCount) { StopTimer (); CurrentGameState = GameState.Won; if (GameWon != null) GameWon(this, new EventArgs()); } }
public int GetSurroundingMines(Hexagon hex) { return GetSurroundingMines (hex.X, hex.Y); }
public Hexagon BottomRight(Hexagon hex) { return BottomRight (hex.X, hex.Y); }