コード例 #1
0
        private static void Main()
        {
            // Creates new game
            ConsoleGame Game = new ConsoleGame();

            Game.InitializeGame();
        }
コード例 #2
0
ファイル: GameInitTests.cs プロジェクト: ValerCheck/CoSnake
 public void GameFieldInitializedWhenPressedEnter()
 {
     var game = new ConsoleGame("CoSnake",WIDTH, HEIGHT);
     game.DrawField();
     Assert.IsTrue(game.CurrentState.Length == WIDTH * HEIGHT);
     Assert.IsTrue(game.CurrentState.Contains("@"));
 }
コード例 #3
0
        public void Run()
        {
            var width  = 80;
            var height = 80;

            var soup   = new Board(width, height);
            var engine = new DefaultEngine <WrappingMooreNeighborhood>();

            soup.Init(() => CellState.Dead, engine);

            soup.GliderAt(2, 10);
            soup.GliderAt(2, 30);
            soup.GliderAt(2, 50);
            soup.GliderAt(2, 70);

            soup.GliderAt(70, 5, true, false);
            soup.GliderAt(70, 25, true, false);
            soup.GliderAt(70, 55, true, false);
            soup.GliderAt(70, 65, true, false);

            soup.GliderAt(30, 30, false, false);
            soup.GliderAt(40, 40, false, false);
            soup.GliderAt(50, 50, false, false);
            soup.GliderAt(60, 60, false, false);

            soup.GliderAt(30, 60, false, true);
            soup.GliderAt(40, 50, false, true);
            soup.GliderAt(50, 40, false, true);
            soup.GliderAt(60, 30, false, true);

            var driver = new ConsoleGame();

            driver.InitConsole(width, height);
            driver.LightningBolt(soup);
        }
コード例 #4
0
ファイル: GameInitTests.cs プロジェクト: ValerCheck/CoSnake
 public void GameDisplayWelcomeMessageCorrect()
 {
     var game = new ConsoleGame("CoSnake");
     Assert.IsTrue(game.CurrentState.Contains("Welcome, player!"));
     Assert.IsTrue(game.CurrentState.Contains("This is CoSnake"));
     Assert.IsTrue(game.CurrentState.Contains("Press Enter to start game"));
 }
コード例 #5
0
        public void Setup()
        {
            while (Game == null)
            {
                Console.WriteLine("Welcome to Exploding Kittens.\n");
                Console.WriteLine("              ^   ^    ");
                Console.WriteLine("             / \\ / \\ ");
                Console.WriteLine("    ??      ( 0   0 )  ");
                Console.WriteLine("    ??_____ |   V   |  ");
                Console.WriteLine("    (          ===  )  ");
                Console.WriteLine("    (               )  ");
                Console.WriteLine("    (_______________)  ");
                Console.WriteLine("      ()         ()    ");
                Console.WriteLine("\nPlease enter the number of players (between 2 and 5):\n");

                int numberOfPlayers = Utilities.GetIntFromString(Console.ReadLine(), 0);

                Console.WriteLine();

                try
                {
                    Game = new ConsoleGame(numberOfPlayers, new ConsoleWriter());//, true);

                    Start();
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(string.Format("{0}\n", e.Message));
                }
            }
        }
コード例 #6
0
        public void ShouldReturnTypeOfPlayerComputer()
        {
            var mockUI = new Mock <IUserInterface>();

            mockUI.Setup(o => o.GetFromUser()).Returns("COMPUTER");
            var game   = new ConsoleGame(mockUI.Object);
            var result = game.GetPlayer();

            Assert.AreEqual("COMPUTER", result.Name());
        }
コード例 #7
0
        private static void Main()
        {
            var game = new ConsoleGame();

            game.Start();

            while (!game.IsGameOver)
            {
                game.GetInput();
                game.MakeTurn();
            }
        }
