Exemplo n.º 1
0
        public void ChooseNumber(int number, State state)
        {
            bool isOnTable = false;

            for (int i = 0; i < board_numbers.Length; i++)
            {
                if (board_numbers[i].value == number)
                {
                    isOnTable = true;

                    if (board_numbers[i].guess != "*+*" && board_numbers[i].guess != "*-*")
                    {
                        state.guesses++;

                        if (chosen_numbers.Contains(number))
                        {
                            board_numbers[i].guess = "*+*";
                            state.credit++;
                            state.correct_guesses++;
                        }
                        else
                        {
                            board_numbers[i].guess = "*-*";
                        }

                        if (state.guesses == 5)
                        {
                            Console.WriteLine("The game has ended! This is the board and your credit:");
                            if (state.correct_guesses == 5)
                            {
                                state.credit = state.credit * 2;
                                Printer.PrintBingoBoard(this, state);
                            }
                            Printer.PrintBoard(this, state);
                        }
                    }

                    else
                    {
                        Console.WriteLine("You already selected this number. Please select another number from the board!");
                    }
                }
            }

            if (!isOnTable)
            {
                Console.WriteLine("The Number you selected is not on the board. Please select a number from the board!");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string command;
            Game   game    = new Game();
            bool   resumed = true;

            game = Backup.Load("savedgame.xml");
            if (game != null)
            {
                Console.WriteLine("The is an open game available! Would you like to resume the saved game?");
                Console.WriteLine("Type \"continue\" to resume or \"new\" for a new game");

                while (resumed)
                {
                    command = Console.ReadLine();
                    switch (command)
                    {
                    case "new":
                        game = new Game();
                        game.board.RandomizeBoard();
                        resumed = false;
                        break;

                    case "continue":
                        game    = Backup.Load("savedgame.xml");
                        resumed = false;
                        break;

                    case "exit":
                        System.Environment.Exit(1);
                        break;

                    default:
                        Console.WriteLine("Invalid command! Type \"continue\" to resume or \"new\" for a new game");
                        break;
                    }
                }
            }

            while ((command = Console.ReadLine()) != null)
            {
                switch (command)
                {
                case "show":
                    if (game.board.chosen_numbers.Count == 0)
                    {
                        game.board.RandomizeBoard();
                    }
                    Printer.PrintBoard(game.board, game.state);
                    break;

                case "end":
                    if (game.board.chosen_numbers.Count == 0)
                    {
                        Console.WriteLine("There is no active game! Type \"show\" in order to populate the board!");
                    }
                    else
                    {
                        Console.WriteLine("The game has ended! This is the board and your credit:");
                        Printer.PrintBoard(game.board, game.state);
                        game = new Game();
                    }

                    break;

                case "exit":
                    if (game.state.guesses > 0 && game.state.guesses < 5)
                    {
                        Backup.Save(game, "savedgame.xml");
                    }
                    System.Environment.Exit(1);
                    break;

                default:
                    try
                    {
                        int number = Int32.Parse(command);

                        if (number >= 90)
                        {
                            Console.WriteLine("The Number must be between 0 and 89!");
                        }
                        else if (number < 0)
                        {
                            Console.WriteLine("The Number must be between 0 and 89!");
                        }
                        else
                        {
                            if (game.board.chosen_numbers.Count == 0)
                            {
                                Console.WriteLine("The board is empty! Type \"show\" in order to populate the board!");
                            }
                            else
                            {
                                game.board.ChooseNumber(number, game.state);
                                if (game.state.guesses == 5)
                                {
                                    var save_credit = game.state.credit;
                                    game = new Game();
                                    game.state.credit = save_credit;
                                }
                            }
                        }
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Invalid Command!");
                    }
                    break;
                }
            }
        }