Esempio n. 1
0
 public void Sudoku_Moved(object sender, SudokuMoveEvent e)
 {
     Console.Write("Sudoku_Moved : ");
     Console.WriteLine(e);
     Invalidate();
 }
Esempio n. 2
0
        private void UC_SudokuGrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (m_cellHover.X == -1 && m_cellHover.Y == -1) return;

            if ((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) ||(e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9))
            {
                int valeur = e.KeyValue - (e.KeyCode <= Keys.D9 ? (int)Keys.D0 : (int)Keys.NumPad0);
                //m_Model.Update(m_cellHover.X, m_cellHover.Y, new Cell(CellFlag.SAISIE,valeur) );

                SudokuMoveEvent levent=new SudokuMoveEvent(new Move(m_cellHover.X ,m_cellHover.Y, new Cell(),new Cell(CellFlag.SAISIE,valeur)));
                SudokuMoved(this.m_Model, levent);
                return;

            }else if (!m_freezSelection)
            {
                if (e.KeyCode == Keys.Up)
                {
                    Point tmp = m_cellHover;

                    while (tmp.X > -1 && tmp.Y > -1)
                    {
                        if (tmp.X > 0)
                        {
                            tmp.X--;
                        }
                        else if (tmp.Y > 0)
                        {
                            tmp.X = GRID_SIZE - 1;
                            //tmp.Y--;
                        }
                        else
                        {
                            tmp.X =  GRID_SIZE - 1;
                        }

                        Cell cell = m_Model.GetCell(tmp.X, tmp.Y);
                        if (cell.CellValeur == 0)
                        {
                            m_cellHover = tmp;
                            e.SuppressKeyPress = true;
                            this.Invalidate();
                            break;
                        }

                        if (m_cellHover.X == tmp.X)
                        {//Tout les champs sont remplies
                            m_cellHover.X = -1;
                            m_cellHover.Y = -1;
                            break;
                        }
                    }
                }
                else if (e.KeyCode == Keys.Down)
                {
                    Point tmp = m_cellHover;

                    while (tmp.X < GRID_SIZE && tmp.Y < GRID_SIZE)
                    {
                        if (tmp.X < GRID_SIZE - 1)
                            tmp.X++;
                        else if (tmp.Y < GRID_SIZE - 1)
                        {
                            tmp.X = 0;
                            //tmp.Y++;
                        }
                        else
                        {
                            tmp.X =  0;
                        }

                        Cell cell = m_Model.GetCell(tmp.X, tmp.Y);
                        if (cell.CellValeur == 0)
                        {
                            m_cellHover = tmp;
                            this.Invalidate();
                            break;
                        }

                        if (m_cellHover.X == tmp.X)
                        {//Tout les champs sont remplies
                            m_cellHover.X = -1;
                            m_cellHover.Y = -1;
                            break;
                        }
                    }
                }
                else if (e.KeyCode == Keys.Left)
                {
                    Point tmp = m_cellHover;

                    while (tmp.X > -1 && tmp.Y > -1)
                    {
                        if (tmp.Y > 0)
                            tmp.Y--;
                        else if (tmp.X > 0)
                        {
                            tmp.Y = GRID_SIZE - 1;
                            //tmp.X--;
                        }
                        else
                        {
                            tmp.X = tmp.Y = GRID_SIZE - 1;
                        }

                        Cell cell = m_Model.GetCell(tmp.X, tmp.Y);
                        if (cell.CellValeur == 0)
                        {
                            m_cellHover = tmp;
                            this.Invalidate();
                            break;
                        }

                        if (m_cellHover.Y == tmp.Y)
                        {//Tout les champs sont remplies
                            m_cellHover.X = -1;
                            m_cellHover.Y = -1;
                            break;
                        }
                    }
                }
                else if (e.KeyCode == Keys.Right)
                {
                    Point tmp = m_cellHover;

                    while (tmp.X < GRID_SIZE && tmp.Y < GRID_SIZE)
                    {
                        if (tmp.Y < GRID_SIZE - 1)
                            tmp.Y++;
                        else if (tmp.X < GRID_SIZE - 1)
                        {
                            tmp.Y = 0;
                            //tmp.X++;
                        }
                        else
                        {
                            tmp.X = tmp.Y = 0;
                        }

                        Cell cell = m_Model.GetCell(tmp.X, tmp.Y);
                        if (cell.CellValeur == 0)
                        {
                            m_cellHover = tmp;
                            this.Invalidate();
                            break;
                        }

                        if (m_cellHover.Y == tmp.Y)
                        {//Tout les champs sont remplies
                            m_cellHover.X = -1;
                            m_cellHover.Y = -1;
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void SudokuMoved(object sender, SudokuMoveEvent e)
        {
            PDUpdateCellRequest pd = new PDUpdateCellRequest(MainForm.GetInstance().gamePanel.currentTable.TableID,
                (uint)MainForm.GetInstance().LocalPlayer.Id,
                (ushort)(e.theMove.line * 9 + e.theMove.column),
                (ushort)e.theMove.newValue.CellValeur);

            MainForm.GetInstance().SudokuClient.sendPacket(pd);
        }