private void TwoZeroFourEightView_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyValue)
            {
            case 37:
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                break;

            case 38:
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                break;

            case 39:
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                break;

            case 40:
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                break;
            }

            lblScore.Text = model.ScoreTotal().ToString();

            if (model.Game_over())
            {
                lblShow.Text = "GameOver";
            }
            else
            {
                lblShow.Text = "";
            }
        }
Exemplo n.º 2
0
        //private KeyPressEventHandler kpeh;
        //private KeyEventHandler keh;

        private void key_Press(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 'w') // (char)Keys.Up)
            {
                controller.ActionPerformed(TwoZeroFourEightController.UP);
            }
        }
        // protected void key_Press(object sneder , EventArgs e)
        // {

        // }
        //protected void key_Down(object sender , EventArgs e)
        // {

        //  }
        //the own method to bevexcuted when the event occurs.
        private void key_Press(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 'w')
            {
                controller.ActionPerformed(TwoZeroFourEightController.UP);
            }
            //check if allow key up is pressed then call something to perform UP
            //
        }
Exemplo n.º 4
0
        private void botton_Click(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.W: controller.ActionPerformed(TwoZeroFourEightController.UP); break;

            case Keys.A: controller.ActionPerformed(TwoZeroFourEightController.LEFT); break;

            case Keys.D: controller.ActionPerformed(TwoZeroFourEightController.RIGHT); break;

            case Keys.S: controller.ActionPerformed(TwoZeroFourEightController.DOWN); break;
            }
        }
Exemplo n.º 5
0
        private void TwoZeroFourEightView_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyData)
            {
            case Keys.W:
            case Keys.Up:
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                //btnUp.Focus();

                break;

            case Keys.S:
            case Keys.Down:
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                //btnDown.Focus();
                break;

            case Keys.A:
            case Keys.Left:
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                //btnLeft.Focus();
                break;

            case Keys.D:
            case Keys.Right:
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                //btnRight.Focus();
                break;
            }
        }
        private void key_Down(object sender, KeyEventArgs e)
        {
            // todo : check if arrow key xx is down then call something to perform xx
            if (e.KeyData == Keys.Right || e.KeyData == Keys.D)
            {
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                //btnRight.Focus();
            }
            else if (e.KeyData == Keys.Left || e.KeyData == Keys.A)
            {
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                //btnLeft.Focus();
            }
            else if (e.KeyData == Keys.Up || e.KeyData == Keys.W)
            {
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                //btnUp.Focus();
            }
            else if (e.KeyData == Keys.Down || e.KeyData == Keys.S)
            {
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                //btnDown.Focus();
            }

            //switch(e.KeyData)
            //{
            //    case Keys.Right:
            //    case Keys.D:
            //        controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
            //        btnRight.Focus();
            //        break;
            //}
        }
Exemplo n.º 7
0
        private void TwoZeroFourEightView_KeyDown(object sender, KeyEventArgs e)
        {
            if (KeyPreview == true)
            {
                switch (e.KeyData)
                {
                case Keys.Up:
                case Keys.W:
                    controller.ActionPerformed(TwoZeroFourEightController.UP);
                    break;

                case Keys.Down:
                case Keys.S:
                    controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                    break;

                case Keys.Left:
                case Keys.A:
                    controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                    break;

                case Keys.Right:
                case Keys.D:
                    controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                    break;
                }
            }
        }
        private void UDLR(object sender, PreviewKeyDownEventArgs e)
        {
            e.IsInputKey = true;
            switch (e.KeyCode)
            {
            case Keys.Up:
                btnUp.Focus();
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                break;

            case Keys.Down:
                btnDown.Focus();
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                break;

            case Keys.Left:
                btnLeft.Focus();
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                break;

            case Keys.Right:
                btnRight.Focus();
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                break;
            }
        }
 public TwoZeroFourEightView()
 {
     InitializeComponent();
     model = new TwoZeroFourEightModel();
     model.AttachObserver(this);
     controller = new TwoZeroFourEightController();
     controller.AddModel(model);
     controller.ActionPerformed(TwoZeroFourEightController.LEFT);
 }
 public TwoZeroFourEightView()
 {
     InitializeComponent();
     model = new TwoZeroFourEightModel();
     model.AttachObserver(this);
     controller = new TwoZeroFourEightController();
     controller.AddModel(model);
     controller.ActionPerformed(TwoZeroFourEightController.LEFT);
 }
