Exemplo n.º 1
0
 public static Game CreateGame(BoardWindow window, string name)
 {
     Game game = stringBoards.ContainsKey(name)
                     ? CreateGame(window, stringBoards[name])
                     : CreateGame(window, intBoards[name]);
     return game;
 }
        /// <summary>
        /// Method to go back to the precedent page
        /// </summary>
        private async Task GoBack()
        {
            BoardWindow page = new BoardWindow(UserServices, AlertServices, MaterialServices, ProductServices, MaterialsProductServices, SaleServices, await AlertServices.CountAlerts());

            page.Show();
            CurrentPage.Close();
        }
Exemplo n.º 3
0
        private void Open(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog
                {
                    DefaultExt = ".LIF",
                    Filter = "Game of Life Patterns (.LIF)|*.LIF",
                    Multiselect = true
                };

            var result = openFileDialog.ShowDialog(this);
            if (result != true) return;

            Parallel.ForEach(openFileDialog.FileNames, path =>
                {
                    var lifePattern = LifeParser.ParseFile(path);

                    var name = Path.GetFileNameWithoutExtension(path);

                    Dispatcher.BeginInvoke(new Action(() =>
                        {
                            var window = new BoardWindow(name);
                            BoardFactory.CreateGame(window, lifePattern).Start();

                            window.Show();
                        }));
                });
        }
Exemplo n.º 4
0
    public static void OpenWindow()
    {
        BoardWindow myWindow = (BoardWindow)GetWindow(typeof(BoardWindow));

        myWindow.wantsMouseMove = true;
        myWindow.Show();
    }
Exemplo n.º 5
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            userService = new UserService();
            taskService = new TaskService();
            try
            {
                var user = await userService.Login(new AuthenticateRequest(passwordBox.Password, usernameBox.Text));

                if (user != null)
                {
                    var tasks = await taskService.GetTasks();

                    var viewModel = new ObservableCollection <TaskViewModel>(tasks.Select(t => new TaskViewModel(t)));

                    BoardWindow boardWindow = new BoardWindow();
                    boardWindow.DataContext = new BoardViewModel(user, viewModel);
                    boardWindow.Show();
                    Close();
                }
                else
                {
                    MessageBox.Show("Please enter login data again");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please enter login data again");
            }
        }
Exemplo n.º 6
0
        public static Game CreateGame(BoardWindow window, LifePattern pattern)
        {
            int w = pattern.Width;
            int h = pattern.Height;

            var board = new GameBoard(window, w, h);
            var game  = new Game(board, window.Generation, pattern.HasRules ? pattern.Rules : LifeRules.Normal);

            window.Game = game;

            foreach (var block in pattern.Blocks)
            {
                for (int y = 0; y < block.Lines.Count; y++)
                {
                    for (int x = 0; x < block.Lines[y].Count; x++)
                    {
                        var isAlive = block.Lines[y][x];
                        if (isAlive)
                        {
                            game.InitAlive(block.OffsetX + x, block.OffsetY + y);
                        }
                    }
                }
            }

            return(game);
        }
Exemplo n.º 7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            BoardWindow win = new BoardWindow(boardId, username);

            win.Show();
            this.Close();
        }
Exemplo n.º 8
0
        public static Game CreateGame(BoardWindow window, string name)
        {
            Game game = stringBoards.ContainsKey(name)
                            ? CreateGame(window, stringBoards[name])
                            : CreateGame(window, intBoards[name]);

            return(game);
        }
Exemplo n.º 9
0
 public void ShowBoard(Board board)
 {
     _boardWindow             = new BoardWindow();
     _boardWindow.DataContext = new BoardViewModel {
         BoardWindow = _boardWindow, Board = board
     };
     _boardWindow.Show();
     _mainWindow.Close();
 }
Exemplo n.º 10
0
        public void StartGame()
        {
            GameSettingsWindow gameSettingsWindow = new GameSettingsWindow();

            if (gameSettingsWindow.ShowDialog() == DialogResult.OK)
            {
                GameState   gameState   = new GameState(gameSettingsWindow.BoardSize, gameSettingsWindow.IsTwoPlayers);
                BoardWindow boardWindow = new BoardWindow(gameState);
                gameState.InitForNewGame();
                boardWindow.ShowDialog();
            }
        }
