Пример #1
0
 public mapBuilder()
 {
     tileType = 0;
     numRows = 15;
     numCols = 15;
     cells = new Grid[numRows, numCols];
     mapSpaces = new Tile[numRows, numCols];
     InitializeComponent();
     for (int r = 0; r < numRows; r++)
     {
         for (int c = 0; c < numCols; c++)
         {
             Grid cell = new Grid();
             mapSpaces[r,c] = new Tile(r,c, 0);
             mapSpaces[r,c].Click += new RoutedEventHandler(Space_Click);
             ImageBrush backgroundImage;
             backgroundImage = new ImageBrush(mapSpaces[r, c].terrainImage.terrainImage);
             mapSpaces[r, c].Background = backgroundImage; //Set the background of the tile button to the terrain image.
             mapSpaces[r,c].BorderThickness = new Thickness(0);
             cells[r, c] = cell;
             cell.Children.Add(mapSpaces[r,c]);
             Map.Children.Add(cell);
         }
     }
     for(int i = 0; i <= 3; i++)
     {
         Tile nextTile = new Tile(0, 0, i);
         ImageBrush backgroundImage;
         backgroundImage = new ImageBrush(nextTile.terrainImage.terrainImage);
         nextTile.Background = backgroundImage;
         nextTile.Click += new RoutedEventHandler(Tile_Type_Click);
         Tiles.Children.Add(nextTile);
     }
 }
Пример #2
0
        private void Move_Click(object sender, RoutedEventArgs e)
        {
          index1 = Board.Children.IndexOf(terrain[firstRow,firstCol]);
          index2 = Board.Children.IndexOf(terrain[secondRow,secondCol]);
                   
                
            

            Board.Children.Remove(terrain[secondRow, secondCol]);
            Board.Children.Remove(terrain[firstRow, firstCol]);
            terrain[secondRow, secondCol].Click -= moveCharacter;
            terrain[firstRow, firstCol].Click -= moveCharacter;
            swamp2 = terrain[secondRow, secondCol];
            swamp1 = terrain[firstRow, firstCol];
            colorTemp = terrain[secondRow, secondCol].Background;
            imageTemp = terrain[firstRow, firstCol].Background;
            

            terrain[firstRow, firstCol] = swamp2;
            terrain[firstRow, firstCol].Row = firstRow;
            terrain[firstRow, firstCol].Col = firstCol;
            terrain[firstRow, firstCol].Background = colorTemp;
            terrain[firstRow, firstCol].Click += moveCharacter;
            Board.Children.Insert(index1,terrain[firstRow, firstCol]);

            terrain[secondRow, secondCol] = swamp1;
            terrain[secondRow, secondCol].Row = secondRow;
            terrain[secondRow, secondCol].Col = secondCol;
            terrain[secondRow, secondCol].Background = imageTemp;
            terrain[secondRow, secondCol].Click += moveCharacter;
            Board.Children.Insert(index2, terrain[secondRow, secondCol]);
            Move.IsEnabled = false;


        }
Пример #3
0
        private void Space_Click(object sender, RoutedEventArgs e)
        {
            int row = 0;
            int col = 0;

            try
            {
                //Get the row and column of the tile button that was clicked (Row and Col are accessors in Tile).
                row = (sender as Tile).Row;
                col = (sender as Tile).Col;
            }
            catch
            {

            }

            cells[row, col].Children.Clear();
            mapSpaces[row, col] = new Tile(row, col, tileType);
            mapSpaces[row, col].Click += new RoutedEventHandler(Space_Click);
            ImageBrush backgroundImage;
            backgroundImage = new ImageBrush(mapSpaces[row, col].terrainImage.terrainImage);
            mapSpaces[row, col].Background = backgroundImage; //Set the background of the tile button to the terrain image.
            mapSpaces[row, col].BorderThickness = new Thickness(0);
            cells[row, col].Children.Add(mapSpaces[row, col]);
        }
