예제 #1
0
 public override void UdelejKrok()
 {
     if (honim && zivy)
     {
         Policko novyKrok = Mapa.VratNejPolickoSmeremKPacmanovi(y, x);
         if (novyKrok != null)
         {
             CoTamBylo(novyKrok.y, novyKrok.x);
             Mapa.PresunPriserku(this, y, x, novyKrok.y, novyKrok.x);
             y = novyKrok.y;
             x = novyKrok.x;
             //AktualizujCoJePodDuchem();
         }
     }
     else if (zivy)
     {
         Utec();
     }
     else
     {
         if (oziveniTimer == 0)
         {
             Ozivni();
         }
         else
         {
             oziveniTimer--;
         }
     }
 }
예제 #2
0
 public Duch(int puvY, int puvX)
 {
     UzJsemVenku   = false;
     honim         = true;
     zivy          = true;
     puvSouradnice = new Policko(puvY, puvX);
 }
예제 #3
0
        /*public void AktualizujCoJePodDuchem()
         * {
         *
         *  char co = this.podDuchem;
         *
         *  if (co == 'J' || co == 'B' || co == 'V' || co == 'G') Mapa.coByloPodDuchemModrym = co;
         *  else
         *  {
         *      while (co != 'J' && co != 'B' && co != 'V' && co != 'G')
         *      {
         *          switch (co)
         *          {
         *              case '1':
         *                  co = Mapa.coByloPodDuchemOranzovym;
         *                  break;
         *              case '2':
         *                  co = Mapa.coByloPodDuchemCervenym;
         *                  break;
         *              case '3':
         *                  co = Mapa.coByloPodDuchemRuzovym;
         *                  break;
         *              case '4':
         *                  co = Mapa.coByloPodDuchemModrym;
         *                  break;
         *              default:
         *                  break;
         *          }
         *
         *      }
         *      Mapa.coByloPodDuchemModrym = co;
         *  }
         * }*/

        public void Utec()
        {
            if (!Mapa.JePacman(y, x))
            {
                if (paritaKroku % 2 == 0)
                {
                    List <Policko> mozneTahy = new List <Policko>();
                    Policko        novyTah   = new Policko(0, 0);

                    if (!Mapa.JeStena(y - 1, x))
                    {
                        mozneTahy.Add(new Policko(y - 1, x));
                    }
                    if (!Mapa.JeStena(y + 1, x))
                    {
                        mozneTahy.Add(new Policko(y + 1, x));
                    }
                    if (!Mapa.JeStena(y, x - 1))
                    {
                        mozneTahy.Add(new Policko(y, x - 1));
                    }
                    if (!Mapa.JeStena(y, x + 1))
                    {
                        mozneTahy.Add(new Policko(y, x + 1));
                    }

                    if (mozneTahy.Count > 1)
                    {
                        Policko pom = Mapa.VratNejPolickoSmeremKPacmanovi(y, x);
                        if (pom != null)
                        {
                            Policko spatnePole = mozneTahy.First(p => p.x == pom.x && p.y == pom.y);
                            mozneTahy.Remove(spatnePole);
                        }
                        Random generator    = new Random();
                        int    nahodneCislo = generator.Next(mozneTahy.Count);
                        novyTah = mozneTahy[nahodneCislo];
                    }
                    else
                    {
                        novyTah = mozneTahy.First();
                    }
                    Mapa.PresunPriserku(this, y, x, novyTah.y, novyTah.x);
                    x = novyTah.x;
                    y = novyTah.y;
                    paritaKroku++;
                }
                else
                {
                    paritaKroku++;
                }
            }
            else
            {
                Zmiz();
            }
        }
