Example #1
0
    void PlacingResourcesToMotherBase()
    {
        //暫時
        if (antMiningActivity == AntMiningActivityState.returnToBase)
        {
            inAttackRange = gameModel.instance.Vector2IntEquality(motherBase.instance.InMapV3Pos, InMapV3Pos);
            if (inAttackRange)
            {
                if (inventory > 0)
                {
                    //礦未用完就跟motherBase新路徑內容
                    motherBase.instance.addNewMinePath(pathRecord);
                }
                gameModel.instance.resource += inventory;
                inventory = 0;

                //清空記憶
                pathRecord = new WalkingPath();

                inAttackRange     = false;
                antMiningActivity = AntMiningActivityState.none;
                antActivity       = AntActivityState.WalkingAround;

                GetComponent <SpriteRenderer>().color = normalStateColor;
            }
        }
    }
        public void Path_With_Unique_Node_Values_Is_Valid()
        {
            var path = new WalkingPath<int>();
            path.Step(new GraphNode<int> { Value = 1 });
            path.Step(new GraphNode<int> { Value = 2 });
            path.Step(new GraphNode<int> { Value = 3 });

            Assert.IsTrue(path.IsValid, "Path with unique node values should be valid");
        }
Example #3
0
    public WalkingPath deepCopyOutputWP()
    {
        List <Vector2Int> newV2List = new List <Vector2Int>();

        newV2List.AddRange(path);
        WalkingPath outputData = new WalkingPath(newV2List);

        outputData.serialNumber = serialNumber;
        return(outputData);
    }
Example #4
0
 void TranPathInfo(MinerAnt target)
 {
     //給自己全新記錄
     //  target.pathRecord = new WalkingPath(pathRecord);
     pathRecord = new WalkingPath(target.pathRecord);
     //target.pathCounter = pathCounter;
     pathCounter = pathRecord.path.Count - 1;
     //target.Destination = pathRecord.path[ pathCounter ];
     // target.startLerpToDestination();
 }
        public void Path_With_Non_Unique_Node_Value_Is_Invalid()
        {
            var path = new WalkingPath<int>();

            path.Step(new GraphNode<int> { Value = 0});
            path.Step(new GraphNode<int> { Value = 1 });
            path.Step(new GraphNode<int> { Value = 2 });
            path.Step(new GraphNode<int> { Value = 1 });

            Assert.IsFalse(path.IsValid, "Path with non-unique node values should be invalid");
        }
Example #6
0
 public void Init()
 {
     if (GameManager.instance.mode == GameMode.TRANSIT || GameManager.instance.mode == GameMode.CAREER)
     {
         wp = paths.GetRandom();
         transform.eulerAngles = Vector3.zero;
         GetComponent <Rigidbody>().velocity        = Vector3.zero;
         GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
         transform.position = wp.start.position;
         dir = (wp.end.position - wp.start.position).normalized;
         transform.LookAt(transform.position + new Vector3(dir.x, 0, dir.z));
         canMove = true;
     }
 }
Example #7
0
    void recordPath()
    {
        switch (antMiningActivity)
        {
        case AntMiningActivityState.none:
            //如果根本很接近基地,就直接清空數據,當成重新在基地出發
            if (gameModel.instance.checkIsThereAPointNearby(InMapV3Pos, motherBase.instance.InMapV3Pos, 2))
            {
                pathRecord = new WalkingPath();
                pathRecord.path.Add(motherBase.instance.InMapV3Pos);
            }
            //記錄舊路徑
            pathRecord.path.Add(InMapV3Pos);
            break;

        default:
            break;
        }
    }
Example #8
0
    void CompareOthersMiningPathAndChooseBetterOne()
    {
        if (antMiningActivity != AntMiningActivityState.none)
        {
            return;
        }

        // if (antMiningActivity == AntMiningActivityState.returnToBase) {
        floorData curFloorData = gameModel.instance.getFloorDatas(InMapV3Pos);

        //ants_FollowMinePath
        for (int i = 0; i < curFloorData.ants.Count; i++)
        {
            MinerAnt item = curFloorData.ants[i].gameObject.GetComponent <MinerAnt>();
            if (!item)
            {
                break;
            }

            WalkingPath itemWalkingPath = item.pathRecord;
            if (itemWalkingPath.path.Count <= 0)
            {
                break;
            }

            /*
             * if (item.antMiningActivity != AntMiningActivityState.followTheMinePath) {
             *  continue;
             * }
             * if (item.pathRecord.serialNumber != pathRecord.serialNumber) {
             *  continue;
             * }
             */

            if ((itemWalkingPath.path.Count) < (pathRecord.path.Count))
            {
                //如果比較目標的掘礦路徑更為短 就偷他的
                TranPathInfo(item);
            }
        }
        // }
    }
