Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C# by dejv ( 15 years ago )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Ianimal;
using Herb;
using Factory;
using Iobserve;
using Iobserver;
using Peep;
using state;
using herd;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public class Symulator
{
public List<Herd> stada = new List<Herd>();
public Herd merge(Herd her, int nd)
{
Herd nowe = her;
for (int j = 0; j < stada[nd].herd.Count(); j++)
{
nowe.herdadd((IAnimal)stada[nd].herd[j]);
}
int ilosc = stada[nd].herd.Count();
stada[nd].herd.RemoveRange(0, ilosc);
for (int j = 0; j < 5; j++)
{
nowe.herdadd(new Herbivore());
}
return nowe;
}
public void run(AbstractAnimalFactory animalfactory)
{
Peeper lol = new Peeper();
for (int j = 0; j < 100; j++)
{
Random rand = new Random();
int x = rand.Next(0, 29);
int y = rand.Next(0, 29); ///tutaj masz parametry
stada.Add(new Herd(x, y));
// IAnimal animal = animalfactory.CreatePredator();
for (int k = 0; k < 100; k++) //tutaj sobie z text boxa ustaw
{
IAnimal animal = animalfactory.CreateHerbivore();
// gdzies tutaj rysowanie na podstawie x i y
animal.SetID(j);
stada[j].herdadd(animal);
}
}
stada[0].reqObserver(lol);
//stada[2].herd[10].reqObserver(lol);
while (1 == 1)
{
/// masz tam 100 stad ale tylko 0 sie uruchamia wiec zamien to na petle kazde stado ma cos takiego jak x i y to wpsolrzedne aby uruchomic to pod wpf to trzeba wrzucuc to w clasy a w glownym projekcie dodac using ConsoleApplication10
run(stada[0]);
Herd nowe = stada[0].herdsplit();
if (nowe.herd.Count != 0) stada.Add(nowe);
Random rand = new Random();
int place = rand.Next(1, 5);
switch (place)
{ //przesun na mapie tu trzeba odrysowac na innej
case 1: stada[0].x = stada[0].x - 1; break;
case 2: stada[0].x = stada[0].x + 1; break;
case 3: stada[0].y = stada[0].y + 1; break;
case 4: stada[0].y = stada[0].y - 1; break;
}
// if (stada[0].herd.Count()==10) Console.ReadKey();
if (stada[0].herd.Count() == 0) { stada.RemoveAt(0); Console.ReadKey(); Environment.Exit(1); } //usun z mapy
}
}
public void run(IAnimal har)
{
Random ran = new Random();
int lol = ran.Next(0, 4);
// if har.x
switch (lol)
{
case 1: har.eat(); break; //tutaj jak sie nachlaja nazra to pola aby zamienialy sie w pustynie
case 2: har.drink(); break;
case 3: har.move(); break;
// case 3: merge((Herd)har,2); break;
}
}
public static void Main(string[] args)
{
Symulator sym = new Symulator();
AbstractAnimalFactory animalfactory = new AnimalFactory();
sym.run(animalfactory);
Console.ReadKey();
}
}
public int pole = 30, moby,moby2, stadaa,stadaa2;
private static Random losowa = new Random();
public int[,] tab=new int[20,15];
public List<Herd> stada = new List<Herd>();
public void drawGrass()
{
Rectangle grass = new Rectangle();
grass.Width = pole;
grass.Height = pole;
SolidColorBrush zielony = new SolidColorBrush(Colors.DarkGreen);
grass.Fill = zielony;
grass.Stroke = Brushes.Black;
grass.StrokeThickness = 1;
wrapPanel1.Children.Add(grass);
}
public void drawPole()
{
Rectangle nic = new Rectangle();
nic.Width = pole;
nic.Height = pole;
SolidColorBrush zolty = new SolidColorBrush(Colors.LightGoldenrodYellow);
nic.Fill = zolty;
nic.Stroke = Brushes.Black;
nic.StrokeThickness = 1;
wrapPanel1.Children.Add(nic);
}
public void drawWoda()
{
Rectangle woda = new Rectangle();
woda.Width = pole;
woda.Height = pole;
SolidColorBrush niebieski = new SolidColorBrush(Colors.DarkBlue);
woda.Fill = niebieski;
woda.Stroke = Brushes.Black;
woda.StrokeThickness = 1;
wrapPanel1.Children.Add(woda);
}
public void drawMob()
{
Rectangle mob = new Rectangle();
mob.Width = pole;
mob.Height = pole;
SolidColorBrush czerwony = new SolidColorBrush(Colors.Red);
mob.Fill = czerwony;
mob.Stroke = Brushes.LightGoldenrodYellow;
mob.StrokeThickness = 5;
wrapPanel1.Children.Add(mob);
}
public void drawMob2()
{
Rectangle mob = new Rectangle();
mob.Width = pole;
mob.Height = pole;
SolidColorBrush czerwony = new SolidColorBrush(Colors.Red);
mob.Fill = czerwony;
mob.Stroke = Brushes.DarkGreen;
mob.StrokeThickness = 5;
wrapPanel1.Children.Add(mob);
}
public void drawStado()
{
Rectangle stado = new Rectangle();
stado.Width = pole;
stado.Height = pole;
SolidColorBrush brush = new SolidColorBrush(Colors.Black);
stado.Fill = brush;
stado.Stroke = Brushes.LightGoldenrodYellow;
stado.StrokeThickness = 7;
wrapPanel1.Children.Add(stado);
}
public void drawStado2()
{
Rectangle stado = new Rectangle();
stado.Width = pole;
stado.Height = pole;
SolidColorBrush brush = new SolidColorBrush(Colors.Black);
stado.Fill = brush;
stado.Stroke = Brushes.DarkGreen;
stado.StrokeThickness = 7;
wrapPanel1.Children.Add(stado);
}
public void wyczysc()
{
wrapPanel1.Children.Clear();
}
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = "Nom Nom moby zjadly stada !";
wyczysc();
moby = int.Parse(textBox2.Text);
stadaa = int.Parse(textBox3.Text);
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 15; j++)
{
if (tab[i, j] == 2 && stadaa2!=0 && moby2!=0)
{
drawMob2();
stadaa2--;
tab[i, j] = 1;
}
else if (tab[i, j] == 1 && moby2!=0)
{
drawGrass();
tab[i, j] = 5;
}
else if (tab[i, j] == 3)
drawWoda();
else if (tab[i, j] == 4)
drawPole();
else if (tab[i, j] == 5)
drawGrass();
}
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
moby = int.Parse(textBox2.Text);
moby2 = moby;
stadaa = int.Parse(textBox3.Text);
stadaa2 = stadaa;
int min = 1, max = 100;
int liczba;
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 15; j++)
{
liczba = losowa.Next(min, max);
if (liczba < 3 && moby != 0)
{
drawMob();
tab[i, j] = 1;
moby--;
}
else if (liczba > 90 && stadaa != 0)
{
drawStado2();
tab[i, j] = 2;
stadaa--;
}
else if (liczba > 80 && liczba < 90)
{
drawWoda();
tab[i, j] = 3;
}
else if (liczba > 50 && liczba < 80)
{
drawPole();
tab[i, j] = 4;
}
else
{
drawGrass();
tab[i, j] = 5;
}
}
}
button2.IsEnabled = false;
textBox2.IsEnabled = false;
textBox3.IsEnabled = false;
}
private void wrapPanel1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point mousePoint = Mouse.GetPosition(this);
double x = mousePoint.X;
x = x - 67;
double y = mousePoint.Y;
y = y - 62;
double nr1,nr2;
textBox4.Text = (x + " , "+ y);
nr1 = x / 30;
int numer1 = Convert.ToInt32(nr1);
if (numer1 > 20)
numer1 = 20;
nr2 = y / 30;
int numer2 = Convert.ToInt32(nr2);
if (numer2 > 20)
numer2 = 20;
textBox5.Text = (numer1 + " , " + numer2);
if (tab[numer1, numer2] == 2)
textBox1.Text = "kliknales na stado";
else
textBox1.Text = "";
textBox6.Text = ("kliknales na: " + tab[numer1, numer2]);
textBox7.Text = "Stado liczy sobie 6 osobnikow";
}
private void button3_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = "";
wyczysc();
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 15; j++)
{
tab[i, j] = 0;
}
}
button2.IsEnabled = true;
textBox2.IsEnabled = true;
textBox3.IsEnabled = true;
}
}
}
Revise this Paste