Пример #1
0
        static void Main(string[] args)
        {
            Plansza        plansza = new Plansza();
            PacMan         pacman  = new PacMan(plansza);
            ConsoleKeyInfo cki     = new ConsoleKeyInfo();

            while (true)
            {
                while (Console.KeyAvailable == false)
                {
                    Console.Clear();
                    //punkt.ruch(cki);

                    pacman.ruch(cki, ref plansza);
                    plansza.generowanieTablicy(ref pacman);

                    Console.WriteLine("\nPunkt x {0} punkt y {1}", pacman.x, pacman.y);
                    Console.WriteLine("Punkty: {0}", pacman.score);

                    Thread.Sleep(300);
                }
                cki = Console.ReadKey();
            }
            Console.ReadLine();
        }
Пример #2
0
 public PacMan(Plansza plansza)
 {
     for (int i = 0; i < 14; i++)
     {
         for (int j = 0; j < 17; j++)
         {
             if (plansza.planszaTab[i, j] == '@')
             {
                 this.x = j;
                 this.y = i;
             }
         }
     }
 }
Пример #3
0
        public void ruch(ConsoleKeyInfo cki, ref Plansza plansza)
        {
            switch (cki.Key)
            {
            case ConsoleKey.LeftArrow:
            {
                if (plansza.planszaTab[this.y, (this.x - 1)] == '#')
                {
                }
                else if (plansza.planszaTab[this.y, (this.x - 1)] == '!')
                {
                }
                else
                {
                    if (plansza.planszaTab[this.y, (this.x - 1)] == '.')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                        this.score += 1;
                    }
                    else if (plansza.planszaTab[this.y, (this.x - 1)] == ' ')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                    }
                    this.x--;
                }
            }
            break;

            case ConsoleKey.DownArrow:
            {
                if (plansza.planszaTab[(this.y + 1), this.x] == '#')
                {
                }
                else if (plansza.planszaTab[(this.y + 1), this.x] == '!')
                {
                }
                else
                {
                    if (plansza.planszaTab[(this.y + 1), this.x] == '.')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                        this.score += 1;
                    }
                    else if (plansza.planszaTab[(this.y + 1), this.x] == ' ')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                    }
                    this.y++;
                }
            }
            break;

            case ConsoleKey.RightArrow:
            {
                if (plansza.planszaTab[this.y, (this.x + 1)] == '#')
                {
                }
                else if (plansza.planszaTab[this.y, (this.x + 1)] == '!')
                {
                }
                else
                {
                    if (plansza.planszaTab[this.y, (this.x + 1)] == '.')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                        this.score += 1;
                    }
                    else if (plansza.planszaTab[this.y, (this.x + 1)] == ' ')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                    }
                    this.x++;
                }
            }
            break;

            case ConsoleKey.UpArrow:
            {
                if (plansza.planszaTab[(this.y - 1), this.x] == '#')
                {
                }
                else if (plansza.planszaTab[(this.y - 1), this.x] == '!')
                {
                }
                else
                {
                    if (plansza.planszaTab[(this.y - 1), this.x] == '.')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                        this.score += 1;
                    }
                    else if (plansza.planszaTab[(this.y - 1), this.x] == ' ')
                    {
                        plansza.planszaTab[this.y, this.x] = ' ';
                    }
                    this.y--;
                }
            }
            break;
            }
        }