public DualModePage(gameMode[] modeSels) : base() { // layout definition InitializeComponent(); p1mode = modeSels[0]; p2mode = modeSels[1]; // game grid definition outerGrid.Width = Styles.WindowSizeGenerator.screenWidth; outerGrid.Height = Styles.WindowSizeGenerator.screenHeight; ColumnDefinition aCol = new ColumnDefinition(); aCol.Width = new GridLength(Styles.WindowSizeGenerator.dualGameModuleRight, GridUnitType.Pixel); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(Styles.WindowSizeGenerator.dualAdditionModuleWidth, GridUnitType.Star); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(Styles.WindowSizeGenerator.dualGameModuleRight, GridUnitType.Pixel); outerGrid.ColumnDefinitions.Add(aCol); Border border1 = new Border(); border1.BorderBrush = new SolidColorBrush(Colors.Gray); border1.BorderThickness = new Thickness(2, 2, 2, 2); Border border2 = new Border(); border2.BorderBrush = new SolidColorBrush(Colors.Gray); border2.BorderThickness = new Thickness(2, 2, 2, 2); games = t.NewDuelGame( p1mode.player == 1?"":PlayersName.getName(0), p2mode.player == 1?"":PlayersName.getName(1) ); int[] gridSize = new int[2] { games.Item1.Height, games.Item1.Width }; // game grid GameGrid gameGrid1 = new GameGrid(gridSize); border1.Child = gameGrid1; outerGrid.Children.Add(border1); border1.SetValue(Grid.RowProperty, 1); border1.SetValue(Grid.ColumnProperty, 1); GameGrid gameGrid2 = new GameGrid(gridSize); border2.Child = gameGrid2; outerGrid.Children.Add(border2); border2.SetValue(Grid.RowProperty, 1); border2.SetValue(Grid.ColumnProperty, 3); games.Item1.AddDisplay(gameGrid1); games.Item2.AddDisplay(gameGrid2); // set score board and next block board Grid scoreNextBlockGrid = new Grid(); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Star); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Star); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Star); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); RowDefinition aRow = new RowDefinition(); aRow.Height = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.RowDefinitions.Add(aRow); aRow = new RowDefinition(); aRow.Height = new GridLength(Styles.WindowSizeGenerator.screenHeight / 30, GridUnitType.Pixel); scoreNextBlockGrid.RowDefinitions.Add(aRow); aRow = new RowDefinition(); aRow.Height = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.RowDefinitions.Add(aRow); outerGrid.Children.Add(scoreNextBlockGrid); scoreNextBlockGrid.SetValue(Grid.ColumnProperty, 2); scoreNextBlockGrid.SetValue(Grid.RowProperty, 1); double scoreHeight = Styles.WindowSizeGenerator.scoreBoardHeight; double scoreWidth = Styles.WindowSizeGenerator.scoreBoardWidth; ScoreGrid score1 = new ScoreGrid(scoreHeight, scoreWidth); ScoreGrid score2 = new ScoreGrid(scoreHeight, scoreWidth); // set next block board double nextBlockHeight = Styles.WindowSizeGenerator.nextBoardHeight; double nextBlockWidth = Styles.WindowSizeGenerator.nextBoardWidth; NextBlock nextBlock1 = new NextBlock(nextBlockHeight, nextBlockWidth); NextBlock nextBlock2 = new NextBlock(nextBlockHeight, nextBlockWidth); scoreNextBlockGrid.Children.Add(nextBlock1); nextBlock1.SetValue(Grid.ColumnProperty, 1); nextBlock1.SetValue(Grid.RowProperty, 2); nextBlock1.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); nextBlock1.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); scoreNextBlockGrid.Children.Add(nextBlock2); nextBlock2.SetValue(Grid.ColumnProperty, 3); nextBlock2.SetValue(Grid.RowProperty, 2); nextBlock2.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); nextBlock2.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); games.Item1.AddDisplay(nextBlock1); games.Item2.AddDisplay(nextBlock2); scoreNextBlockGrid.Children.Add(score1); scoreNextBlockGrid.Children.Add(score2); score1.SetValue(Grid.ColumnProperty, 1); score1.SetValue(Grid.RowProperty, 0); score1.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); score1.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); score2.SetValue(Grid.ColumnProperty, 3); score2.SetValue(Grid.RowProperty, 0); score2.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); score2.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); score1.DataContext = games.Item1.ScoreSystem; score2.DataContext = games.Item2.ScoreSystem; // set background pictures. PicGen pic = new Cat3Gen(); double picSizeRatio = 1.1; PicGenGrid pg1 = new PicGenGrid(pic, SquareGenerator.picSquareSize / picSizeRatio); aCanvas.Children.Add(pg1); pg1.SetValue(Canvas.ZIndexProperty, 0); Canvas.SetLeft(pg1, (Styles.WindowSizeGenerator.screenWidth - pg1.getPicSize()[1] * SquareGenerator.picSquareSize / picSizeRatio) / 2); Canvas.SetBottom(pg1, Styles.WindowSizeGenerator.gameModuleTop + (-1 * pg1.getPicSize()[0] * SquareGenerator.picSquareSize / picSizeRatio) / 2.2); aRect1 = new Rectangle(); aRect1.Fill = new SolidColorBrush(Colors.Transparent); aRect1.Width = gameGrid1.getGameGridSize()[1]; aRect1.Height = gameGrid1.getGameGridSize()[0]; outerGrid.Children.Add(aRect1); aRect1.SetValue(Grid.ColumnProperty, 1); aRect1.SetValue(Grid.RowProperty, 1); //game.GameEndEvent += gameEnd; games.DuelGameEndEvent += gameEndEffect; // set the mask rect (used when game is over) aRect2 = new Rectangle(); aRect2.Fill = new SolidColorBrush(Colors.Transparent); aRect2.Width = gameGrid1.getGameGridSize()[1]; aRect2.Height = gameGrid1.getGameGridSize()[0]; outerGrid.Children.Add(aRect2); aRect2.SetValue(Grid.ColumnProperty, 3); aRect2.SetValue(Grid.RowProperty, 1); }
public SingleModePage() { InitializeComponent(); int[] nextBlockSize = new int[] { 4, 3 }; ColumnDefinition aCol = new ColumnDefinition(); aCol.Width = new GridLength(50, GridUnitType.Star); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(50, GridUnitType.Auto); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(50, GridUnitType.Star); outerGrid.ColumnDefinitions.Add(aCol); outerGrid.Width = Styles.WindowSizeGenerator.screenWidth; outerGrid.Height = Styles.WindowSizeGenerator.screenHeight; Border border = new Border(); border.BorderBrush = new SolidColorBrush(Colors.Gray); border.BorderThickness = new Thickness(2, 2, 2, 2); game = t.NewGame(PlayersName.getName(0)); int[] gridSize = new int[2] { game.Height, game.Width }; gameGrid = new GameGrid(gridSize); game.AddDisplay(gameGrid); border.Child = gameGrid; outerGrid.Children.Add(border); border.SetValue(Grid.RowProperty, 1); border.SetValue(Grid.ColumnProperty, 1); // set left crocodile PicGen pic = new CrocodileGen(); PicGenGrid pg1 = new PicGenGrid(pic, SquareGenerator.picSquareSize); aCanvas.Children.Add(pg1); pg1.SetValue(Canvas.ZIndexProperty, 0); Canvas.SetLeft(pg1, (Styles.WindowSizeGenerator.screenWidth - gameGrid.getGameGridSize()[1]) / 6); Canvas.SetBottom(pg1, (Styles.WindowSizeGenerator.screenHeight - gameGrid.getGameGridSize()[0]) / 2 - 0.2 * pg1.getPicSize()[0]); // set right crocodile pic = new CrocodileGen(); PicGenGrid pg2 = new PicGenGrid(pic, SquareGenerator.picSquareSize); aCanvas.Children.Add(pg2); pg2.SetValue(Canvas.ZIndexProperty, 0); Canvas.SetRight(pg2, (Styles.WindowSizeGenerator.screenWidth - gameGrid.getGameGridSize()[1]) / 4); Canvas.SetBottom(pg2, (Styles.WindowSizeGenerator.screenHeight - gameGrid.getGameGridSize()[0]) / 2 - 0.2 * pg2.getPicSize()[0]); // set little sun pic = new SunGen(); PicGenGrid pg3 = new PicGenGrid(pic, SquareGenerator.picSquareSize / 1.1); aCanvas.Children.Add(pg3); pg3.SetValue(Canvas.ZIndexProperty, 0); Canvas.SetLeft(pg3, -40); Canvas.SetTop(pg3, -40); // set score board double scoreHeight = Styles.WindowSizeGenerator.scoreBoardHeight; double scoreWidth = Styles.WindowSizeGenerator.scoreBoardWidth; double scoreLeftLoc = Styles.WindowSizeGenerator.scoreBoardLeft + (Styles.WindowSizeGenerator.screenWidth + gameGrid.getGameGridSize()[1]) / 2; double scoreBottomLoc = gameGrid.getGameGridSize()[0] + Styles.WindowSizeGenerator.gameModuleTop - scoreHeight; score = new ScoreGrid(scoreHeight, scoreWidth); Grid scoreNextBlockGrid = new Grid(); aCol = new ColumnDefinition(); aCol.Width = new GridLength(0.5 * scoreWidth, GridUnitType.Pixel); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); RowDefinition aRow = new RowDefinition(); aRow.Height = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.RowDefinitions.Add(aRow); aRow = new RowDefinition(); aRow.Height = new GridLength(0.2 * scoreHeight, GridUnitType.Pixel); scoreNextBlockGrid.RowDefinitions.Add(aRow); aRow = new RowDefinition(); aRow.Height = new GridLength(1, GridUnitType.Star); scoreNextBlockGrid.RowDefinitions.Add(aRow); scoreNextBlockGrid.Children.Add(score); score.SetValue(Grid.ColumnProperty, 1); score.SetValue(Grid.RowProperty, 0); score.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); score.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); outerGrid.Children.Add(scoreNextBlockGrid); scoreNextBlockGrid.SetValue(Grid.ColumnProperty, 2); scoreNextBlockGrid.SetValue(Grid.RowProperty, 1); score.DataContext = game.ScoreSystem; // set next block board double nextBlockHeight = Styles.WindowSizeGenerator.nextBoardHeight; double nextBlockWidth = Styles.WindowSizeGenerator.nextBoardWidth; double nextLeftLoc = scoreLeftLoc; double nextBottomLoc = scoreBottomLoc + nextBlockHeight + 10; NextBlock nextBlock = new NextBlock(nextBlockHeight, nextBlockWidth); Console.WriteLine(nextBlockHeight + " block h"); double[] nextSize = nextBlock.getSize(); scoreNextBlockGrid.Children.Add(nextBlock); nextBlock.SetValue(Grid.RowProperty, 2); nextBlock.SetValue(Grid.ColumnProperty, 1); nextBlock.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); nextBlock.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); game.AddDisplay(nextBlock); aRect = new Rectangle(); aRect.Fill = new SolidColorBrush(Colors.Transparent); aRect.Width = gameGrid.getGameGridSize()[1]; aRect.Height = gameGrid.getGameGridSize()[0]; outerGrid.Children.Add(aRect); aRect.SetValue(Grid.ColumnProperty, 1); aRect.SetValue(Grid.RowProperty, 1); game.GameEndEvent += gameEndEffect; }