Пример #4
0
        public override Tile[,] Attack1(Tile[,] boardspaces, int numRows, int numCols)
        {
            //TEST ATTACK ONLY, will probably be removed later
            //up
            this.selectedAttackPower = 1.0;

            if(row - 1 >= 0 && !boardspaces[row -1, col].isUnpassable)
            {
                boardspaces[row - 1, col].attackOption = 1;
                if(row - 2 >= 0 && !boardspaces[row - 2, col].isUnpassable)
                {
                    boardspaces[row - 2, col].attackOption = 1;
                    if (col - 1 >= 0 && !boardspaces[row - 2, col - 1].isUnpassable)
                        boardspaces[row - 2, col - 1].attackOption = 1;
                    if (col + 1 >= 0 && !boardspaces[row - 2, col + 1].isUnpassable)
                        boardspaces[row - 2, col + 1].attackOption = 1;
                }
            }
            //down
            if (row + 1 < numRows && !boardspaces[row + 1, col].isUnpassable)
            {
                boardspaces[row + 1, col].attackOption = 4;
                if (row + 2 < numRows && !boardspaces[row + 2, col].isUnpassable)
                {
                    boardspaces[row + 2, col].attackOption = 4;
                    if (col - 1 >= 0 && !boardspaces[row + 2, col - 1].isUnpassable)
                        boardspaces[row + 2, col - 1].attackOption = 4;
                    if (col + 1 < numCols && !boardspaces[row + 2, col + 1].isUnpassable)
                        boardspaces[row + 2, col + 1].attackOption = 4;
                }
            }
            //left
            if (col - 1 >= 0 && !boardspaces[row, col - 1].isUnpassable)
            {
                boardspaces[row, col - 1].attackOption = 2;
                if (col - 2 >= 0 && !boardspaces[row, col - 2].isUnpassable)
                {
                    boardspaces[row, col - 2].attackOption = 2;
                    if (row - 1 >= 0 && !boardspaces[row -1, col - 2].isUnpassable)
                        boardspaces[row -1, col - 2].attackOption = 2;
                    if (row + 1 < numCols && !boardspaces[row + 1, col -2].isUnpassable)
                        boardspaces[row + 1, col -2].attackOption = 2;
                }
            }
            //right
            if (col + 1 >= 0 && !boardspaces[row, col + 1].isUnpassable)
            {
                boardspaces[row, col + 1].attackOption = 3;
                if (col + 2 >= 0 && !boardspaces[row, col + 2].isUnpassable)
                {
                    boardspaces[row, col + 2].attackOption = 3;
                    if (row - 1 >= 0 && !boardspaces[row - 1, col + 2].isUnpassable)
                        boardspaces[row - 1, col + 2].attackOption = 3;
                    if (row + 1 < numCols && !boardspaces[row - 1, col + 2].isUnpassable)
                        boardspaces[row + 1, col + 2].attackOption = 3;
                }
            }

            return boardspaces;
        }
Пример #5
0
 public void removeAttackOption(Tile space)
 {
     typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(space, new object[] { false });
     space.Click -= new RoutedEventHandler(AttackOption_Click);
     space.MouseEnter -= new MouseEventHandler(AttackOption_MouseEnter);
     space.MouseLeave -= new MouseEventHandler(AttackOption_MouseLeave);
     space.BorderThickness = new Thickness(0);
     space.Click += new RoutedEventHandler(Tile_Click);
     if (space.containsCharacter())
     {
         space.tileCharacter.Click -= new RoutedEventHandler(AttackOption_Click);
         space.tileCharacter.MouseEnter -= new MouseEventHandler(AttackOption_MouseEnter);
         space.tileCharacter.MouseEnter -= new MouseEventHandler(AttackOption_MouseLeave);
         space.tileCharacter.Click += new RoutedEventHandler(Character_Click);
         typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(space.tileCharacter, new object[] { false });
     }
 }
Пример #6
0
        public void setUpBoard()
        {
            
            for (int r = 0; r < boardRow; r++)
            {
                for (int c = 0; c < boardCol; c++)
                {
                    cell[r,c] = new Grid();
                    switch (table[r, c])
                    {
                         case 1:
                                                         
                            
                            terrain[r, c] = new Mage();
                            terrain[r,c].Background = terrain[r, c].Image;
                            
                            
                            terrain[r, c].BorderThickness = new Thickness(0);
                           

                            break;
                        default:
                            terrain[r, c] = new Tile();
                            terrain[r,c].Background = grass;
                            terrain[r, c].BorderThickness = new Thickness(0);
                                                              
                                   break;

                    }
                    terrain[r, c].Row = r;
                    terrain[r, c].Col = c;
                    terrain[r, c].Click += new RoutedEventHandler(moveCharacter);
                   // cell[r, c].Children.Add(terrain[r, c]);
                    Board.Children.Add(terrain[r, c]);
                     
                    
                    
                }

            }
        }
