Esempio n. 1
0
 public static bool Equal( Row r1, Row r2 )
 {
     return ( r1.Pegs == r2.Pegs ) && ( r1.Pegs == 0 || r1.Color == r2.Color );
 }
Esempio n. 2
0
        private static void Sub( Row rowFrom, Row rowTo )
        {
            rowTo.Color = ( rowTo.Pegs > rowFrom.Pegs ? rowTo.Color : rowFrom.Color );
            rowTo.Pegs = Math.Abs( rowFrom.Pegs - rowTo.Pegs );

            rowFrom.Pegs = 0;
        }
Esempio n. 3
0
        private static void Swap( Row rowFrom, Row rowTo )
        {
            Color colorFrom = rowFrom.Color;
            Color colorTo = rowTo.Color;
            int pegsFrom = rowFrom.Pegs;
            int pegsTo = rowTo.Pegs;

            rowFrom.Color = colorTo;
            rowTo.Color = colorFrom;
            rowFrom.Pegs = pegsTo;
            rowTo.Pegs = pegsFrom;
        }
Esempio n. 4
0
        private static void DoMoveUp( Row rowFrom, Row rowTo )
        {
            if ( rowFrom.IsEmpty )
                return;

            if ( rowTo.IsBar )
            {
                if ( rowFrom.IsBar )
                    ChangeColor( rowFrom, rowTo );
            }
            else if ( rowTo.IsEmpty )
            {
                if ( rowFrom.IsEven )
                    Split( rowFrom, rowTo );
            }
            else if ( rowFrom.IsBar )
            {
                Swap( rowFrom, rowTo );
            }
            else
            {
                Add( rowFrom, rowTo );
            }
        }
Esempio n. 5
0
        private static void Split( Row rowFrom, Row rowTo )
        {
            rowTo.Pegs = rowFrom.Pegs / 2;
            rowFrom.Pegs = rowTo.Pegs;

            rowFrom.Color = NextColor( rowFrom.Color );
            rowTo.Color = NextColor( rowFrom.Color );
        }
Esempio n. 6
0
 private static void ChangeColor( Row rowFrom, Row rowTo )
 {
     rowTo.Color = NextColor( rowFrom.Color, rowTo.Color );
 }
Esempio n. 7
0
        private static void DoMoveDown( Row rowFrom, Row rowTo )
        {
            if ( rowFrom.IsEmpty )
                return;

            if ( rowTo.IsEmpty )
            {
                if ( rowFrom.IsEven )
                    Split( rowFrom, rowTo );
            }
            else
            {
                Sub( rowFrom, rowTo );
            }
        }
Esempio n. 8
0
        private static void Add( Row rowFrom, Row rowTo )
        {
            Color colorFrom, colorTo;
            int totalPegs, restPegs;

            if ( rowFrom.Pegs == rowTo.Pegs )
            {
                colorTo = NextColor( rowFrom.Color, rowTo.Color );
                colorFrom = rowTo.Color;
            }
            else if ( rowFrom.Pegs > rowTo.Pegs )
            {
                colorTo = rowFrom.Color;
                colorFrom = rowTo.Color;
            }
            else
            {
                colorTo = rowTo.Color;
                colorFrom = rowFrom.Color;
            }

            totalPegs = rowFrom.Pegs + rowTo.Pegs;
            restPegs = Math.Max( totalPegs - 4, 0 );
            totalPegs = Math.Min( totalPegs, 4 );

            rowTo.Color = colorTo;
            rowTo.Pegs = totalPegs;
            rowFrom.Color = colorFrom;
            rowFrom.Pegs = restPegs;
        }
Esempio n. 9
0
        public Panel Clone()
        {
            Row[] rows = new Row[m_Rows.Length];

            for ( int i = 0; i < m_Rows.Length; i++ )
                rows[i] = m_Rows[i].Clone();

            return new Panel( rows );
        }
Esempio n. 10
0
 public Panel( Row[] rows )
 {
     m_Rows = rows;
 }
Esempio n. 11
0
        private int GetGraphic( Row row )
        {
            bool bar = row.IsBar;

            switch ( row.Color )
            {
                default:
                case Color.Red: return bar ? 0x2A58 : 0x2A62;
                case Color.Green: return bar ? 0x2A44 : 0x2A4E;
                case Color.Blue: return bar ? 0x2A30 : 0x2A3A;
            }
        }
Esempio n. 12
0
        private void DrawRow( Row row, int xBase, int yBase )
        {
            int graphic = GetGraphic( row );

            switch ( row.Pegs )
            {
                default:
                case 0:
                    break;
                case 1: // 1 peg
                    AddImage( xBase + 40, yBase, graphic );
                    break;
                case 2: // 2 pegs
                    AddImage( xBase + 2, yBase, graphic );
                    AddImage( xBase + 80, yBase, graphic );
                    break;
                case 3: // 3 pegs
                    AddImage( xBase + 2, yBase, graphic );
                    AddImage( xBase + 40, yBase, graphic );
                    AddImage( xBase + 80, yBase, graphic );
                    break;
                case 4: // bar
                    AddImage( xBase + 1, yBase, graphic );
                    break;
            }
        }