Exemplo n.º 1
0
        public Row NewHeaderRow()
        {
            var row = new Row();
            row.Id = 0;

            new GameColors().NewGameRandomColors(row);

            return row;
        }
Exemplo n.º 2
0
        public void NewGameRandomColors(Row headerRow)
        {
            List<int> selectedNumbers = new List<int>();
            Random r = new Random(DateTime.Now.Millisecond);

            while (true)
            {
                var number = r.Next(1, 6);

                if (!selectedNumbers.Contains(number) && number != 0)
                {
                    selectedNumbers.Add(number);
                }

                if (selectedNumbers.Count(x => x != 0) == 4)
                {
                    break;
                }
            }

            headerRow.Field1 = Field.NewField(1, colors[selectedNumbers[0]]);
            headerRow.Field2 = Field.NewField(2, colors[selectedNumbers[1]]);
            headerRow.Field3 = Field.NewField(3, colors[selectedNumbers[2]]);
            headerRow.Field4 = Field.NewField(4, colors[selectedNumbers[3]]);
        }
Exemplo n.º 3
0
        public Row NewRow(byte id)
        {
            var row = new Row();

            row.Id = id;

            row.Field1 = Field.NewField(1);
            row.Field2 = Field.NewField(2);
            row.Field3 = Field.NewField(3);
            row.Field4 = Field.NewField(4);

            return row;
        }
Exemplo n.º 4
0
        public void Reset()
        {
            rows.Clear();

            // Add Details Empty Rows
            for (byte i = 1; i <= 9; i++)
            {
                rows.Add(new Row().NewRow(i));
            }

            currentRow = rows.Last();
            this.GameState = StateEnum.NewGame;
            this.CurrentScore.Reset();
            this.dtm.Start();
        }
Exemplo n.º 5
0
        public void OnColorClick(Brush color)
        {
            if (this.Paused)
                return;

            StateEnum state = RowFilledState();

            switch (state)
            {
                case StateEnum.GameOverSuccess:
                    return;
                case StateEnum.RowFilled:
                    this.currentRow = this.rows.FirstOrDefault(x => x.Id == this.currentRow.Id - 1);
                    if (this.currentRow != null)
                    {
                        var clr = new SolidColorBrush(Colors.White);

                        OnColorClick(color);
                    }
                    else
                    {
                        return;
                    }

                    break;
            }

            // fill each field with color.
            if (state == StateEnum.FieldEmpty)
                state = SetFieldBrush(this.currentRow.Field1, color);
            if (state == StateEnum.FieldEmpty)
                state = SetFieldBrush(this.currentRow.Field2, color);
            if (state == StateEnum.FieldEmpty)
                state = SetFieldBrush(this.currentRow.Field3, color);
            if (state == StateEnum.FieldEmpty)
            {
                state = SetFieldBrush(this.currentRow.Field4, color);
                // Get Hint
                var headerRow = this.headerRow.First();
                GetHint(headerRow.Field1, this.currentRow.Field1);
                GetHint(headerRow.Field2, this.currentRow.Field2);
                GetHint(headerRow.Field3, this.currentRow.Field3);
                GetHint(headerRow.Field4, this.currentRow.Field4);

                // Check Game over condition
                if (IsGameOver())
                {
                    state = StateEnum.GameOverSuccess;
                    this.GameState = StateEnum.GameOverSuccess;
                    // Game over
                }
                else if (this.currentRow.Id == this.rows.Min(i=> i.Id))
                {
                    state = StateEnum.GameOverFailure;
                    this.GameState = StateEnum.GameOverFailure;
                    // Game over
                }
            }
        }