Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="battleships.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="525" Width="525" ResizeMode="NoResize">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="520" MaxWidth="520" MinWidth="520"/>
- <ColumnDefinition Width="0*"/>
- </Grid.ColumnDefinitions>
- <TextBlock x:Name="maintext" Loaded="Output_Loaded" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Text="asd" Foreground="Black" FontSize="18" TextDecorations="{x:Null}" FontFamily="Arial" TextAlignment="Center"/>
- <Button x:Name="startBtn" Height="26" HorizontalAlignment="Left" Margin="403,0,0,0"
- VerticalAlignment="Bottom"
- Width="106" Click="startGame">Start Game</Button>
- </Grid>
- </Window>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Text.RegularExpressions;
- namespace battleships
- {
- public partial class MainWindow : Window
- {
- private Random rand;
- private int[,] field;
- private Regex reg;
- private TextBlock output;
- private Button Buttons;
- private Dictionary<string, Button> ButtonDict = new Dictionary<string, Button>();
- public MainWindow()
- {
- InitializeComponent();
- this.rand = new Random();
- this.reg = new Regex(@"^\d,\d$", RegexOptions.IgnoreCase);
- this.CreateField();
- }
- private void Output_Loaded(object sender, RoutedEventArgs e)
- {
- this.output = sender as TextBlock;
- }
- private void startGame(object sender, EventArgs e)
- {
- Button clicked = (Button)sender;
- clicked.Content = "Restart";
- this.output.Text = "The enemy has placed his ships. Ready your weapons";
- this.createButtons();
- }
- private void createButtons()
- {
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- Button newButton = new Button();
- ButtonDict.Add(i + "," + j , newButton);
- }
- }
- }
- private void CreateField()
- {
- // setup empty field
- this.field = new int[10, 10] {
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0}
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment