Пример #1
0
 public bool BottomLeftExists(Hexagon hex)
 {
     return BottomLeftExists (hex.X, hex.Y);
 }
Пример #2
0
 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);
 }
Пример #3
0
 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);
         }
     }
 }
Пример #4
0
 public Hexagon BottomLeft(Hexagon hex)
 {
     return BottomLeft (hex.X, hex.Y);
 }
Пример #5
0
 public bool TopRightExists(Hexagon hex)
 {
     return TopRightExists (hex.X, hex.Y);
 }
Пример #6
0
        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);
        }
Пример #7
0
 public Hexagon TopLeft(Hexagon hex)
 {
     return TopLeft (hex.X, hex.Y);
 }
Пример #8
0
 public Hexagon TopRight(Hexagon hex)
 {
     return TopRight (hex.X, hex.Y);
 }
Пример #9
0
 public bool LeftExists(Hexagon hex)
 {
     return LeftExists (hex.X, hex.Y);
 }
Пример #10
0
        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 ();
        }
Пример #11
0
        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;
            }
        }
Пример #12
0
        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;
        }
Пример #13
0
        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());
            }
        }
Пример #14
0
 public int GetSurroundingMines(Hexagon hex)
 {
     return GetSurroundingMines (hex.X, hex.Y);
 }
Пример #15
0
 public Hexagon BottomRight(Hexagon hex)
 {
     return BottomRight (hex.X, hex.Y);
 }