Exemplo n.º 1
0
    /**
     * Obtain the victory points for a player, given their ID.
     */
    public int GetVictoryPointsForPlayerId(string id)
    {
        BoardGrid boardGrid     = GetComponent <GameManager>().GetGame().GetBoardHandler().GetBoardGrid();
        int       victoryPoints = 0;

        for (int col = 0; col < boardGrid.GetColCount(); col++)
        {
            for (int row = 0; row < boardGrid.GetRowCount(); row++)
            {
                for (int spec = 0; spec < 2; spec++)
                {
                    Vertex vertex = boardGrid.GetVertex(col, row, (BoardGrid.VertexSpecifier)spec);
                    if (vertex != null && vertex.settlement != null)
                    {
                        if (vertex.settlement.ownerId == id)
                        {
                            if (vertex.settlement.isCity)
                            {
                                victoryPoints += 2;
                            }
                            else
                            {
                                victoryPoints += 1;
                            }
                        }
                    }
                }
            }
        }
        return(victoryPoints);
    }
Exemplo n.º 2
0
        public void Constructor_generates_new_board_based_on_given_BoardSize(
            BoardSize expectedSize)
        {
            var sut = new BoardGrid(expectedSize.Width, expectedSize.Height);

            Assert.Equal(sut.Columns * sut.Rows, sut.State.Count);
        }
Exemplo n.º 3
0
        private void UndoButton_Click(object sender, RoutedEventArgs e)
        {
            if (MoveHistory.Count < 1)
            {
                return;
            }

            Untrack();

            Move lastMove = MoveHistory.Last();

            Cell target = BoardGrid.GetCellAt(lastMove.Target);

            target.Filled = false;
            Cell source = BoardGrid.GetCellAt(lastMove.Source);
            Cell middle = BoardGrid.GetMiddleCell(source, target);

            middle.Selected = false;
            middle.Filled   = true;
            source.Selected = false;
            source.Filled   = true;

            UndoHistory.Add(lastMove);
            MoveHistory.RemoveAt(MoveHistory.Count - 1);
        }
Exemplo n.º 4
0
 private void BallClick(object sender, RoutedEventArgs e)
 {
     if (SourceCell == null)
     {
         SourceCell          = (Cell)sender;
         SourceCell.Selected = true;
     }
     else
     {
         TargetCell = (Cell)sender;
         if (BoardGrid.IsValidMove(SourceCell, TargetCell))
         {
             SourceCell.Filled = false;
             MakeMove();
         }
         else
         {
             SourceCell.Selected = false;
             if (SourceCell.Position == TargetCell.Position)
             {
                 SourceCell = null;
             }
             else
             {
                 SourceCell          = TargetCell;
                 SourceCell.Selected = true;
             }
             TargetCell = null;
         }
     }
 }
Exemplo n.º 5
0
        private void MovePart2(Point p, bool reverse)
        {
            Move move;

            if (reverse)
            {
                move = new Move(p, _originMovePoint, _amazonMovePoint);
                if (!Board.GetAvailableReverseMovesForPreviousPlayer().Contains(move))
                {
                    throw new Exception($"Invalid reverse move: {move}");
                }
                Board.ApplyReverseMove(move);
            }
            else
            {
                move = new Move(_originMovePoint, _amazonMovePoint, p);
                if (!Board.GetAvailableMovesForCurrentPlayer().Contains(move))
                {
                    throw new Exception($"Invalid move: {move}");
                }
                Board.ApplyMove(move);
            }
            MoveUpdated?.Invoke(move, reverse);
            BoardGrid.Children.Clear();
            BoardGrid.UpdateLayout();
            DrawBoard();
            BoardGrid.UpdateLayout();
        }
Exemplo n.º 6
0
 public DeploymentState(UnitController unit, UnitController king, BoardGrid myGrid, UIController ui)
 {
     _unitToDeploy = null;
     _activeUnit   = unit;
     _kingUnit     = king;
     myGrid.HideHighlight();
     ui.ShowDeployableUnits();
 }