Exemplo n.º 11
0
 private void TwoZeroFourEightView_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Right || e.KeyCode == Keys.D)
     {
         controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
     }
     else if (e.KeyCode == Keys.Left || e.KeyCode == Keys.A)
     {
         controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     }
     else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.W)
     {
         controller.ActionPerformed(TwoZeroFourEightController.UP);
     }
     else if (e.KeyCode == Keys.Down || e.KeyCode == Keys.S)
     {
         controller.ActionPerformed(TwoZeroFourEightController.DOWN);
     }
 }
 public TwoZeroFourEightView()
 {
     InitializeComponent();
     model = new TwoZeroFourEightModel();
     model.AttachObserver(this);
     controller = new TwoZeroFourEightController();
     controller.AddModel(model);
     controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     textBox1.KeyDown += new KeyEventHandler(OnKeyDownHandler);
 }
Exemplo n.º 13
0
 private void KeyDownHandler(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Left)
     {
         controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     }
     else if (e.KeyCode == Keys.Up)
     {
         controller.ActionPerformed(TwoZeroFourEightController.UP);
     }
     else if (e.KeyCode == Keys.Right)
     {
         controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
     }
     else if (e.KeyCode == Keys.Down)
     {
         controller.ActionPerformed(TwoZeroFourEightController.DOWN);
     }
 }
        private void Left()
        {
            bool check = false;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 3; j > 0; j--)
                {
                    if (((TwoZeroFourEightModel)model).GetBoard()[i, j] == ((TwoZeroFourEightModel)model).GetBoard()[i, j - 1] || ((TwoZeroFourEightModel)model).GetBoard()[i, j] == 0)
                    {
                        check = true;
                    }
                }
            }
            if (check == true)
            {
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
            }
        }
Exemplo n.º 15
0
        public int sum; //add by me

        public TwoZeroFourEightView()
        {
            InitializeComponent();
            model = new TwoZeroFourEightModel();
            model.AttachObserver(this);
            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);
            labelGameOver.Visible = false;
            KeyPreview            = true;
        }
 private new void KeyDown(object sender, KeyEventArgs e)
 {
     textBox1.Hide();
     ScoreLb.Show();
     if (e.KeyCode == Keys.Left)
     {
         controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     }
     if (e.KeyCode == Keys.Right)
     {
         controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
     }
     if (e.KeyCode == Keys.Up)
     {
         controller.ActionPerformed(TwoZeroFourEightController.UP);
     }
     if (e.KeyCode == Keys.Down)
     {
         controller.ActionPerformed(TwoZeroFourEightController.DOWN);
     }
 }
        private void _calendar_PreviewKey(object sender, PreviewKeyDownEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Down:
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                break;

            case Keys.Right:
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                break;

            case Keys.Up:
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                break;

            case Keys.Left:
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                break;
            }
        }
 public TwoZeroFourEightView()
 {
     InitializeComponent();
     model = new TwoZeroFourEightModel();
     model.AttachObserver(this);
     controller = new TwoZeroFourEightController();
     controller.AddModel(model);
     controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     // Form ScoreBoard = new Form();
     //ScoreBoard.IsMdiContainer = true;
     // ScoreBoard.Show();
 }
        TwoZeroFourEightScoreView scoreview; //สร้างสกอร์วิว

        #endregion Fields

        #region Constructors

        public TwoZeroFourEightView()
        {
            InitializeComponent();
            model = new TwoZeroFourEightModel();
            model.AttachObserver(this);
            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);
            scoreview = new TwoZeroFourEightScoreView(); //การสร้างสกอร์ ชี้ไปที่คลาส 2048
            scoreview.Visible = true;
            scoreview.Enabled = true;
        }
        private void Keyboard(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Up:
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                break;

            case Keys.Down:
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                break;

            case Keys.Right:
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                break;

            case Keys.Left:
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                break;
            }
        }
 public TwoZeroFourEightView()
 {
     InitializeComponent();
     model = new TwoZeroFourEightModel();
     model.AttachObserver(this);
     controller = new TwoZeroFourEightController();
     controller.AddModel(model);
     controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     scoreView = new ShowScore(model);
     scoreView.Visible = true;
     scoreView.Enabled = true;
 }
