Exemplo n.º 1
0
        private void RunGameLoop(Gracz[] players)
        {
            Int32 CurrentPlayer = 0;
            Gracz PlayerWhoWon  = null;

            while (true)
            {
                try
                {
                    Console.WriteLine("{0} twoja kolej", players[CurrentPlayer].Nazwa);
                    Console.WriteLine();
                    Console.WriteLine("Przeciwnik wyzej\r\n");
                    players[CurrentPlayer == 0 ? 1 : 0].RysPole(false);
                    Console.WriteLine();
                    Console.WriteLine("Ty (Dolny)\r\n");
                    players[CurrentPlayer].RysPole(true);

                    Console.WriteLine();

                    String Point = null;

                    while (String.IsNullOrEmpty(Point))
                    {
                        Console.Write("Wprowadz lokalizacje (Np : A5): ");
                        Point = Console.ReadLine();
                    }

                    Console.WriteLine();

                    Point CheckedPoint = CheckPoint(Point);

                    if (players[CurrentPlayer == 0 ? 1 : 0].JestSukces(CheckedPoint))
                    {
                        if (players[CurrentPlayer == 0 ? 1 : 0].Allzatopione)
                        {
                            PlayerWhoWon = players[CurrentPlayer];
                            break;
                        }
                    }

                    Console.WriteLine("Wcisnij Enter by kontynuowac.");
                    Console.ReadLine();
                    CurrentPlayer = CurrentPlayer == 0 ? 1 : 0;
                }
                catch (Exception Ex)
                {
                    Console.WriteLine(Ex.Message);
                    Console.WriteLine();
                    Console.WriteLine("Wcisnij Enter by kontynuowac.");
                    Console.ReadLine();
                }

                Console.Clear();
            }

            Console.Clear();
            Console.WriteLine("{0} wygral! Koniec.", PlayerWhoWon.Nazwa);
        }
Exemplo n.º 2
0
        public void Start()
        {
            Console.ForegroundColor = ConsoleColor.Green;

            DisplayStart();

            Gracz[] Players = new Gracz[] { new Gracz(), new Gracz() };

            SetupPlayer(Players[0], 1); //Gracz1
            SetupPlayer(Players[1], 2); //Gracz2

            RunGameLoop(Players);
            Console.ReadLine();
        }
Exemplo n.º 3
0
        private void SetupPlayer(Gracz player, Int32 playerNumber)
        {
            Console.WriteLine("*************Gracz {0}*************\r\n\r\n", playerNumber);

            while (String.IsNullOrEmpty(player.Nazwa))
            {
                Console.Write("Wprowadz imie : ");
                player.Nazwa = Console.ReadLine();
            }

            Console.WriteLine();

            SetupBoats(player);

            Console.WriteLine();
            Console.Clear();
        }
Exemplo n.º 4
0
        private void SetupBoats(Gracz player)
        {
            Statek[] Boats =
            {
                new Lotniskowiec(),
                new OkretWojenny(),
                new Niszczyciel(),
                new Patrolowiec(),
                new Podwodny()
            };

            Console.WriteLine("Teraz wprowadz punkty dla roznych lodzi..\r\n\r\n" +
                              "Gdy zostaniesz poproszony o punkty, wpisz je w ten sposób: A5;A6;A7\r\n\r\n\r\n");

            foreach (Statek Boat in Boats)
            {
                while (true)
                {
                    try
                    {
                        Console.WriteLine();
                        Console.Write("Wprowadz {0} punktow dla {1} : ", Boat.Trafienia, Boat.Nazwa);
                        String PointsRead = Console.ReadLine().Trim().Replace(" ", "");

                        if (String.IsNullOrEmpty(PointsRead))
                        {
                            continue;
                        }

                        String[] Points = PointsRead.Split(new Char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                        if (0 == Points.Length)
                        {
                            continue;
                        }

                        Boat.Points = new List <Trafienie>(Boat.Trafienia);

                        Int32 X = -1, Y = -1;

                        for (Int32 J = 0; J < Points.Length; J++)//(String Point in Points)
                        {
                            Point CheckedPoint = CheckPoint(Points[J]);

                            if (X != -1)
                            {
                                if (Math.Abs(X - CheckedPoint.X) > 1 || Math.Abs(Y - CheckedPoint.Y) > 1)
                                {
                                    throw new Exception("Punkty lokalizacji lodzi musza byc wprowadzane w kolejnosci sekwencyjnej i nie mogą zawierac przerw");
                                }
                            }

                            X = CheckedPoint.X;
                            Y = CheckedPoint.Y;

                            Boat.Points.Add(new Trafienie {
                                Lokalizacja = CheckedPoint
                            });
                        }

                        player.Dodaj(Boat);

                        break;
                    }
                    catch (Exception Ex)
                    {
                        Boat.Points = null;
                        Console.WriteLine(Ex.Message);
                        continue;
                    };
                }
            }
        }