Exemplo n.º 1
0
        public Wood(int ID, int X, int Y, int tAmount, int mAmount)
        {
            this.ID       = ID;
            this.X        = X;
            this.Y        = Y;
            this.map      = new Bitmap(X * this.Scale, Y * this.Scale);
            this.Graphics = Graphics.FromImage(this.map);
            this.Log      = new Log(Program.ExportPath, DateTime.Now.ToString("yyyy-MM-dd") + "_" + this.ID + "_log.txt");

            Program.printHeader();
            Console.WriteLine("Start logging wood " + ID);
            Console.WriteLine("--------------------");
            this.log("Started generating map...");

            Random r = new Random();

            for (int i = 0; i < tAmount; i++)
            {
                Tree tree = new Tree(this.Trees.Count, r.Next(0, this.X), r.Next(0, this.Y));
                while (this.Trees.Contains(tree))
                {
                    tree = new Tree(this.Trees.Count, r.Next(0, this.X), r.Next(0, this.Y));
                }
                this.Trees.Add(tree);
                this.drawTree(tree);
            }

            this.log("Map generated with " + tAmount + " trees");

            Task.Run(() => this.saveTreesThread());

            this.log("Start generating monkeys...");

            for (int i = 0; i < mAmount; i++)
            {
                Tree start = this.Trees[r.Next(this.Trees.Count)];
                while (this.Monkeys.Any(x => x.Start == start))
                {
                    start = this.Trees[r.Next(this.Trees.Count)];
                }
                Monkey monkey = new Monkey(this.Monkeys.Count, Program.monkeyNames[this.Monkeys.Count], start);
                this.Monkeys.Add(monkey);
                drawStartTree(monkey);
                this.log($"[ID: {monkey.ID}] New monkey {monkey.Name}, {Program.monkeyColors[monkey.ID].ToString()}");
            }

            this.log("Monkey generation done, generated " + mAmount + " monkeys");
            Thread.Sleep(500);
            this.moveMonkeys();

            while (this.Monkeys.Any(x => x.Done == false))
            {
            }
            Thread.Sleep(5);
            foreach (Monkey monkey in this.Monkeys)
            {
                Task.Run(() => this.saveMonkeyThread(monkey));
            }
            Task.Run(() => this.saveDataLogThread());
            this.log("Start drawing paths...");
            this.generateImagePath();
            this.log("Paths drawed on map");
            this.saveToImage(Program.ExportPath);
            this.Log.stopLogging();

            Thread.Sleep(500);
            Console.WriteLine(" ");
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
Exemplo n.º 2
0
 private void saveMonkeyThread(Monkey monkey)
 {
     this.log($"Saving monkey [ID: {monkey.ID}] to database...");
     DatabaseManager.logMonkeys(this.ID, monkey);
     this.log($"Monkey [ID: {monkey.ID}] saved to database");
 }