Exemplo n.º 1
0
        /// <summary>
        /// Setting the viewmodel
        /// </summary>
        /// <param name="m"></param>
        public void SetVM(MazeViewModel m)
        {
            myVM             = m as MultiViewModel;
            this.DataContext = myVM;
            MultiMazeModel tempModel = myVM.MyModel as MultiMazeModel;

            //Delegate for moving opponent's player on his board
            tempModel.OpponentMoved += delegate(Object sender, Key e)
            {
                int close = 10;
                this.Dispatcher.Invoke(() =>
                {
                    close = OpponentBoard.MovePlayer(e);

                    //Opponent won
                    if (close == -1 || close == 2)
                    {
                        LoserWindow lw = new LoserWindow();
                        lw.ShowDialog();
                        BackToMain();
                    }
                    //Opponent closed game
                    if (close == -2)
                    {
                        OtherPlayerQuit();
                    }
                });
            };
            myVM.VM_Maze = myVM.MyModel.MazeString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts the game created by the player
        /// </summary>
        /// <param name="sender">window</param>
        /// <param name="e">none</param>
        private void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            waitingWindow ww = new waitingWindow();

            ww.Show();
            MultiMazeModel m = myVM.MyModel as MultiMazeModel;

            m.StartGame("start");
            MultiGame mg = new MultiGame();

            mg.SetVM(myVM);
            myVM.VM_GameList = null;
            ww.Close();
            mg.Show();
            this.Close();
        }
Exemplo n.º 3
0
        /// <summary>
        /// constructor
        /// </summary>
        public MultiStartWindow()
        {
            InitializeComponent();
            MultiMazeModel m       = new MultiMazeModel();
            int            success = m.Connect();

            if (success < 0)
            {
                ConnectionFailedWindow c = new ConnectionFailedWindow();
                c.Show();
            }
            if (success >= 0)
            {
                m.GetListOfGames();
                myVM                     = new MultiViewModel(m);
                DataContext              = myVM;
                GameInfo.btnStart.Click += BtnStart_Click;
                this.Show();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Joins the game selected in the comboBox
        /// </summary>
        /// <param name="sender">This window</param>
        /// <param name="e">sd</param>
        private void JoinClicked(object sender, RoutedEventArgs e)
        {
            MultiMazeModel m       = myVM.MyModel as MultiMazeModel;
            int            success = m.Connect();

            if (success < 0)
            {
                ConnectionFailedWindow c = new ConnectionFailedWindow();
                c.Show();
            }
            if (success >= 0)
            {
                GameInfo.btnStart.Click += BtnStart_Click;
                this.Show();
                m.GetListOfGames();
                m.StartGame("join");
                MultiGame mg = new MultiGame();
                mg.SetVM(myVM);
                mg.Show();
                this.Close();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Moving player by pressed key
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Board_KeyDown(object sender, KeyEventArgs e)
        {
            int check;
            Key k = e.Key;

            check = Board.MovePlayer(k);
            Position       pos;
            MultiMazeModel tempModel = myVM.MyModel as MultiMazeModel;

            switch (k)
            {
            case Key.Left:
                tempModel.MovePlayer("Left");
                break;

            case Key.Right:
                tempModel.MovePlayer("Right");
                break;

            case Key.Up:
                tempModel.MovePlayer("Up");
                break;

            case Key.Down:
                tempModel.MovePlayer("Down");
                break;
            }
            //checks whether player won the game
            if (check == 3)
            {
                FinishWindow fw = new FinishWindow();
                fw.ShowDialog();
                myVM.MyModel.CloseGame();
                fw.sPlayer.Stop();
                BackToMain();
                fw.Close();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Moves the player on the maze
        /// in a certain direction
        /// </summary>
        /// <param name="direction"> which way to move</param>
        public void MovePlayer(string direction)
        {
            MultiMazeModel m = MyModel as MultiMazeModel;

            m.MovePlayer(direction);
        }