예제 #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (czy_gra_aktywna)
            {
                pole_gry.CreateGraphics().Clear(Color.Black);                          // czyścimy pole gry kiedy gra jest aktywna
                waz.move();                                                            // wywolanie metody move
                waz.rysuj(pole_gry.CreateGraphics(), new SolidBrush(Color.Aqua));      // waz.rysuj + parametry metody
                owoc.rysuj_owoc(pole_gry.CreateGraphics(), new SolidBrush(Color.Red)); // uruchamiamy rysowanie owocu

                if (owoc.czy_nowy_owoc(waz.x[0], waz.y[0]))
                {
                    waz.dodaj();
                }
                if (waz.czy_waz_zyje() == false)
                {
                    czy_gra_aktywna = false;
                }
            }
            else
            {
                FontFamily fontFamily1 = new FontFamily("Arial");                     // tworzenie obiektu typu FontFamily
                Font       f           = new Font(fontFamily1, 15);
                Brush      b           = new SolidBrush(Color.Aqua);                  // kolor jakim chcemy pisać
                pole_gry.CreateGraphics().DrawString("Naciśnij Start", f, b, 50, 50); // 1.tekst, który chcemy utworzyć 2.obiekt typu font 3.obiekt typu brush, 4.współrzędne x i y
            }
        }
예제 #2
0
 public void render()
 {
     if (updateGame())
     {
         Task task = new Task(handleUserChoice);
         task.Start();
         Console.Clear();
         snake.move();
         snake.render();
         food.render();
         this.detectEat();
         framesSinceLastDirectionChange++;
     }
 }
예제 #3
0
        private void loop()
        {
            uint prevS = s.length;

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKey key  = Console.ReadKey(false).Key;
                    Direction  dnew = Direction.UP;
                    switch (key)
                    {
                    case ConsoleKey.UpArrow:
                        dnew = Direction.UP;
                        break;

                    case ConsoleKey.RightArrow:
                        dnew = Direction.RIGHT;
                        break;

                    case ConsoleKey.DownArrow:
                        dnew = Direction.DOWN;
                        break;

                    case ConsoleKey.LeftArrow:
                        dnew = Direction.LEFT;
                        break;

                    default: break;
                    }

                    if ((dnew == Direction.UP && s.direction == Direction.DOWN) ||
                        (dnew == Direction.DOWN && s.direction == Direction.UP) ||
                        (dnew == Direction.LEFT && s.direction == Direction.RIGHT) ||
                        (dnew == Direction.RIGHT && s.direction == Direction.LEFT))
                    {
                        ;
                    }
                    else
                    {
                        s.direction = dnew;
                    }
                }
                if (prevS != s.length)
                {
                    prevS = s.length;
                    message("Score: " + s.length);
                }

                ConsoleColor[] prev = prevCC();

                Point tail = s.move();
                if (tail != null)
                {
                    setCC(ConsoleColor.Black);
                    writeCP(tail.x, tail.y);
                }

                setCC(ConsoleColor.Green);
                Point head = s.head;
                writeCP(head.x, head.y);
                setCC(prev);

                for (int i = 0; i < mice.Count; i++)
                {
                    if (head.x == mice[i].x && head.y == mice[i].y)
                    {
                        s.addLength(2);
                        mice.RemoveAt(i);
                    }
                }

                if (mice.Count < 3)
                {
                    addMouse();
                }

                if (s.head.x <= 1 || s.head.x >= width - 2 ||
                    s.head.y <= 1 || s.head.y >= height - 2)
                {
                    reset("You hit the wall!");
                }
                else if (s.selfCollision)
                {
                    reset("You ran into your self!");
                }

                Thread.Sleep(50);
            }
        }