Ejemplo n.º 1
0
 private List<Tile> GenerateTiles()
 {
     var tiles = new List<Tile>();
     for (int i = 0; i < 6; i++)
     {
         for (int j = i; j < 6; j++)
         {
             var tile = new Tile(i,j);
             tiles.Add(tile);
         }
     }
     return tiles;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Generate and shuffle tiles
 /// </summary>
 /// <returns></returns>
 public static List<Tile> GenerateTiles()
 {
     var tiles = new List<Tile>();
     for (int i = 0; i <= 6; i++)
     {
         for (int j = i; j <= 6; j++)
         {
             var tile = new Tile(i, j);
             tiles.Add(tile);
         }
     }
     // Shuffle tiles
     var rand = new Random();
     int n = tiles.Count;
     while (n > 1)
     {
         n--;
         int k = rand.Next(n + 1);
         var value = tiles[k];
         tiles[k] = tiles[n];
         tiles[n] = value;
     }
     return tiles;
 }
Ejemplo n.º 3
0
        private Node Go(Tile tile, Node parentNode, Side parentTileSide, List<Tile> tiles)
        {
            var newMove = GameMoves.NewMove(tile, parentNode, parentTileSide);
            tiles.Remove(tile);

            IsPlayerTurn = !IsPlayerTurn;
            movesCount++;
            return newMove;
        }
Ejemplo n.º 4
0
 private void FirstGo(Tile tile, List<Tile> tiles)
 {
     var newMove = GameMoves.FirstMove(tile);
     tiles.Remove(tile);
     IsPlayerTurn = !IsPlayerTurn;
     movesCount++;
 }
Ejemplo n.º 5
0
 public Node PlayerMoves(Tile tile, Node node, Side tileSide)
 {
     if (IsPlayerTurn)
     {
         var n = Go(tile, node, tileSide, PlayerTiles);
         Scoring.CheckGameState(GameMoves, TileBase, PlayerTiles, AiTiles);
         return n;
     }
     else { throw new Exception("Is not player's turn"); }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Add tile to user interface on exact coords
        /// </summary>
        /// <param name="tile">New tile</param>
        /// <param name="point">Point on the table</param>
        public void AddTileToUserBase(Tile tile, Point point)
        {
            TileModel tileModel = new TileModel();
            var node = new Node { CurrentTile = tile };
            tileModel.CurrentNode = node;

            tileModel.Center = point;
            tileModel.MouseDown += TileModel_MouseDown;
            UserBaseTileModels.Add(tileModel);
            _parentGrid.Children.Add(tileModel);
        }
Ejemplo n.º 7
0
 public Node FirstMove(Tile tile)
 {
     var newNode = new Node { CurrentTile = tile };
     root = newNode;
     return newNode;
 }
Ejemplo n.º 8
0
        public Node NewMove(Tile tile, Node parentNode, Side parentTileSide)
        {
            var childNode = new Node { CurrentTile = tile };
            Side childSide = GetMatchSide(parentNode, childNode, parentTileSide);

            parentNode.AddNewNode(childNode, parentTileSide);
            childNode.AddNewNode(parentNode, childSide);
            childNode.ParentNode = parentNode;

            return childNode;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Finds available points to connect new tile
        /// </summary>
        /// <param name="mouse">Current mouse coordinates</param>
        /// <param name="tile">New tile</param>
        private void HelpToConnect(Point mouse, Tile tile)
        {
            if (_gameLogic.IsPlayerTurn)
            {
                //get match free connectors
                var connectors = GetLeavesConnectors(_gameLogic.GameMoves.Leaves).Where(x =>
                x.ParentTileModel.CurrentNode.CurrentTile.GetSideValue(x.ConnectorSide) == tile.TopEnd ||
                x.ParentTileModel.CurrentNode.CurrentTile.GetSideValue(x.ConnectorSide) == tile.BottomEnd).ToList();

                foreach (var item in connectors)
                {
                    var point = item.ConnectorPoint;
                    Background.Children.Add(new Ellipse { Margin = new Thickness(point.X - 4, point.Y - 4, 0, 0), Fill = Brushes.OrangeRed, Width = 8, Height = 8, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left });
                }

                if (connectors.Count > 0)
                {
                    var points = connectors.Select(x => x.ConnectorPoint).ToList();
                    var vectors = points.Select(x => (x - mouse)).ToList(); //Vector from mouse to connector

                    var minLength = points.Select(x => (x - mouse).Length).Min();
                    var minVectors = vectors.Find(x => x.Length == minLength);

                    if (minLength <= 70)
                    {
                        _nearConnector = connectors.Find(x => x.ConnectorPoint == (mouse + minVectors));
                        var point = _nearConnector.ConnectorPoint;
                        var childNode = new Node { CurrentTile = tile };
                        var parentTileSide = _nearConnector.ConnectorSide;
                        var childTileSide = _gameLogic.GameMoves.GetMatchSide(_nearConnector.ParentTileModel.CurrentNode, childNode, parentTileSide);
                        int angle = (2 + _nearConnector.ParentTileModel.Angle - ((int)parentTileSide) + ((int)childTileSide)) % 4;
                        var offset = _newTile.OffsetVector(childTileSide);
                        point.X = point.X - offset.X;
                        point.Y = point.Y - offset.Y;
                        _newTile.Angle = angle;
                        _newTile.Center = point;
                        _newTile.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        _nearConnector = null;
                        _newTile.Visibility = Visibility.Hidden;
                    }
                }
                else
                {
                    _nearConnector = null;
                    _newTile.Visibility = Visibility.Hidden;
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Sets tile dots
        /// </summary>
        /// <param name="tile"></param>
        private void SetTileSideDots(Tile tile)
        {
            dot1_1.Visibility = Visibility.Hidden;
            dot1_2.Visibility = Visibility.Hidden;
            dot1_3.Visibility = Visibility.Hidden;
            dot1_4.Visibility = Visibility.Hidden;
            dot1_5.Visibility = Visibility.Hidden;
            dot1_6.Visibility = Visibility.Hidden;
            dot1_7.Visibility = Visibility.Hidden;
            dot2_1.Visibility = Visibility.Hidden;
            dot2_2.Visibility = Visibility.Hidden;
            dot2_3.Visibility = Visibility.Hidden;
            dot2_4.Visibility = Visibility.Hidden;
            dot2_5.Visibility = Visibility.Hidden;
            dot2_6.Visibility = Visibility.Hidden;
            dot2_7.Visibility = Visibility.Hidden;

            List<string> dots = new List<string>();
            var topValue= tile.TopEnd;
            var bottomValue = tile.BottomEnd;
            switch (topValue)
            {
                case 0:
                    //do nothing
                    break;
                case 1:
                    dot1_7.Visibility = Visibility.Visible;
                    break;
                case 2:
                    dot1_1.Visibility = Visibility.Visible;
                    dot1_6.Visibility = Visibility.Visible;
                    break;
                case 3:
                    dot1_1.Visibility = Visibility.Visible;
                    dot1_7.Visibility = Visibility.Visible;
                    dot1_6.Visibility = Visibility.Visible;
                    break;
                case 4:
                    dot1_1.Visibility = Visibility.Visible;
                    dot1_3.Visibility = Visibility.Visible;
                    dot1_4.Visibility = Visibility.Visible;
                    dot1_6.Visibility = Visibility.Visible;
                    break;
                case 5:
                    dot1_1.Visibility = Visibility.Visible;
                    dot1_3.Visibility = Visibility.Visible;
                    dot1_4.Visibility = Visibility.Visible;
                    dot1_6.Visibility = Visibility.Visible;
                    dot1_7.Visibility = Visibility.Visible;
                    break;
                case 6:
                    dot1_1.Visibility = Visibility.Visible;
                    dot1_2.Visibility = Visibility.Visible;
                    dot1_3.Visibility = Visibility.Visible;
                    dot1_4.Visibility = Visibility.Visible;
                    dot1_5.Visibility = Visibility.Visible;
                    dot1_6.Visibility = Visibility.Visible;
                    break;
            }
            switch (bottomValue)
            {
                case 0:
                    //do nothing
                    break;
                case 1:
                    dot2_7.Visibility = Visibility.Visible;
                    break;
                case 2:
                    dot2_1.Visibility = Visibility.Visible;
                    dot2_6.Visibility = Visibility.Visible;
                    break;
                case 3:
                    dot2_1.Visibility = Visibility.Visible;
                    dot2_7.Visibility = Visibility.Visible;
                    dot2_6.Visibility = Visibility.Visible;
                    break;
                case 4:
                    dot2_1.Visibility = Visibility.Visible;
                    dot2_3.Visibility = Visibility.Visible;
                    dot2_4.Visibility = Visibility.Visible;
                    dot2_6.Visibility = Visibility.Visible;
                    break;
                case 5:
                    dot2_1.Visibility = Visibility.Visible;
                    dot2_3.Visibility = Visibility.Visible;
                    dot2_4.Visibility = Visibility.Visible;
                    dot2_6.Visibility = Visibility.Visible;
                    dot2_7.Visibility = Visibility.Visible;
                    break;
                case 6:
                    dot2_1.Visibility = Visibility.Visible;
                    dot2_2.Visibility = Visibility.Visible;
                    dot2_3.Visibility = Visibility.Visible;
                    dot2_4.Visibility = Visibility.Visible;
                    dot2_5.Visibility = Visibility.Visible;
                    dot2_6.Visibility = Visibility.Visible;
                    break;
            }
        }