Exemplo n.º 7
0
 private void ClearInitialMoves()
 {
     foreach (var element in BoardGrid.Children.OfType <Ellipse>().ToList())
     {
         BoardGrid.Children.Remove(element);
     }
     BoardGrid.UpdateLayout();
 }
Exemplo n.º 8
0
    private void PlaceFigureOnBoard(GridCell spawnCell)
    {
        BoardGrid board = BoardGrid.GetInstance();

        board.InverseMarks(spawnCell.CellPosition, figureStruct.partsPositions, true);
        board.CheckWin();
        StartCoroutine(DestroyFigure());
    }
Exemplo n.º 9
0
        public void Constructor_generates_a_board_based_on_given_BoardSlotValue_array(
            BoardSlotValue[,] boardSlotValues, BoardSize expectedSize)
        {
            var sut = new BoardGrid(boardSlotValues);

            Assert.Equal(expectedSize, sut.ToBoardSize());
            Assert.Equal(expectedSize.Height, sut.Rows);
            Assert.Equal(expectedSize.Width, sut.Columns);
        }
Exemplo n.º 10
0
 public void ApplyMove(Move move, bool reverse)
 {
     Board.ApplyMove(move);
     MoveUpdated?.Invoke(move, reverse);
     BoardGrid.Children.Clear();
     BoardGrid.UpdateLayout();
     DrawBoard();
     BoardGrid.UpdateLayout();
 }
Exemplo n.º 11
0
 private void CheckGameOver()
 {
     BoardGrid.CheckGameOver((int countFilled) =>
     {
         Play("ms-appx:///Assets/Audio/finale.mp3");
         Frame rootFrame = Window.Current.Content as Frame;
         rootFrame.Navigate(typeof(ResultPage), countFilled, new DrillInNavigationTransitionInfo());
     });
 }
Exemplo n.º 12
0
 public AttackSelectedState(UnitController uc, BoardGrid myGrid, UIController ui)
 {
     _activeUnit = uc;
     _activeUnit.SetReticle(true);
     ui.DisplayUnit(uc);
     ui.SelectUnit(uc);
     myGrid.HideHighlight();
     myGrid.ShowAttackRange(uc, uc.GetAttackRange(), _activeUnit.GetPlayerId());
     Debug.Log("Stan: Wybrany atak jednostki gracza: " + _activeUnit.GetPlayerId());
 }
Exemplo n.º 13
0
        private void MakeMove()
        {
            SaveMove(SourceCell, TargetCell);

            Play("ms-appx:///Assets/Audio/short_pop_sound.mp3");
            TargetCell.Selected = false;
            TargetCell.Filled   = true;
            BoardGrid.GetMiddleCell(SourceCell, TargetCell).Filled = false;
            Untrack();
            CheckGameOver();
        }
Exemplo n.º 14
0
 public UnitSelectedState(UnitController uc, BoardGrid myGrid, UIController ui)
 {
     _activeUnit = uc;
     _activeUnit.SetReticle(true);
     myGrid.ShowMoveRange(_activeUnit.GetGridPosition(), _activeUnit.GetMoveRange());
     if (_activeUnit._freeAttacksCount > 0)
     {
         myGrid.ShowAttackRange(uc, uc.GetAttackRange(), _activeUnit.GetPlayerId());
     }
     ui.DisplayUnit(uc);
     ui.SelectUnit(uc);
     Debug.Log("Stan: Wybrana jednostka gracza: " + _activeUnit.GetPlayerId());
 }
Exemplo n.º 15
0
 public void StartTutorial(Game game, LevelInfoPanel levelInfoPanel, FigureSpawner figureSpawner, BoardGrid boardGrid)
 {
     this.game           = game;
     this.levelInfoPanel = levelInfoPanel;
     this.figureSpawner  = figureSpawner;
     this.boardGrid      = boardGrid;
     levelInfoPanel.SetLevelHeaderText("Training");
     levelInfoPanel.UpdateLevelValue(tutorialLevel);
     figureSpawner.SpawnFigures(GetFiguresSpawnInfo(), GetCountOfFigures());
     boardGrid.ShowMarks(false);
     levelInfoPanel.ShowTutorialButtons();
     Addressables.LoadAssetAsync <GameObject>("Assets/Prefabs/Rules Window.prefab").Completed += OnResultWindowInstantiate;
 }