Exemplo n.º 22
0
        public TwoZeroFourEightView()
        {
            KeyPreview = true;
            InitializeComponent();
            TextBox Text = new TextBox();

            this.Controls.Add(Text);
            model = new TwoZeroFourEightModel();
            model.AttachObserver(this);
            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);
        }
Exemplo n.º 23
0
        public TwoZeroFourEightView()
        {
            InitializeComponent();
            TextBox tb = new TextBox();

            this.Controls.Add(tb); // keyboard controll
            tb.KeyDown += new KeyEventHandler(Form1_KeyDown);
            model       = new TwoZeroFourEightModel();
            model.AttachObserver(this);
            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);
        }
Exemplo n.º 24
0
 public TwoZeroFourEightView()
 {
     InitializeComponent();
     model = new TwoZeroFourEightModel();
     model.AttachObserver(this);
     model.AttachObserver(a);
     controller = new TwoZeroFourEightController();
     controller.AddModel(model);
     controller.ActionPerformed(TwoZeroFourEightController.LEFT);
        // a.Text = "TwoZeroFourEightScoreView";
     //a.Controls.Add(new Label() { Name = "lblScore" ,Text = "Hello"});
        // a.label1.Text = "Hello";
     a.Show();
 }
 private void btnUp_Click(object sender, KeyEventArgs b)
 {
     if (model.checkgameover() == true)
     {
         MessageBox.Show("Game Over", "", MessageBoxButtons.OK);
     }
     if (b.KeyCode == Keys.Up)
     {
         controller.ActionPerformed(TwoZeroFourEightController.UP);
     }
     else if (b.KeyCode == Keys.Left)
     {
         controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     }
     else if (b.KeyCode == Keys.Right)
     {
         controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
     }
     else if (b.KeyCode == Keys.Down)
     {
         controller.ActionPerformed(TwoZeroFourEightController.DOWN);
     }
 }
        public TwoZeroFourEightView()
        {
            InitializeComponent();
            model = new TwoZeroFourEightModel();
            model.AttachObserver(this);

            ScoreVeiw = new TwoZeroFourEightScoreView();
            ScoreVeiw.Visible = false;
            ScoreVeiw.Enabled = false;

            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);
        }
Exemplo n.º 27
0
        private void TwoZeroFourEightView_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyData)
            {
            case Keys.W:
            case Keys.Up:
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                label1.Visible = isFull2;
                label2.Visible = isFull2;
                break;

            case Keys.S:
            case Keys.Down:
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                label1.Visible = isFull2;
                label2.Visible = isFull2;

                break;

            case Keys.D:
            case Keys.Right:
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                label1.Visible = isFull2;
                label2.Visible = isFull2;

                break;

            case Keys.A:
            case Keys.Left:
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                label1.Visible = isFull2;
                label2.Visible = isFull2;

                break;
            }
        }