Exemplo n.º 11
0
        private void Start(object sender, RoutedEventArgs e)
        {
            var button = (Button)sender;

            var name = button.Content.ToString();
            var window = new BoardWindow(name);

            Game game = BoardFactory.CreateGame(window, name);
            game.Start();

            window.Show();
        }
Exemplo n.º 12
0
        public void ShowBoard(Board board)
        {
            _boardWindow = new BoardWindow {
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };
            _boardWindow.SourceInitialized += (s, a) => _boardWindow.WindowState = WindowState.Maximized;
            _boardWindow.DataContext        = new BoardViewModel {
                BoardWindow = _boardWindow, Board = board
            };
            _boardWindow.Show();

            _mainWindow?.Close();
        }
Exemplo n.º 13
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                chooseBoardRowInput bwr = choose.SelectedBoard;

                BoardWindow win = new BoardWindow(bwr.boardId, choose.Username);
                win.Show();
                this.Close();
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 14
0
        public static Game CreateGame(BoardWindow window, string[] state)
        {
            int w = state[0].Length;
            int h = state.Length;
            var board = new GameBoard(window, w + 4, h + 4);
            var game = new Game(board, window.Generation);
            window.Game = game;
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    bool alive = state[y][x] == 'x';
                    if (alive)
                    {
                        game.InitAlive(x + 2, y + 2);
                    }
                }
            }

            return game;
        }
Exemplo n.º 15
0
        public static Game CreateGame(BoardWindow window, int[,] state)
        {
            int w = state.GetLength(1);
            int h = state.GetLength(0);
            var board = new GameBoard(window, w + 4, h + 4);
            var game = new Game(board, window.Generation);
            window.Game = game;
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    bool alive = state[y, x] == 1;
                    if (alive)
                    {
                        game.InitAlive(x + 2, y + 2);
                    }
                }
            }

            return game;
        }
Exemplo n.º 16
0
        public static Game CreateGame(BoardWindow window, string[] state)
        {
            int w     = state[0].Length;
            int h     = state.Length;
            var board = new GameBoard(window, w + 4, h + 4);
            var game  = new Game(board, window.Generation);

            window.Game = game;
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    bool alive = state[y][x] == 'x';
                    if (alive)
                    {
                        game.InitAlive(x + 2, y + 2);
                    }
                }
            }

            return(game);
        }
Exemplo n.º 17
0
        public static Game CreateGame(BoardWindow window, int[,] state)
        {
            int w     = state.GetLength(1);
            int h     = state.GetLength(0);
            var board = new GameBoard(window, w + 4, h + 4);
            var game  = new Game(board, window.Generation);

            window.Game = game;
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    bool alive = state[y, x] == 1;
                    if (alive)
                    {
                        game.InitAlive(x + 2, y + 2);
                    }
                }
            }

            return(game);
        }
Exemplo n.º 18
0
        private void StartRandom(object sender, RoutedEventArgs e)
        {
            var name = "Random";
            var window = new BoardWindow(name);

            int width = int.Parse(RandomWidth.Text, NumberFormatInfo.InvariantInfo);
            int height = int.Parse(RandomHeight.Text, NumberFormatInfo.InvariantInfo);
            double prob = double.Parse(RandomProbability.Text, NumberFormatInfo.InvariantInfo);
            int seed = int.Parse(RandomSeed.Text, NumberFormatInfo.InvariantInfo);
            int[,] b = new int[width, height];
            var rand = new Random(seed);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    b[x, y] = rand.NextDouble() < prob ? 1 : 0;
                }
            }
            var game = BoardFactory.CreateGame(window, b);
            game.Start();

            window.Show();
        }
Exemplo n.º 19
0
 private static void OpenBoardWindow()
 {
     BoardWindow.Init();
 }
Exemplo n.º 20
0
 public GameBoard(BoardWindow window, int width, int height)
 {
     _window = window;
     Cells = new Cell[width, height];
     SetDrawingSize(width, height);
 }