Exemplo n.º 16
0
    public void CmdRollDice()
    {
        // Roll
        System.Random random = new System.Random();
        int           roll   = random.Next(1, 7) + random.Next(1, 7);

        GameManager.Instance.recentRoll = roll;

        // Update this player's state
        Player thisPlayer = GameManager.Instance.GetPlayerById(playerBehaviour.netId + "");

        if (roll == 7)
        {
            thisPlayer.state = PlayerState.ROBBING;

            // If any players have 8 or more development cards, dump half their hands by random
            foreach (Player player in GameManager.Instance.GetGame().players)
            {
                player.AttemptToDiscardHalfOfCards();
            }
        }
        else
        {
            thisPlayer.state = PlayerState.TRADING;
        }

        // Produce resources for each player
        BoardGrid boardGrid = GameManager.Instance.GetGame().GetBoardHandler().GetBoardGrid();

        for (int col = 0; col < boardGrid.GetColCount(); col++)
        {
            for (int row = 0; row < boardGrid.GetRowCount(); row++)
            {
                Face face = boardGrid.GetFace(col, row);
                if (face != null && face.tile != null && face.tile.chanceValue == roll) // If tile exists, and roll
                {
                    List <Vertex> vertices = boardGrid.GetVerticesFromFace(col, row);
                    foreach (Vertex vertex in vertices) // Get all vertexes of this tile
                    {
                        if (vertex.settlement != null)
                        {
                            Player player = GameManager.Instance.GetPlayerById(vertex.settlement.ownerId);
                            player.AddResource(face.tile.resourceType, vertex.settlement.isCity ? 2 : 1); // Give two resources if city, one if settlement
                        }
                    }
                }
            }
        }

        GameManager.Instance.SetDirtyBit(0b11111111);
    }
Exemplo n.º 17
0
        private void BallDragEnter(object sender, DragEventArgs e)
        {
            e.DragUIOverride.IsGlyphVisible   = false;
            e.DragUIOverride.IsCaptionVisible = false;

            TargetCell = (Cell)sender;
            if (BoardGrid.IsValidMove(SourceCell, TargetCell))
            {
                e.AcceptedOperation = DataPackageOperation.Move;
            }
            else
            {
                e.AcceptedOperation = DataPackageOperation.None;
            }
        }
Exemplo n.º 18
0
    public void StartGame()
    {
        UnitController newUnit;

        string configFilePath = Application.streamingAssetsPath + "/grid.csv";

        string[] gridFile = File.ReadAllLines(configFilePath);
        _myGrid      = new BoardGrid(gridFile, _tilePrefabs, _designerTileSize, _tileWidth, _tileHeight);
        _myGameState = new BeginTurnState(_startingPlayer);
        int i = 0;

        foreach (GameObject unitPrefab in _unitPrefabsPlayer1)
        {
            newUnit = Instantiate(unitPrefab, new Vector3(100.0f, 100.0f, 0.0f), Quaternion.identity).GetComponent <UnitController>();
            newUnit.InitializeUnit();
            if (newUnit.IsKing())
            {
                newUnit.DeployUnit(_myGrid.GetTile(0, _myGrid.GetBoardHeight() - 1));
            }
            _units.Add(newUnit);
            i++;
        }
        i = 0;
        foreach (GameObject unitPrefab in _unitPrefabsPlayer2)
        {
            newUnit = Instantiate(unitPrefab, new Vector3(100.0f, 100.0f, 0.0f), Quaternion.identity).GetComponent <UnitController>();
            newUnit.InitializeUnit();
            if (newUnit.IsKing())
            {
                newUnit.DeployUnit(_myGrid.GetTile(_myGrid.GetBoardWidth() - 1, 0));
            }
            _units.Add(newUnit);
            i++;
        }
        foreach (UnitController unit in _units)
        {
            IEnterTile[] unitEnterTileReactors;
            if (unit._isDeployed)
            {
                unitEnterTileReactors = unit.gameObject.GetComponents <IEnterTile>();
                foreach (IEnterTile reactor in unitEnterTileReactors)
                {
                    reactor.EnterTileAction(unit._myTile);
                }
            }
        }
        _myUIController.InitializeUnitsPanel(_units, _startingPlayer, this, _timeLimit);
    }
