static void Main(string[] args)
        {
            GameBoard gb = new GameBoard();
            gb.GenerateNewGame();
            gb.PrintGameBoard();
            TopScore ts = new TopScore();

            ts.OpenTopScoreList();

            bool isCoordinates;
            Coordinates coordinates = new Coordinates();
            Command command = new Command();
            while (gb.RemainingBaloons > 0)
            {
                if (gb.ReadInput(out isCoordinates, ref coordinates, ref command))
                {
                    if (isCoordinates)
                    {
                        gb.Shoot(coordinates);
                        gb.PrintGameBoard();
                    }
                    else
                    {
                        switch (command.Value)
                        {
                            case "top":
                                {
                                    ts.PrintScoreList();
                                }
                                break;
                            case "restart":
                                {
                                    gb.GenerateNewGame();
                                    gb.PrintGameBoard();
                                }
                                break;
                            case "exit":
                                {
                                    return;
                                }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Wrong Input!");
                }
            }

            Person player = new Person();
            player.Score = gb.ShootCounter;

            if (ts.IsTopScore(player))
            {
                Console.WriteLine("Please enter your name for the top scoreboard: ");
                player.Name = Console.ReadLine();
                ts.AddToTopScoreList(player);
            }
            ts.SaveTopScoreList();
        }
Example #2
0
        public bool ReadInput(out bool IsCoordinates, ref Coordinates coordinates, ref Command command)
        {
            Console.Write("Enter a row and column: ");
            string consoleInput = Console.ReadLine();

            coordinates = new Coordinates();
            command = new Command();

            if (Command.IsValidCommand(consoleInput))
            {
                IsCoordinates = false;
                command.Name = consoleInput;
                return true;
            }
            else if (Coordinates.TryParse(consoleInput, ref coordinates))
            {
                IsCoordinates = true;
                return true;
            }

            else
            {
                IsCoordinates = false;
                return false;
            }
        }
        public static bool TryParse(string input, ref Coordinates result)
        {
            char[] separators = { ' ', ',' };

            string[] substrings = input.Split(separators);

            if (substrings.Count<string>() != 2)
            {
                Console.WriteLine("Invalid move or command!");
                return false;
            }

            string coordinate = substrings[1].Trim();
            int x;
            if (int.TryParse(coordinate, out x))
            {
                if (x >= 0 && x <= 9)
                {
                    result.X = x;
                }
                else
                {
                    Console.WriteLine("Wrong x coordinates");
                    return false;
                }
            }
            else
            {
                Console.WriteLine("Invalid move or command!");
                return false;
            }

            coordinate = substrings[0].Trim();
            int y;
            if (int.TryParse(coordinate, out y))
            {
                if (y >= 0 && y <= 4)
                {
                    result.Y = y;
                }
                else
                {
                    Console.WriteLine("Wrong y coordinates");
                    return false;
                }
            }
            else
            {
                Console.WriteLine("Invalid move or command!");
                return false;
            }

            return true;
        }
Example #4
0
        public void GenerateNewGame()
        {
            Console.WriteLine("Welcome to “Balloons Pops” game. Please try to pop the balloons. Use 'top' to view the top scoreboard, 'restart' to start a new game and 'exit' to quit the game.");
            broya4 = 50;
            FillBlankGameBoard();
            Random random = new Random();
            Coordinates c = new Coordinates();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    c.X = i;
                    c.Y = j;

                    AddNewBaloonToGameBoard(c, (char)(random.Next(1, 5) + (int)'0'));
                }
            }
        }
Example #5
0
 private void Swap(Coordinates c, Coordinates c1)
 {
     char tmp = get(c);
     AddNewBaloonToGameBoard(c, get(c1));
     AddNewBaloonToGameBoard(c1, tmp);
 }
Example #6
0
        private void LandFlyingBaloons()
        {
            Coordinates c = new Coordinates();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j <= 4; j++)
                {
                    c.X = i;
                    c.Y = j;
                    if (get(c) == '.')
                    {
                        for (int k = j; k > 0; k--)
                        {
                            Coordinates tempCoordinates = new Coordinates();
                            Coordinates tempCoordinates1 = new Coordinates();
                            tempCoordinates.X = i;
                            tempCoordinates.Y = k;
                            tempCoordinates1.X = i;
                            tempCoordinates1.Y = k - 1;
                            Swap(tempCoordinates, tempCoordinates1);
                        }
                    }
                }

            }
        }
Example #7
0
        private char get(Coordinates c)
        {
            int xPosition, yPosition;
            if (c.X < 0 || c.Y < 0 || c.X > 9 || c.Y > 4) return 'e';
            xPosition = 4 + c.X * 2;

            yPosition = 2 + c.Y;
            return gb[xPosition, yPosition];
        }
Example #8
0
 private void AddNewBaloonToGameBoard(Coordinates c, char value)
 {
     int xPosition, yPosition;
     xPosition = 4 + c.X * 2;
     yPosition = 2 + c.Y;
     gb[xPosition, yPosition] = value;
 }
Example #9
0
        public void Shoot(Coordinates c)
        {
            char currentBaloon;
            currentBaloon = get(c);
            Coordinates tempCoordinates = new Coordinates();

            if (currentBaloon < '1' || currentBaloon > '4')
            {
                Console.WriteLine("Illegal move: cannot pop missing ballon!");return;
            }

            AddNewBaloonToGameBoard(c, '.');
            broya4--;

            tempCoordinates.X = c.X - 1;
            tempCoordinates.Y = c.Y;
            while (currentBaloon == get(tempCoordinates))
            {
                AddNewBaloonToGameBoard(tempCoordinates, '.');
                broya4--;
                tempCoordinates.X--;
            }

            tempCoordinates.X = c.X + 1; tempCoordinates.Y = c.Y;
            while (currentBaloon == get(tempCoordinates))
            {
                AddNewBaloonToGameBoard(tempCoordinates, '.');
                broya4--;
                tempCoordinates.X++;
            }

            tempCoordinates.X = c.X;
            tempCoordinates.Y = c.Y - 1;
            while (currentBaloon == get(tempCoordinates))
            {

                AddNewBaloonToGameBoard(tempCoordinates, '.');
                broya4--;
                tempCoordinates.Y--;
            }

            tempCoordinates.X = c.X;
            tempCoordinates.Y = c.Y + 1;
            while (currentBaloon == get(tempCoordinates))
            {
                AddNewBaloonToGameBoard(tempCoordinates, '.');
                broya4--;
                tempCoordinates.Y++;
            }

            count++;
            LandFlyingBaloons();
        }