コード例 #8
0
        public void Run()
        {
            var width  = 80;
            var height = 80;

            var soup = new Board(width, height);

            soup.Init(Board._RandomState, new DefaultestEngine());

            var driver = new ConsoleGame();

            driver.InitConsole(width, height);
            driver.LightningBolt(soup);
        }
コード例 #9
0
        public bool CreateConsoleGame(ConsoleGameCreate model)
        {
            var entity = new ConsoleGame()
            {
                ConsoleId = model.ConsoleId,
                GameId    = model.GameId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.ConsoleGames.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #10
0
        /// <summary>
        /// Handles the drawing part of the scene
        /// </summary>
        /// <param name="game">Game manager</param>
        public void Draw(Game game)
        {
            // Game is a generic class, so make sure to convert it to ConsoleGame
            ConsoleGame consoleGame = (ConsoleGame)game;
            // ConsoleGame has a screen to draw whereas Game doesn't
            ConsoleScreen consoleScreen = consoleGame.Screen;

            // Clears the whole screen
            consoleScreen.Clear();
            // Draw the gameover text
            consoleScreen.DrawText(3, 7, "    Your pet left you!\nTake better care next time!");
            // When we're done drawing everything we needed, updates the screen
            consoleScreen.Show();
        }
コード例 #11
0
        public void Run()
        {
            var width  = 80;
            var height = 80;

            var soup = new Board(width, height);

            soup.Init(() => CellState.Dead, null);
            soup.Actors.Add(new LangtonAnt(new Coordinant(width / 2, height / 2), false));

            var driver = new ConsoleGame();

            driver.InitConsole(width, height);
            driver.LightningBolt(soup);
        }
コード例 #12
0
        public void Run()
        {
            var width  = 80;
            var height = 80;

            var soup   = new Board(width, height);
            var engine = new DefaultEngine <MooreNeighborhood>();

            soup.Init(() => CellState.Dead, engine);
            GosperGliderGun.GggAt(soup, 10, 10);
            var driver = new ConsoleGame();

            driver.InitConsole(width, height);
            driver.LightningBolt(soup);
        }
コード例 #13
0
        public void Setup()
        {
            _boardInitializerDouble        = A.Fake <BoardInitializer>();
            _consoleWrapperDouble          = A.Fake <ConsoleWrapper>();
            _boardPrinterDouble            = A.Fake <BoardPrinter>();
            _consoleCoordinateReaderDouble = A.Fake <ConsoleCoordinatesReader>();
            _inputMapperDouble             = A.Fake <CoordinatesMapper>();
            _shotResultMapperDouble        = A.Fake <ShotResultMapper>();

            _subject = new ConsoleGame(
                _boardInitializerDouble,
                _consoleWrapperDouble,
                _boardPrinterDouble,
                _consoleCoordinateReaderDouble,
                _inputMapperDouble,
                _shotResultMapperDouble);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: fga401/Tetris
        static void Main()
        {
#if CONSOLE_OUTPUT
            ConsoleGame.AllocConsole();
            ConsoleGame.GameStart();
#elif WINFORM_OUTPUT
#if DEBUG
            ConsoleGame.AllocConsole();
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TetrisForm());
#endif
#if CONSOLE_OUTPUT
            Console.ReadKey();
            ConsoleGame.FreeConsole();
#endif
        }
コード例 #15
0
        public void Run()
        {
            var width  = 80;
            var height = 80;

            var soup   = new Board(width, height);
            var engine = new DefaultEngine <NoDiag_N_VonNeuman <N_3> >();

            soup.Init(Board._RandomState, engine);

            //MortalCells
            var maxLife = 4;

            soup.BoardIterator((x, y) => soup.State[x, y] = new AbsoluteMortalCell(soup.State[x, y], maxLife));

            var driver = new ConsoleGame();

            driver.InitConsole(width, height);
            driver.LightningBolt(soup);
        }
コード例 #16
0
        public void Run()
        {
            var width  = 80;
            var height = 80;

            var soup = new Board(width, height);

            //var engine = new DefaultEngine<WrappingMooreNeighborhood>();
            soup.Init(() => CellState.Dead, null);
            soup.Actors.Add(new LangtonAnt(new Coordinant(width / 2, height / 2), true));
            //MortalCells
            var maxLife = 100;

            soup.BoardIterator((x, y) => soup.State[x, y] = new AbsoluteMortalCell(soup.State[x, y], maxLife));

            var driver = new ConsoleGame();

            driver.InitConsole(width, height);
            driver.LightningBolt(soup);
        }
コード例 #17
0
        public static void Run()
        {
            bool exitFlag = false;
            int  select;

            do
            {
                Console.Clear();
                Console.WriteLine("Исполнитель «Калькулятор» преобразует целое число, записанное на экране." +
                                  "\nУ исполнителя две команды, каждой присвоен номер:\n" +
                                  "1.Прибавь 1\n2.Умножь на 2\nПервая команда увеличивает число на экране на 1,\n" +
                                  "вторая увеличивает его в 2 раза.\n" +
                                  "Определить, сколько существует программ, которые преобразуют число 3 в число 20:\n" +
                                  "а) С использованием массива\nb) С использованием рекурсии *");

                Console.WriteLine("\nВыберите дальнейшее действие:\n0 - Выйти\n1 - Сыграть в игру\n2 - Выполнить задание");
                select = GetNumber();

                switch (select)
                {
                case 0:
                    exitFlag = true;
                    Console.Clear();
                    break;

                case 1:
                    ConsoleGame game = new ConsoleGame(GetNumber("Введите начальное число: "), GetNumber("Введите конечное число: "));
                    game.StartGame();
                    break;

                case 2:
                    CalculateTask3();
                    break;

                default:
                    Console.WriteLine($"В текущем меню нет пункта {select}\nДля повтора нажмите любую клавишу...");
                    Console.ReadKey();
                    break;
                }
            }while (!exitFlag);
        }
コード例 #18
0
        public bool CreateConsoleGames(ConsoleGamesCreates model)
        {
            var recordList = new List <ConsoleGame>();

            foreach (var choice in model.ConsoleList)
            {
                if (choice.isLinked)
                {
                    var newEntity = new ConsoleGame()
                    {
                        ConsoleId = choice.ConsoleId, GameId = model.GameId
                    };
                    recordList.Add(newEntity);
                }
            }
            using (var ctx = new ApplicationDbContext())
            {
                foreach (var consoleGame in recordList)
                {
                    ctx.ConsoleGames.Add(consoleGame);
                }
                return(ctx.SaveChanges() >= 1);
            }
        }
コード例 #19
0
 public HelpCommand(ConsoleGame game)
 {
     Game = game;
 }
コード例 #20
0
        static void Main(string[] args)
        {
            ConsoleGame game = new ConsoleGame(FieldRows, FieldCols, NumberOfMines);

            game.Play();
        }
コード例 #21
0
 public PlayCommand(ConsoleGame game, Player player, int index)
 {
     Game                     = game;
     CurrentPlayer            = player;
     CurrentTargetPlayerIndex = index;
 }
コード例 #22
0
ファイル: StartUp.cs プロジェクト: YordanDobrev97/Chess
        public static void Main()
        {
            IGame currentGame = new ConsoleGame();

            currentGame.StartMenu();
        }
コード例 #23
0
        static void Main(string[] args)
        {
            ConsoleGame game = new ConsoleGame(FieldRows, FieldCols, NumberOfMines);

            game.Play();
        }
コード例 #24
0
        public string RunMenu()
        {
            string input;

            while (true)
            {
                PrintMenu();

                var rawInput = Console.ReadLine()?.Trim();
                input = rawInput?.ToUpper();

                // Quit to main menu
                if (DisplayQuitToMainMenu && input == MenuInitializers.QuitToMainItem.Shortcut)
                {
                    break;
                }

                // Go back
                if (!DisableGoBackItem && input == MenuInitializers.GoBackItem.Shortcut)
                {
                    break;
                }

                // Current menu contains no shortcuts and is only for inputting a value
                if (MenuTypes.Contains(MenuType.Input))
                {
                    if (MenuTypes.Contains(MenuType.ShipCoordInput) ||
                        MenuTypes.Contains(MenuType.RuleIntInput) ||
                        MenuTypes.Contains(MenuType.NameInput) ||
                        MenuTypes.Contains(MenuType.CoordInput))
                    {
                        return(rawInput);
                    }
                }

                // Load user-specified or default menuitem
                var item = string.IsNullOrWhiteSpace(input) || string.IsNullOrEmpty(input)
                    ? MenuItems.FirstOrDefault(m => m.IsDefaultChoice)
                    : MenuItems.FirstOrDefault(m => m.Shortcut == input);

                // The menuitem was null
                if (item == null)
                {
                    Console.WriteLine("Unknown input!");
                    Console.ReadKey(true);
                    continue;
                }

                // Again the input but this time the user can actually cancel and go back
                if (MenuTypes.Contains(MenuType.Input))
                {
                    if (MenuTypes.Contains(MenuType.YesNoInput))
                    {
                        return(item.Shortcut);
                    }
                }

                // Current menu is the game menu
                if (MenuTypes.Contains(MenuType.GameMenu))
                {
                    // Current menu is game loading menu
                    if (MenuTypes.Contains(MenuType.LoadGameMenu) && item.GameId != null)
                    {
                        // Load the game from the database and continue it
                        ConsoleGame.LoadGame((int)item.GameId);
                        ConsoleGame.RunGame();

                        // Return the GoBackItem shortcut to exit the game loading menu
                        return(MenuInitializers.GoBackItem.Shortcut);
                    }

                    // Current menu is game deleting menu
                    if (MenuTypes.Contains(MenuType.DeleteGameMenu) && item.GameId != null)
                    {
                        // Delete the game from the database
                        ConsoleGame.DeleteGame((int)item.GameId);

                        // Return the GoBackItem shortcut to exit the game deletion menu
                        return(MenuInitializers.GoBackItem.Shortcut);
                    }

                    // Current menu is new game menu
                    if (MenuTypes.Contains(MenuType.NewGameMenu))
                    {
                        // Reset current game to initial state
                        ActiveGame.Init();

                        // Start new game
                        if (item.ActionToExecute != null)
                        {
                            item.ActionToExecute();

                            // Return the GoBackItem shortcut to exit the menu
                            return(MenuInitializers.GoBackItem.Shortcut);
                        }
                    }
                }

                // Current menu is the rules menu
                if (MenuTypes.Contains(MenuType.RulesMenu))
                {
                    // Current item has an action
                    if (item.ActionToExecute != null)
                    {
                        item.ActionToExecute();

                        // If current menu item was for resetting some rules, show a confirmation that indeed, the rules
                        // have been set to default values
                        if (item.IsResetRules)
                        {
                            Console.WriteLine("Rules set to default...");
                            Console.ReadKey(true);
                        }

                        continue;
                    }

                    // Current menu is the main rules menu
                    if (item.RuleTypeToChange != null)
                    {
                        DynamicMenus.ChangeRuleValue((RuleType)item.RuleTypeToChange);
                        continue;
                    }
                }

                if (item.ActionToExecute != null)
                {
                    item.ActionToExecute();

                    if (item.MenuToRun == null)
                    {
                        continue;
                    }
                }

                // execute the command specified in the menu item
                if (item.MenuToRun == null)
                {
                    Console.WriteLine(input + " has no command assigned to it!");
                    Console.ReadKey(true);
                    continue;
                }

                // everything should be ok now, lets run it!
                input = item.MenuToRun();

                if (!MenuTypes.Contains(MenuType.MainMenu) && input == MenuInitializers.QuitToMainItem.Shortcut)
                {
                    break;
                }

                if (input != MenuInitializers.GoBackItem.Shortcut && input != MenuInitializers.QuitToMainItem.Shortcut)
                {
                    Console.ReadKey(true);
                }
            }

            return(input);
        }