Exemplo n.º 19
0
    public void StartNewGame(int difficulty)
    {
        boardGrid = new BoardGrid();

        currentDifficulty = difficulty;
        playerSign        = 1;
        aiSign            = 2;
        makingMoveSign    = 1;

        wins   = 0;
        draws  = 0;
        losses = 0;

        SceneManager.LoadScene("GameScene");
        SceneManager.sceneLoaded += GameReady;
    }
Exemplo n.º 20
0
 public void SpawnField()
 {
     instance  = this;
     gridCells = GetComponent <CellsSpawner>().SpawnCells(DataStorage.FieldSize.x);
     FillBoard(MarkType.Cross);
     for (int i = 0; i < gridCells.GetLength(0); i++)
     {
         for (int j = 0; j < gridCells.GetLength(1); j++)
         {
             if (i != 1 || j != 1)
             {
                 StartCoroutine(gridCells[i, j].SpawnCellAnimated());
             }
         }
     }
 }
Exemplo n.º 21
0
 // Update is called once per frame
 void Update()
 {
     if (boardGrid == null)
     {
         boardGrid = Manager.boardGrid;
     }
     else
     {
         if (!set)
         {
             newPos.x             = boardGrid.getGridCell(boardGrid.getGridSize() - 1, boardGrid.getGridSize() - 1).getCellTile().transform.position.x;
             newPos.y             = boardGrid.getGridCell(boardGrid.getGridSize() - 1, boardGrid.getGridSize() - 1).getCellTile().transform.position.y;
             transform.position   = newPos;
             transform.localScale = new Vector2(8.0f / boardGrid.getGridSize(), 8.0f / boardGrid.getGridSize());
             set = true;
         }
     }
 }
Exemplo n.º 22
0
 public void OnPointerUp(PointerEventData eventData)
 {
     if (!isDragging)
     {
         return;
     }
     isDragging = false;
     if (gridCell != null && BoardGrid.GetInstance().CanPlaceFigure(gridCell.GetComponent <GridCell>(), figureStruct.figureSize))
     {
         figureTransform.localPosition = new Vector3(gridCell.transform.position.x, gridCell.transform.position.y, figureTransform.localPosition.z);
         PlaceFigureOnBoard(gridCell.GetComponent <GridCell>());
         FigureSpawner.GetInstance().DeleteFigure(figureIndex);
     }
     else
     {
         StartCoroutine(MoveFigureToStartPosition());
     }
 }
Exemplo n.º 23
0
    private static int Evaluate(BoardGrid grid)
    {
        int result = grid.CheckWinner();

        switch (result)
        {
        case 1:
            return(10);

        case 2:
            return(-10);

        case 0:
            return(0);

        default:
            return(-1);
        }
    }
Exemplo n.º 24
0
    public static Coordinates GetBestMove(int difficulty, BoardGrid grid, int aiSign)
    {
        currentDifficulty = difficulty;

        int opponentSign = aiSign == 1 ? 2 : 1;

        Coordinates coordinates;

        List <Move> moves = new List <Move>();

        for (int i = 0; i < grid.cells.GetLength(0); i++)
        {
            for (int j = 0; j < grid.cells.GetLength(1); j++)
            {
                if (grid.cells[i, j] == 0)
                {
                    grid.cells[i, j] = aiSign;

                    int moveVal = MiniMax(grid, 0, opponentSign);

                    grid.cells[i, j] = 0;

                    moves.Add(new Move(new Coordinates(i, j), moveVal));
                }
            }
        }

        if (aiSign == 1)
        {
            moves = moves.OrderByDescending(m => m.score).ToList();
        }
        else
        {
            moves = moves.OrderBy(m => m.score).ToList();
        }

        List <Move> sameMoves = moves.Where(m => m.score == moves[0].score).ToList();

        coordinates = sameMoves[UnityEngine.Random.Range(0, sameMoves.Count)].coordinates;

        return(coordinates);
    }