Exemplo n.º 28
0
        private void btnUp_KeyDown(object sender, KeyEventArgs e)
        {
            bool check = model.isOver();

            if (!check)
            {
                if (e.KeyCode == Keys.Right)
                {
                    controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                    int score = model.GetScore();
                    lblDisplay.Text = score.ToString();
                }
                else if (e.KeyCode == Keys.Left)
                {
                    controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                    int score = model.GetScore();
                    lblDisplay.Text = score.ToString();
                }
                else if (e.KeyCode == Keys.Up)
                {
                    controller.ActionPerformed(TwoZeroFourEightController.UP);
                    int score = model.GetScore();
                    lblDisplay.Text = score.ToString();
                }
                else if (e.KeyCode == Keys.Down)
                {
                    controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                    int score = model.GetScore();
                    lblDisplay.Text = score.ToString();
                }
            }
            else
            {
                lblDisplay.Text = "Game Over!";
            }
        }
        public TwoZeroFourEightView()
        {
            InitializeComponent();
            model = new TwoZeroFourEightModel();
            model.AttachObserver(this);
            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);

            //kp = new KeyPressEventHandler(key_Press);
            //this.KeyPress += kp;
            // kd = new KeyEventHandler(key_Down);
            this.KeyDown += new KeyEventHandler(key_Down); // this works only when the control(form) has focus
            // you can also use anonymous EventHandler like this...
            // this.KeyPress += new KeyPressEventHandler(yourMethod);
        }
        public TwoZeroFourEightView()
        {
            InitializeComponent();
            model = new TwoZeroFourEightModel();
            model.AttachObserver(this);
            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);

            //kpeh = new KeyPressEventHandler(key_Press);
            // this.KeyPress += kpeh; //this works only when the contro (form) has focus

            keh           = new KeyEventHandler(key_Down);
            this.KeyDown += keh;   //this works only when the control (form) has focus

            // this.KeyPress += new KeyPressEventHandler(key_Press); //create object
        }
Exemplo n.º 31
0
 protected void Arrow(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Up)
     {
         controller.ActionPerformed(TwoZeroFourEightController.UP);
     }
     else if (e.KeyCode == Keys.Down)
     {
         controller.ActionPerformed(TwoZeroFourEightController.DOWN);
     }
     else if (e.KeyCode == Keys.Left)
     {
         controller.ActionPerformed(TwoZeroFourEightController.LEFT);
     }
     else
     {
         controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
     }
 }
Exemplo n.º 32
0
        public TwoZeroFourEightView()
        {
            InitializeComponent();
            this.BackColor = Color.FromArgb(115, 220, 235);
            model          = new TwoZeroFourEightModel();
            model2048      = new TwoZeroFourEightModel();
            model.AttachObserver(this);
            controller = new TwoZeroFourEightController();
            controller.AddModel(model);
            controller.ActionPerformed(TwoZeroFourEightController.LEFT);

            /*this.Focus();
             * kpeh = new KeyPressEventHandler(key_Press);
             * this.KeyPress += kpeh;
             *
             * keh = new KeyEventHandler(key_Down);
             * this.KeyDown += keh;*/
        }
        private void btnAll_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            switch (btn.Text)
            {
            case "←":
                controller.ActionPerformed(TwoZeroFourEightController.LEFT);
                break;

            case "↑":
                controller.ActionPerformed(TwoZeroFourEightController.UP);
                break;

            case "→":
                controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
                break;

            case "↓":
                controller.ActionPerformed(TwoZeroFourEightController.DOWN);
                break;
            }
        }
 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
 {
     if (keyData == Keys.Up)
     {
         controller.ActionPerformed(TwoZeroFourEightController.UP);
         return(true);
     }
     if (keyData == Keys.Down)
     {
         controller.ActionPerformed(TwoZeroFourEightController.DOWN);
         return(true);
     }
     if (keyData == Keys.Left)
     {
         controller.ActionPerformed(TwoZeroFourEightController.LEFT);
         return(true);
     }
     if (keyData == Keys.Right)
     {
         controller.ActionPerformed(TwoZeroFourEightController.RIGHT);
         return(true);
     }
     return(base.ProcessCmdKey(ref msg, keyData));
 }
 private void btnLeft_Click(object sender, EventArgs e)
 {
     if (((TwoZeroFourEightModel)model).GetOver() == true)
     {
         if (Stop == true)
         {
             controller.ActionPerformed(TwoZeroFourEightController.LEFT);
             Stop = false;
         }
         return;
     }
     controller.ActionPerformed(TwoZeroFourEightController.LEFT);
 }