예제 #4
0
        public static void NactiMapu()
        {
            pohyblivePrvky = new List <PohyblivyPrvek>();
            System.IO.StreamReader sr = new System.IO.StreamReader("mapa.txt");
            sirka            = int.Parse(sr.ReadLine());
            vyska            = int.Parse(sr.ReadLine());
            mapa             = new char[vyska, sirka];
            mapaJidlaABonusu = new char[vyska, sirka];
            mapaVObrazcich   = new PictureBox[vyska, sirka];
            sr.ReadLine();
            dx = Form1.sirkaFormulare / sirka;
            dy = Form1.vyskaFormulare / vyska - 4;

            for (int y = 0; y < vyska; y++)
            {
                string radek = sr.ReadLine();
                for (int x = 0; x < sirka; x++)
                {
                    char znak = radek[x];
                    mapa[y, x]           = znak;
                    mapaVObrazcich[y, x] = new PictureBox();
                    PictureBox pomBox = mapaVObrazcich[y, x];
                    pomBox.Parent          = Form.ActiveForm;
                    pomBox.Height          = dy;
                    pomBox.Width           = dx;
                    pomBox.Top             = dy * y + 40;
                    pomBox.Left            = dx * x;
                    pomBox.Visible         = true;
                    pomBox.BackColor       = Color.Black;
                    mapaJidlaABonusu[y, x] = 'V';

                    switch (znak)
                    {
                    case 'P': Pacman pacMan = new Pacman(y, x);
                        souradnicePacmana = new Policko(y, x);
                        puvP = new Policko(y, x);
                        pohyblivePrvky.Add(pacMan);
                        break;

                    case '1':
                        DuchOranzovy D_Oran = new DuchOranzovy(y, x, '<');
                        puvO = new Policko(y, x);
                        pohyblivePrvky.Add(D_Oran);
                        break;

                    case '2':
                        DuchCerveny D_Cerv = new DuchCerveny(y, x);
                        puvC = new Policko(y, x);
                        pohyblivePrvky.Add(D_Cerv);
                        break;

                    case '3':
                        DuchRuzovy D_Ruz = new DuchRuzovy(y, x);
                        pohyblivePrvky.Add(D_Ruz);
                        break;

                    case '4':
                        DuchModry D_Mod = new DuchModry(y, x, '>');
                        puvM = new Policko(y, x);
                        pohyblivePrvky.Add(D_Mod);
                        break;

                    //jeste promyslet co s jidlem
                    case 'J':
                        KolikZbyvaJidla++;
                        mapaJidlaABonusu[y, x] = 'J';
                        break;

                    case 'B':
                        KolikZbyvaBonusu++;
                        mapaJidlaABonusu[y, x] = 'B';
                        break;

                    case 'G':
                        mapaJidlaABonusu[y, x] = 'G';
                        break;

                    default:
                        break;
                    }
                }
            }
            sr.Close();
        }
예제 #5
0
        public static Policko VratNejPolickoSmeremKPacmanovi(int zY, int zX)
        {
            //algoritmus vlny
            int[,] pole = new int[vyska, sirka];

            for (int j = 0; j < vyska; j++)
            {
                for (int i = 0; i < sirka; i++)
                {
                    if (JeStena(j, i))
                    {
                        pole[j, i] = -10;
                    }
                    else
                    {
                        pole[j, i] = -5;
                    }
                }
            }
            int             vyslX = 0, vyslY = 0;
            int             y = 0, x = 0;
            bool            nasliJsme = false;
            Queue <Policko> fronta    = new Queue <Policko>();

            fronta.Enqueue(new Policko(zY, zX));
            pole[zY, zX] = 0;
            while (!nasliJsme && fronta.Count > 0)
            {
                Policko novePolicko = fronta.Dequeue();
                y = novePolicko.y;
                x = novePolicko.x;
                if (JePacman(y, x))
                {
                    nasliJsme = true;
                    vyslY     = y;
                    vyslX     = x;
                }
                else
                {
                    if (pole[y + 1, x] == -5)
                    {
                        fronta.Enqueue(new Policko(y + 1, x));
                        pole[y + 1, x] = pole[y, x] + 1;
                    }
                    if (pole[y - 1, x] == -5)
                    {
                        fronta.Enqueue(new Policko(y - 1, x));
                        pole[y - 1, x] = pole[y, x] + 1;
                    }
                    if (pole[y, x + 1] == -5)
                    {
                        fronta.Enqueue(new Policko(y, x + 1));
                        pole[y, x + 1] = pole[y, x] + 1;
                    }
                    if (pole[y, x - 1] == -5)
                    {
                        fronta.Enqueue(new Policko(y, x - 1));
                        pole[y, x - 1] = pole[y, x] + 1;
                    }
                }
            }
            if (nasliJsme)
            {
                //najdeme cestu z (zY,zX) do (vyslY, vyslX)
                Stack <Policko> cesta      = new Stack <Policko>();
                int             delkaCesty = pole[vyslY, vyslX];
                y = vyslY;
                x = vyslX;
                cesta.Push(new Policko(vyslY, vyslX));
                for (int l = delkaCesty - 1; l > 0; l--)
                {
                    if (pole[y + 1, x] == l)
                    {
                        cesta.Push(new Policko(y + 1, x));
                        y++;
                    }
                    else if (pole[y - 1, x] == l)
                    {
                        cesta.Push(new Policko(y - 1, x));
                        y--;
                    }
                    else if (pole[y, x + 1] == l)
                    {
                        cesta.Push(new Policko(y, x + 1));
                        x++;
                    }
                    else if (pole[y, x - 1] == l)
                    {
                        cesta.Push(new Policko(y, x - 1));
                        x--;
                    }
                }
                return(cesta.Pop());
            }
            else
            {
                return(null);
            }
        }