Exemplo n.º 25
0
 public void InitializeTile(GridPosition position, BoardGrid myBoardGrid)
 {
     _mySpriteRenderer                  = GetComponent <SpriteRenderer>();
     _myCollider                        = GetComponent <PolygonCollider2D>();
     _myDesignerCollider                = GetComponent <BoxCollider2D>();
     _mySpriteRenderer.sprite           = _tile.tileSprite;
     _crosshairSpriteRenderer.enabled   = false;
     _crosshairSpriteRenderer.sprite    = _crosshairSprite;
     _overlayColorSpriteRenderer.sprite = _plainTileSprite;
     _gridPosition                      = position;
     _previousColor                     = _overlayColorSpriteRenderer.color;
     _previousMarker                    = _overlayMarkerSpriteRenderer.sprite;
     _myUnit                     = null;
     _isOccupied                 = false;
     _gCost                      = 0;
     _hCost                      = 0;
     _fCost                      = 0;
     _myBehaviour                = GetComponent <ITileBehaviour>();
     _myBoard                    = myBoardGrid;
     _isDesignerMode             = false;
     _myDesignerCollider.enabled = false;
 }
Exemplo n.º 26
0
 private void HighlightCells(IEnumerable <Point> points, bool part2, bool reverse)
 {
     ClearInitialMoves();
     foreach (Point p in points)
     {
         (int row, int column) = GetRowColumn(Board.Size, p);
         System.Windows.Shapes.Ellipse ellipse = new Ellipse();
         ellipse.Fill = Brushes.Coral;
         Grid.SetRow(ellipse, row);
         Grid.SetColumn(ellipse, column);
         BoardGrid.Children.Add(ellipse);
         if (part2)
         {
             ellipse.MouseDown += (sender, e) => { MovePart2(p, reverse); }
         }
         ;
         else
         {
             ellipse.MouseDown += (sender, e) => { MovePart1(p, reverse); }
         };
     }
     BoardGrid.UpdateLayout();
 }
    /**
     * Obtain the victory points for a player, given their ID.
     */
    public int GetVictoryPointsForPlayerId(string id)
    {
        BoardGrid boardGrid     = GameManager.Instance.GetGame().GetBoardHandler().GetBoardGrid();
        int       victoryPoints = 0;

        // Building related victory points
        for (int col = 0; col < boardGrid.GetColCount(); col++)
        {
            for (int row = 0; row < boardGrid.GetRowCount(); row++)
            {
                for (int spec = 0; spec < 2; spec++)
                {
                    Vertex vertex = boardGrid.GetVertex(col, row, (BoardGrid.VertexSpecifier)spec);
                    if (vertex != null && vertex.settlement != null)
                    {
                        if (vertex.settlement.ownerId == id)
                        {
                            if (vertex.settlement.isCity)
                            {
                                victoryPoints += 2;
                            }
                            else
                            {
                                victoryPoints += 1;
                            }
                        }
                    }
                }
            }
        }

        // Longest Road related victory points

        // Largest Army related victory points

        return(victoryPoints);
    }
Exemplo n.º 28
0
    public void CmdPlaceSettlement(int col, int row, int vertexSpec)
    {
        Player    player    = GameManager.Instance.GetPlayerById(playerBehaviour.netId + "");
        BoardGrid boardGrid = GameManager.Instance.GetGame().boardHandler.GetBoardGrid();

        Vertex     vertex     = boardGrid.GetVertex(col, row, (BoardGrid.VertexSpecifier)vertexSpec);
        Settlement settlement = new Settlement();

        settlement.ownerId = player.GetId();
        settlement.isCity  = false;
        vertex.settlement  = settlement;
        if (player.freeSettlements >= 1)
        {
            player.freeSettlements--;
        }
        else
        {
            player.RemoveResources(1, 1, 1, 1, 0);
        }

        player.storeSettlementNum--;

        // If this was the second turn, give resources related to tiles surrounding this settlement to player.
        if (GameManager.Instance.GetTurnCycle() == 2)
        {
            foreach (Face face in boardGrid.GetFacesFromVertexCoordinate(col, row, (BoardGrid.VertexSpecifier)vertexSpec))
            {
                if (face.tile != null)
                {
                    player.AddResource(face.tile.resourceType, 1);
                }
            }
        }

        GameManager.Instance.SetDirtyBit(0b11111111);
    }
