public void TestPathFinder()
        {
            Graph graph            = new Graph(10, 10);
            Node  startDestinaton  = graph.getNode(1, 1);
            Node  finalDestination = graph.getNode(5, 5);

            System.Diagnostics.Debug.WriteLine(startDestinaton);

            BasicCreature creature = new BasicCreature(startDestinaton, finalDestination, graph, 100, 100, null);
            Mooving       mooving  = (Mooving)creature.getMoovnig();

            mooving.onStart();

            Node lastPosition = null;

            while (lastPosition != creature.getPosition())     //ked sa rovnaju posledny node a aktualny, znamena ze sa uz nehybem dalej
            {
                lastPosition = creature.getPosition();
                //najdi novu poziciu
                mooving.prepare();
                creature.action();
                System.Diagnostics.Debug.WriteLine(creature.getPosition());    //debug vypis noveho nodu
            }
            Assert.AreEqual(finalDestination, creature.getPosition());
        }
Beispiel #2
0
        void Button5Click(object sender, EventArgs e)
        {
            MessageBox.Show("SAVE GAME");
            string content          = "";
            string path             = "../SAVE.txt";
            List <ThinkingObject> w = world.getarrayOfObjectInGame();

            Node[,] nodes = graph.getNodes();

            for (int i = 0; i < nodes.GetLength(0); i++)
            {
                for (int j = 0; j < nodes.GetLength(1); j++)
                {
                    content += (nodes[i, j].getX() / 10).ToString() + " " + (nodes[i, j].getY() / 10).ToString() + " " + nodes[i, j].getTerrain().ToString() + " ";
                }
            }
            content += "\n";

            Console.WriteLine(content);
            for (int i = 0; i < w.Count; i++)
            {
                if (w[i].GetType() == typeof(BasicCreature))
                {
                    BasicCreature c = (BasicCreature)w[i];
                    content += "0 " + (c.getPosition().getX() / 10).ToString() + " " + (c.getPosition().getY() / 10).ToString() + " ";
                }
                else
                {
                    BasicTower c = (BasicTower)w[i];
                    content += "1 " + (c.getPosition().getX() / 10).ToString() + " " + (c.getPosition().getY() / 10).ToString() + " ";
                }
            }

            Console.WriteLine(content);
            File.WriteAllText(path, content);
        }