コード例 #1
0
        public void TestHashCode()
        {
            var dp1 = new DropPiece(new DropPieceSimple());
            var dp2 = new DropPiece(new DropPieceSimple());

            Assert.AreNotEqual(dp1.GetHashCode(), dp2.GetHashCode());
        }
コード例 #2
0
 public StateInfo(Playfield pf, DropPiece dp, float tl, StatsInfo si)
 {
     Playfield = pf;
     DropPiece = dp;
     Timeline  = tl;
     Stats     = si;
 }
コード例 #3
0
        public void TestDeepClone()
        {
            var dp1 = new DropPiece(new DropPieceSimple());
            var dp2 = dp1.DeepClone();

            Assert.AreNotSame(dp1, dp2);
            Assert.AreEqual(dp1, dp2);
        }
コード例 #4
0
        public void TestEquality()
        {
            var dp1 = new DropPiece(new DropPieceSimple());
            var dp2 = new DropPiece(new DropPieceSimple());

            Assert.AreEqual(dp1, dp2);
            Assert.AreEqual(dp1, dp1);
            Assert.AreNotEqual(null, dp1);
        }
コード例 #5
0
        public void TestConstructor()
        {
            var dp = new DropPiece();

            Assert.AreEqual(DropPiece.State.Whole, dp.CurrentState);
        }