Exemplo n.º 29
0
        /// <summary>
        /// Event handler for orientation changes.
        /// Repositions UI elements depending on the orientation.
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="r">Event arguments</param>
        private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            if (e.Orientation == PageOrientation.Landscape ||
                e.Orientation == PageOrientation.LandscapeLeft ||
                e.Orientation == PageOrientation.LandscapeRight)
            {
                Logo.SetValue(Grid.RowProperty, 1);
                Logo.SetValue(Grid.ColumnSpanProperty, 1);

                BoardGrid.SetValue(Grid.RowProperty, 0);
                BoardGrid.SetValue(Grid.ColumnProperty, 1);
                BoardGrid.SetValue(Grid.RowSpanProperty, 3);
                BoardGrid.SetValue(Grid.ColumnSpanProperty, 2);

                waitIndicator.SetValue(Grid.RowProperty, 0);
                waitIndicator.SetValue(Grid.ColumnProperty, 1);
                waitIndicator.SetValue(Grid.RowSpanProperty, 3);
                waitIndicator.SetValue(Grid.ColumnSpanProperty, 2);

                Statistics.SetValue(Grid.RowProperty, 1);
                Statistics.SetValue(Grid.RowSpanProperty, 2);
                Statistics.SetValue(Grid.ColumnSpanProperty, 1);

                if (e.Orientation == PageOrientation.LandscapeLeft)
                {
                    LayoutRoot.Margin = new Thickness(0, 0, 72, 0);
                }
                if (e.Orientation == PageOrientation.LandscapeRight)
                {
                    LayoutRoot.Margin = new Thickness(72, 0, 0, 0);
                }

                LayoutRoot.RowDefinitions[0].Height = new GridLength(90);
                LayoutRoot.RowDefinitions[1].Height = new GridLength(90);

                for (int t = 0; t < Statistics.ColumnDefinitions.Count; t++)
                {
                    Statistics.ColumnDefinitions[t].Width = new GridLength(0);
                }

                Statistics.ColumnDefinitions[0].Width = new GridLength(10);
                Statistics.ColumnDefinitions[1].Width = new GridLength(35, GridUnitType.Star);
                Statistics.ColumnDefinitions[2].Width = new GridLength(65, GridUnitType.Star);

                Statistics.RowDefinitions[0].Height = new GridLength(10);
                Statistics.RowDefinitions[1].Height = new GridLength(100, GridUnitType.Star);
                Statistics.RowDefinitions[2].Height = new GridLength(100, GridUnitType.Star);
                Statistics.RowDefinitions[3].Height = new GridLength(100, GridUnitType.Star);
                Statistics.RowDefinitions[4].Height = new GridLength(10);

                Statistics.Height = 192;

                MovesImage.SetValue(Grid.ColumnProperty, 1);
                MovesImage.SetValue(Grid.RowProperty, 1);

                EmptyImage.SetValue(Grid.ColumnProperty, 1);
                EmptyImage.SetValue(Grid.RowProperty, 2);

                GameTimeImage.SetValue(Grid.ColumnProperty, 1);
                GameTimeImage.SetValue(Grid.RowProperty, 3);

                Moves.SetValue(Grid.ColumnProperty, 2);
                Moves.SetValue(Grid.RowProperty, 1);

                Empty.SetValue(Grid.ColumnProperty, 2);
                Empty.SetValue(Grid.RowProperty, 2);

                GameTime.SetValue(Grid.ColumnProperty, 2);
                GameTime.SetValue(Grid.RowProperty, 3);
            }
            else
            {
                Logo.SetValue(Grid.RowProperty, 0);
                Logo.SetValue(Grid.ColumnSpanProperty, 2);

                BoardGrid.SetValue(Grid.RowProperty, 1);
                BoardGrid.SetValue(Grid.ColumnProperty, 0);
                BoardGrid.SetValue(Grid.RowSpanProperty, 1);
                BoardGrid.SetValue(Grid.ColumnSpanProperty, 2);

                waitIndicator.SetValue(Grid.RowProperty, 1);
                waitIndicator.SetValue(Grid.ColumnProperty, 0);
                waitIndicator.SetValue(Grid.RowSpanProperty, 1);
                waitIndicator.SetValue(Grid.ColumnSpanProperty, 2);

                Statistics.SetValue(Grid.RowProperty, 3);
                Statistics.SetValue(Grid.RowSpanProperty, 1);
                Statistics.SetValue(Grid.ColumnSpanProperty, 2);

                LayoutRoot.Margin = new Thickness(0, 0, 0, 72);
                LayoutRoot.RowDefinitions[0].Height = new GridLength(120);
                LayoutRoot.RowDefinitions[1].Height = new GridLength(460);

                for (int t = 0; t < Statistics.RowDefinitions.Count; t++)
                {
                    Statistics.RowDefinitions[t].Height = new GridLength(0);
                }

                Statistics.ColumnDefinitions[0].Width = new GridLength(18);
                Statistics.ColumnDefinitions[1].Width = new GridLength(60, GridUnitType.Star);
                Statistics.ColumnDefinitions[2].Width = new GridLength(75, GridUnitType.Star);
                Statistics.ColumnDefinitions[3].Width = new GridLength(60, GridUnitType.Star);
                Statistics.ColumnDefinitions[4].Width = new GridLength(75, GridUnitType.Star);
                Statistics.ColumnDefinitions[5].Width = new GridLength(60, GridUnitType.Star);
                Statistics.ColumnDefinitions[6].Width = new GridLength(90, GridUnitType.Star);
                Statistics.ColumnDefinitions[7].Width = new GridLength(18);

                Statistics.RowDefinitions[0].Height = new GridLength(100, GridUnitType.Star);

                Statistics.Height = 64;

                MovesImage.SetValue(Grid.ColumnProperty, 1);
                MovesImage.SetValue(Grid.RowProperty, 0);

                EmptyImage.SetValue(Grid.ColumnProperty, 3);
                EmptyImage.SetValue(Grid.RowProperty, 0);

                GameTimeImage.SetValue(Grid.ColumnProperty, 5);
                GameTimeImage.SetValue(Grid.RowProperty, 0);

                Moves.SetValue(Grid.ColumnProperty, 2);
                Moves.SetValue(Grid.RowProperty, 0);

                Empty.SetValue(Grid.ColumnProperty, 4);
                Empty.SetValue(Grid.RowProperty, 0);

                GameTime.SetValue(Grid.ColumnProperty, 6);
                GameTime.SetValue(Grid.RowProperty, 0);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            vertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);
             basicEffect = new BasicEffect(GraphicsDevice, null);
             basicEffect.VertexColorEnabled = true;

             projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60.0f), GraphicsDevice.Viewport.AspectRatio, 1.0f, 2000.0f);
             worldMatrix = Matrix.CreateTranslation(0, 0, 0);

             basicEffect.World = worldMatrix;
             basicEffect.Projection = projectionMatrix;

             pointList = new VertexPositionColor[POINTS];

             for (int x = 0; x < POINTS / 2; x++)
             {
            for (int z = 0; z < 2; z++)
            {
               pointList[(x * 2) + z] = new VertexPositionColor(new Vector3(x * 100, 0, z * 100), Color.White);
            }
             }

             board = new BoardGrid(10, 10);

             base.Initialize();
        }
        public void RenderBoard()
        {
            BoardGrid.Children.Clear();
            _pebbleControls.Clear();

            for (int row = 0; row < Board.Rows; row++)
            {
                for (int column = 0; column < Board.Columns; column++)
                {
                    if (!IsInvalidPebble(row, column)) //if not invalid position
                    {
                        bool addQTextBlock = false;

                        string pebbleImagePath = _holeImagePath;
                        Cursor pebbleCursor    = Cursors.Arrow;
                        double pebbleOpacity   = _holeOpacity;
                        bool   pebbleHitTest   = false;

                        if (IsValidPebble(row, column)) //if there is a pebble in this position
                        {
                            pebbleImagePath = _pebbleImagePaths[_currentTheme];
                            pebbleCursor    = Cursors.Hand;
                            pebbleOpacity   = _normalPebbleOpacity;
                            pebbleHitTest   = true;
                        }

                        //if game is in target-selection-mode, disable moving other pebbles
                        if (_currentGameMode == GameMode.TargetSelection)
                        {
                            pebbleOpacity = _otherPebblesOpacity;
                            pebbleHitTest = false;
                            pebbleCursor  = Cursors.Arrow;

                            if (IsTargetPosition(new Position(row, column)))
                            {
                                pebbleImagePath = _highlightedImagePath;
                                pebbleOpacity   = _normalPebbleOpacity;
                                pebbleHitTest   = true;
                                pebbleCursor    = Cursors.Hand;

                                addQTextBlock = true;
                            }
                            if (row == _currentPosition.Row && column == _currentPosition.Column)
                            {
                                //pebbleImagePath = _highlightedImagePath;
                                pebbleOpacity = _normalPebbleOpacity;
                            }
                        }

                        Image pebbleImage = new Image();
                        pebbleImage.Source  = new BitmapImage(new Uri(pebbleImagePath, UriKind.Relative));
                        pebbleImage.Stretch = Stretch.Uniform;
                        pebbleImage.Margin  = new Thickness(2);
                        if (pebbleImagePath.Equals(_holeImagePath))
                        {
                            //pebbleImage.RenderTransform = new ScaleTransform(0.95, 0.95);
                        }

                        ContentControl pebbleControl = new ContentControl();
                        pebbleControl.Name    = "PebbleControl_" + row + "_" + column;
                        pebbleControl.Tag     = new Position(row, column);
                        pebbleControl.Content = pebbleImage;
                        //pebbleControl.Style = (Style)FindResource("PebbleButtonStyle");
                        //pebbleControl.Background = new SolidColorBrush(Colors.Transparent);
                        //pebbleControl.BorderBrush = new SolidColorBrush(Colors.Transparent);
                        //pebbleControl.BorderThickness = new Thickness(0);
                        pebbleControl.Cursor           = pebbleCursor;
                        pebbleControl.Opacity          = pebbleOpacity;
                        pebbleControl.IsHitTestVisible = pebbleHitTest;
                        pebbleControl.IsTabStop        = false;
                        pebbleControl.SetValue(Grid.RowProperty, row);
                        pebbleControl.SetValue(Grid.ColumnProperty, column);
                        pebbleControl.MouseEnter += new MouseEventHandler(pebbleControl_MouseEnter);
                        pebbleControl.MouseLeave += new MouseEventHandler(pebbleControl_MouseLeave);
                        //pebbleControl.Click += new RoutedEventHandler(pebbleControl_Click);
                        pebbleControl.MouseDown += new MouseButtonEventHandler(pebbleControl_MouseDown);
                        BoardGrid.Children.Add(pebbleControl);
                        _pebbleControls.Add(pebbleControl);

                        if (addQTextBlock)
                        {
                            TextBlock qTextBlock = new TextBlock();
                            qTextBlock.Text                = "?";
                            qTextBlock.Foreground          = new SolidColorBrush(Colors.Black);
                            qTextBlock.IsHitTestVisible    = false;
                            qTextBlock.FontSize            = 52;
                            qTextBlock.FontWeight          = FontWeights.ExtraBold;
                            qTextBlock.Cursor              = Cursors.Hand;
                            qTextBlock.HorizontalAlignment = HorizontalAlignment.Center;
                            qTextBlock.VerticalAlignment   = VerticalAlignment.Center;
                            qTextBlock.SetValue(Grid.RowProperty, row);
                            qTextBlock.SetValue(Grid.ColumnProperty, column);
                            BoardGrid.Children.Add(qTextBlock);
                        }
                    }
                }
            }
            BoardGrid.UpdateLayout();
        }