Пример #7
0
        //constructors
        /*
         * Constructor for a blank board, makes a default board of all empty spaces
         */
        public void setupBoard()
        {
            numRows = 15;
            numCols = 15;
            numTurns = 1;
            numEnemies = 0;
            numHeroes = 5;
            boardspaces = new Tile[numRows, numCols];
            cells = new Grid[numRows, numCols]; //a 2d array of references to the grid cells that make up the board tiles graphically
            HeroesCounter.Content = ("Heroes Remaining: " + numHeroes);
            for(int r = 0; r < numRows; r++)
            {
                for(int c = 0; c < numCols; c++)
                {
                    boardspaces[r, c] = new Tile(r,c);

                    Grid cell = new Grid(); //Make a new grid object to contain the tile/character objects/buttons, images
                    cells[r, c] = cell;

                    refreshBoardSpace(r, c); //Draws the space for the first time
                    Board.Children.Add(cell);
                }
            }
        }
Пример #8
0
        /*
         * Constructor for setting up a board defined in a text file using various characters in the text file to determine the terrain type of each tile.
         * The input is read character by character, so the file should not be broken up with spaces or with multiple lines.
         * 0 = grass, 1 = mountain, 2 = water, 3 = swamp, other = defaults to grass. In the code, these are returned as their ascii code numbers, and have to be tested accordingly.
         * If the text file is not found, makes a blank, default board instead.
         * 
         * String mapfile = the name of the text file to read input from (Example: "testmap.txt")
         */
        public void setupBoard(String mapfile)
        {
            numRows = 15;
            numCols = 15;
            numTurns = 1;
            numEnemies = 0;
            numHeroes = 5;
            boardspaces = new Tile[numRows, numCols];
            HeroesCounter.Content = ("Heroes Remaining: " + numHeroes);
            cells = new Grid[numRows, numCols]; //a 2d array of references to the grid cells that make up the board tiles graphically

            if(!File.Exists(mapfile))
            {
                setupBoard();//make a blank board instead
            }
            else
            {
                using (StreamReader sr = File.OpenText(mapfile))
                {
                    int input;
                    for (int r = 0; r < numRows; r++)
                    {
                        for (int c = 0; c < numCols; c++)
                        {
                            input = sr.Read(); //read the next character in the txt file
                            switch (input)
                            {
                                case 48: //ascii code number for 0, grass (The StreamReader is reading them in as their ascii values)
                                    boardspaces[r, c] = new Tile(r,c,0);
                                    break;
                                case 49: //ascii code number for 1, mountain
                                    boardspaces[r, c] = new Tile(r,c,1);
                                    break;
                                case 50: //ascii code number for 2, water
                                    boardspaces[r, c] = new Tile(r,c,2);
                                    break;
                                case 51: //ascii code number for 3, swamp
                                    boardspaces[r, c] = new Tile(r,c,3);
                                    break;
                                default: //if no input or invalid input found in the file, make a blank grass space instead
                                    boardspaces[r, c] = new Tile(r,c);
                                    break;
                            }

                            Grid cell = new Grid(); //Make a new grid object to contain the tile/character objects/buttons, images
                            cells[r, c] = cell;

                            refreshBoardSpace(r, c); //Draws the space for the first time
                            Board.Children.Add(cell);
                        }
                    }
                }
            }
        }
Пример #9
0
        private Tile setTileByInput(int input)
        {
            Tile aTile;
            switch (input)
            {
                case 48: //ascii code number for 0, grass (The StreamReader is reading them in as their ascii values)
                    aTile = new Tile(0, 0, 0);
                    break;
                case 49: //ascii code number for 1, mountain
                    aTile = new Tile(0, 0, 1);
                    break;
                case 50: //ascii code number for 2, water
                    aTile = new Tile(0, 0, 2);
                    break;
                case 51: //ascii code for 3, swamp
                    aTile = new Tile(0, 0, 3);
                    break;
                case 52: //Tile_Color1 character: 4
                    aTile = new Tile(0, 0, 4);
                    break;
                case 53: //Tile_Color2 character: 5
                    aTile = new Tile(0, 0, 5);
                    break;
                case 54: //Tile_Color3 character: 6
                    aTile = new Tile(0, 0, 6);
                    break;
                case 55: //Tile_Textured character: 7
                    aTile = new Tile(0, 0, 7);
                    break;
                case 56: //Tile_Texture2 character: 8
                    aTile = new Tile(0, 0, 8);
                    break;
                case 57: //Tile_Texture3 character: 9
                    aTile = new Tile(0, 0, 9);
                    break;
                default: //if no input or invalid input found in the file, make a blank grass space instead
                    aTile = new Tile(0, 0);
                    break;
            }

            return aTile;
        }
Пример #10
0
 public virtual Tile[,] Attack1(Tile[,] boardspaces, int numRows, int numCols)
 {
     
     return boardspaces;
 }
Пример #11
0
 public void removeEnemyAttackOption(Tile space)
 {
     
     
     space.BorderThickness = new Thickness(0);
     
         
     
 }