Example #9
0
        private void CreateGrid()
        {
            //xml ontcijferen
            Field[,] Fields = new Field[columns, rows];
            int countrow = 0, countcolumn = 0;

            foreach (XmlNode node in xmldoc.SelectNodes("spel/map/row"))
            {
                string tempRow = node.SelectSingleNode("short").InnerText;

                string[] tempFields = tempRow.Split(';');
                foreach (string tempField in tempFields)
                {
                    Field temp = null;
                    switch (tempField)
                    {
                    case " ":
                        temp = null;
                        break;

                    case "F":
                        temp = new NormalField();
                        break;

                    case "W-r":
                        temp = new WaitingField(players[(int)PlayerColor.Red]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Red], temp));
                        players[(int)PlayerColor.Red].AddPin(temp.Pin);
                        break;

                    case "W-b":
                        temp = new WaitingField(players[(int)PlayerColor.Blue]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Blue], temp));
                        players[(int)PlayerColor.Blue].AddPin(temp.Pin);
                        break;

                    case "W-g":
                        temp = new WaitingField(players[(int)PlayerColor.Green]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Green], temp));
                        players[(int)PlayerColor.Green].AddPin(temp.Pin);
                        break;

                    case "W-e":
                        temp = new WaitingField(players[(int)PlayerColor.Yellow]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Yellow], temp));
                        players[(int)PlayerColor.Yellow].AddPin(temp.Pin);
                        break;

                    case "F-r":
                        temp = new FinishField(players[(int)PlayerColor.Red]);
                        break;

                    case "F-b":
                        temp = new FinishField(players[(int)PlayerColor.Blue]);
                        break;

                    case "F-g":
                        temp = new FinishField(players[(int)PlayerColor.Green]);
                        break;

                    case "F-e":
                        temp = new FinishField(players[(int)PlayerColor.Yellow]);
                        break;

                    case "F-F-b":
                        temp = new ExitField(players[(int)PlayerColor.Blue]);
                        break;

                    case "F-F-g":
                        temp = new ExitField(players[(int)PlayerColor.Green]);
                        break;

                    case "F-F-r":
                        temp = new ExitField(players[(int)PlayerColor.Red]);
                        break;

                    case "F-F-e":
                        temp = new ExitField(players[(int)PlayerColor.Yellow]);
                        break;

                    case "F-S-b":
                        temp = new StartField(players[(int)PlayerColor.Blue]);
                        players[(int)PlayerColor.Blue].StartField = temp;
                        break;

                    case "F-S-g":
                        temp = new StartField(players[(int)PlayerColor.Yellow]);
                        players[(int)PlayerColor.Green].StartField = temp;
                        break;

                    case "F-S-r":
                        temp = new StartField(players[(int)PlayerColor.Red]);
                        players[(int)PlayerColor.Red].StartField = temp;
                        break;

                    case "F-S-e":
                        temp = new StartField(players[(int)PlayerColor.Yellow]);
                        players[(int)PlayerColor.Yellow].StartField = temp;
                        break;

                    case "|":
                        temp = new WalkingPath("Vertical", "");
                        break;

                    case "-":
                        temp = new WalkingPath("Horizontal", "");
                        break;

                    case "\\":
                        temp = new WalkingPath("Vertical", "Block");
                        break;

                    case "/":
                        temp = new WalkingPath("Horizontal", "Block");
                        break;
                    }
                    if (Fields != null)
                    {
                        Fields[countrow, countcolumn] = temp;
                    }
                    countcolumn++;
                }
                countcolumn = 0;
                countrow++;
            }

            //koppelen van de velden.
            Field  firstField;
            Field  lastField;
            string position = "";
            string dotted   = "";

            //eerste veld opsporen
            for (int y = 0; y < columns; y++)
            {
                for (int x = 0; x < rows; x++)
                {
                    if (Fields[x, y] != null)
                    {
                        if (Fields[x, y].GetType() == typeof(WalkingPath))
                        {
                            switch (Fields[x, y].direction)
                            {
                            case "Vertical":
                                firstField = Fields[x - 1, y];
                                lastField  = Fields[x + 1, y];
                                position   = "Vertical";
                                dotted     = Fields[x, y].dotted;
                                break;

                            case "Horizontal":
                                firstField = Fields[x, y - 1];
                                lastField  = Fields[x, y + 1];
                                position   = "Horizontal";
                                dotted     = Fields[x, y].dotted;
                                break;
                            }

                            if (position.Equals("Vertical"))
                            {
                                if ((columns) / 2 < y)
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    else
                                    {
                                        //firstField.SetNext(lastField);
                                    }
                                }
                                else
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }

                                    /*else if (firstField.FieldName == "ExitField" && lastField.FieldName == "FinishField")
                                     * {
                                     *  ((ExitField)firstField).Exit = lastField;
                                     * }
                                     * else if (firstField.FieldName == "FinishField" && lastField.FieldName == "ExitField")
                                     * {
                                     *  ((ExitField)lastField).Exit = firstField;
                                     * }*/
                                    else
                                    {
                                        //lastField.SetNext(firstField);
                                    }
                                }
                            }
                            else
                            {
                                if ((rows) / 2 < x)
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    else
                                    {
                                        //lastField.SetNext(firstField);
                                    }
                                }
                                else
                                {
                                    if (dotted.Equals("Block")) // finish field
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }

                                    /*else if (lastField.FieldName == "ExitField" && firstField.FieldName == "FinishField")
                                     * {
                                     *  ((ExitField)lastField).Exit = firstField;
                                     * }
                                     * else if (firstField.FieldName == "ExitField" && lastField.FieldName == "FinishField")
                                     * {
                                     *  ((ExitField)firstField).Exit = lastField;
                                     * }*/
                                    else
                                    {
                                        //firstField.SetNext(lastField);
                                    }
                                }
                            }
                        }
                        else if (Fields[x, y].GetType() == typeof(WaitingField))
                        {
                            foreach (Player p in players)
                            {
                                if (Fields[x, y].Player == p)
                                {
                                    Fields[x, y].SetNext(p.StartField);
                                }
                            }
                        }
                    }
                }
            }

            //grid tekenen
            int        cellBig = 40, cellSmall = 28;
            GridLength CellSizeBig   = new GridLength(cellBig);
            GridLength CellSizeSmall = new GridLength(cellSmall);

            for (int x = 0; x < rows; x++)
            {
                ColumnDefinition colDef = new ColumnDefinition();
                if (x % 2 == 0)
                {
                    colDef.Width = CellSizeBig;
                }
                else
                {
                    colDef.Width = CellSizeSmall;
                }
                FieldGrid.ColumnDefinitions.Add(colDef);
            }

            for (int y = 0; y < columns; y++)
            {
                RowDefinition rowDef = new RowDefinition();
                if (y % 2 == 0)
                {
                    rowDef.Height = CellSizeBig;
                }
                else
                {
                    rowDef.Height = CellSizeSmall;
                }
                FieldGrid.RowDefinitions.Add(rowDef);
            }

            //Grid koppelen
            for (int y = 0; y < columns; y++)
            {
                for (int x = 0; x < rows; x++)
                {
                    if (Fields[y, x] != null)
                    {
                        if (Fields[y, x].GetType() == typeof(WalkingPath))
                        {
                            Image smallpic = new Image();

                            smallpic.Height = cellSmall;
                            smallpic.Width  = cellSmall;

                            smallpic.SetValue(Grid.RowProperty, y);
                            smallpic.SetValue(Grid.ColumnProperty, x);

                            //Fields[y, x].SetImage(smallpic);
                            FieldGrid.Children.Add(smallpic);
                        }
                        else
                        {
                            RoundButton button = new RoundButton(Fields[y, x], vm);

                            button.SetValue(Grid.RowProperty, y);
                            button.SetValue(Grid.ColumnProperty, x);

                            //Fields[y, x].SetButton(button);
                            FieldGrid.Children.Add(button);
                        }
                    }
                }
            }

            // grid kleuren
            foreach (Field fieldd in Fields)
            {
                //if(fieldd != null) fieldd.setButtonColor();
            }
        }
Example #10
0
 public WalkingPath(WalkingPath WP)
 {
     deepCopyWriteIn(WP.path);
     serialNumber = WP.serialNumber;
 }
Example #11
0
 public void addNewMinePath(WalkingPath path)
 {
     newWalkPathToMineReport = path;
     OnNewMinePathFinded();
 }