コード例 #6
0
        public StateInfo GeneratePlayfield(DataTable table, bool resetSubscriptions)
        {
            float?timeLine  = null;
            var   statsInfo = new StatsInfo();


            // count columns and rows:
            int columnCount = -1;
            int rowCount    = 0;

            for (int ri = 0; ri < table.Rows.Count; ri++)
            {
                var    row = table.Rows[ri];
                string str = row[0].ToString();

                // skip rows with empty first columns:
                if (String.IsNullOrWhiteSpace(str))
                {
                    continue;
                }

                // see if we've reached the end:
                if (str.StartsWith("timeline"))
                {
                    timeLine = Convert.ToSingle(row[1]);
                    continue;
                }
                else if (str.StartsWith("frame"))
                {
                    statsInfo.Frame = Convert.ToInt32(row[1]);
                    continue;
                }
                else if (str.StartsWith("dropPieceDownDropRate"))
                {
                    statsInfo.DropPieceDownDropRate = Convert.ToSingle(row[1]);
                    continue;
                }
                else if (str.StartsWith("totalSquaresRemoved"))
                {
                    statsInfo.TotalSquaresRemoved = Convert.ToInt32(row[1]);
                    continue;
                }
                else if (str.StartsWith("totalNumEmptyColorBonuses"))
                {
                    statsInfo.TotalNumEmptyColorBonuses = Convert.ToInt32(row[1]);
                    continue;
                }
                else if (str.StartsWith("totalNumSingleColorBonuses"))
                {
                    statsInfo.TotalNumSingleColorBonuses = Convert.ToInt32(row[1]);
                    continue;
                }
                else if (str.StartsWith("frameSquaresRemoved"))
                {
                    statsInfo.FrameSquaresRemoved = Convert.ToInt32(row[1]);
                    continue;
                }
                else if (str.StartsWith("debuggerBreak"))
                {
                    statsInfo.DebuggerBreak = true;
                    continue;
                }
                else if (str.StartsWith("key"))
                {
                    break; // we stop processing
                }
                else if (String.IsNullOrWhiteSpace(str))
                {
                    continue;
                }

                ++rowCount;

                // count columns - don't trust library as it
                // sometimes reports more columns than expected:
                for (int c = 0; c < table.Columns.Count; c++)
                {
                    var col = row[c].ToString();
                    // skip rows with empty first columns:
                    if (String.IsNullOrWhiteSpace(col))
                    {
                        columnCount = Math.Max(c, columnCount);
                        break;
                    }
                }
            }

            // column count matches library's count:
            if (columnCount < 0)
            {
                columnCount = table.Columns.Count;
            }

            var pf = new Playfield(columnCount, rowCount);

            if (resetSubscriptions)
            {
                pf.ResetSubscriptions();
            }

            DropPiece dp = null;

            // fill playfield:
            int r = 0;
            int?columnDropPieceStart = null, rowDropPieceStart = null;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                var row = table.Rows[i];
                if (r >= rowCount)
                {
                    break;
                }

                // skip rows with empty first columns:
                if (String.IsNullOrWhiteSpace(row[0].ToString()))
                {
                    continue;
                }

                if (Keywords.Contains(row[0]))
                {
                    r++;
                    continue;
                }
                int c = 0;
                for (int j = 0; j < columnCount; j++)
                {
                    var column = row[j];
                    var columnStr = column.ToString();
                    int dpCol = 0, dpRow = 0;

                    if (String.IsNullOrWhiteSpace(columnStr))
                    {
                        continue;
                    }

                    if (columnStr.StartsWith("DP_"))
                    {
                        if (columnDropPieceStart == null)
                        {
                            columnDropPieceStart = c;
                        }
                        if (rowDropPieceStart == null)
                        {
                            rowDropPieceStart = r;
                        }
                        dpCol = c - (int)columnDropPieceStart;
                        dpRow = r - (int)rowDropPieceStart;

                        if (dp == null)
                        {
                            dp = new DropPiece(new DropPieceSimple());
                            if (statsInfo.DropPieceDownDropRate != null)
                            {
                                dp.DownDropRate = statsInfo.DropPieceDownDropRate;
                            }
                        }
                        dp.Positions[dpCol] = new PlayfieldPoint(c, r);
                    }


                    var columnSplit = columnStr.Split('_');
                    switch (columnSplit[0])
                    {
                    case "D":
                        pf.Cells[c][r].State = Logic.Cell.States.Disabled;
                        break;

                    case "E":
                        pf.Cells[c][r].State = Logic.Cell.States.Empty;
                        break;

                    case "B":
                        pf.Cells[c][r].State = Logic.Cell.States.Black;
                        break;

                    case "W":
                        pf.Cells[c][r].State = Logic.Cell.States.White;
                        break;

                    case "BW":
                        pf.Cells[c][r].State = Logic.Cell.States.BlackAndWhite;
                        break;

                    // jeweled
                    case "JB":
                        pf.Cells[c][r].State = Logic.Cell.States.BlackJeweledBoth;
                        break;

                    case "JHB":
                        pf.Cells[c][r].State = Logic.Cell.States.BlackJeweledHorz;
                        break;

                    case "JVB":
                        pf.Cells[c][r].State = Logic.Cell.States.BlackJeweledVert;
                        break;

                    case "JW":
                        pf.Cells[c][r].State = Logic.Cell.States.WhiteJeweledBoth;
                        break;

                    case "JHW":
                        pf.Cells[c][r].State = Logic.Cell.States.WhiteJeweledHorz;
                        break;

                    case "JVW":
                        pf.Cells[c][r].State = Logic.Cell.States.WhiteJeweledVert;
                        break;

                    // drop piece
                    case "DP":
                    {
                        switch (columnSplit[1])
                        {
                        case "W":
                            dp.Cells[dpCol][dpRow] = Logic.Cell.States.White;
                            break;

                        case "B":
                            dp.Cells[dpCol][dpRow] = Logic.Cell.States.Black;
                            break;

                        case "JW":
                            dp.Cells[dpCol][dpRow] = Logic.Cell.States.WhiteJeweledBoth;
                            break;

                        case "JB":
                            dp.Cells[dpCol][dpRow] = Logic.Cell.States.BlackJeweledBoth;
                            break;
                        }
                    }
                    break;

                    default:
                    {
                        var sb = new System.Text.StringBuilder();
                        sb.AppendLine($"Unknown column type '{columnSplit[0]}' from '" +
                                      $"{columnStr}' at column {j }, row {i}");
                        sb.AppendLine($"in Worksheet '{table}'");
                        throw new InvalidDataException(sb.ToString());
                    }
                    }

                    c++;
                }
                r++;
            }

            // second pass - set remove states after cell states are set:
            r = 0;
            columnDropPieceStart = null; rowDropPieceStart = null;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                var row = table.Rows[i];
                if (r >= rowCount)
                {
                    break;
                }

                // skip rows with empty first columns:
                if (String.IsNullOrWhiteSpace(row[0].ToString()))
                {
                    continue;
                }

                if (Keywords.Contains(row[0]))
                {
                    r++;
                    continue;
                }
                int c = 0;
                for (int j = 0; j < table.Columns.Count; j++)
                {
                    var column    = row[j];
                    var columnStr = column.ToString();

                    var columnSplit = columnStr.Split('_');
                    if (columnSplit[0] != "DP" && columnSplit.Length == 2)
                    {
                        switch (columnSplit[1])
                        {
                        case "NR":
                            pf.Cells[c][r].RemoveState = Logic.Cell.RemoveStates.NotRemoved;
                            break;

                        case "WR":
                            pf.Cells[c][r].RemoveState = Logic.Cell.RemoveStates.WillBeRemoved;
                            break;

                        case "RM":
                            pf.Cells[c][r].RemoveState = Logic.Cell.RemoveStates.Removing;
                            break;

                        case "JW":
                            pf.Cells[c][r].RemoveState = Logic.Cell.RemoveStates.JewelWillBeRemoved;
                            break;

                        case "JR":
                            pf.Cells[c][r].RemoveState = Logic.Cell.RemoveStates.JewelRemoving;
                            break;

                        default:
                            throw new InvalidDataException($"unknown remove state '{columnSplit[1]}'");
                        }
                    }
                    c++;
                }
                r++;
            }
            return(new StateInfo(pf, dp, (float)timeLine, statsInfo));
        }
コード例 #7
0
 public void RemoveDropPiece(DropPiece dP)
 {
     //audioManager.PlaySFXClip("getItem");
     dropPiecesList.Remove(dP);
 }