public PopBalloonsCommand(IBalloonsFactory balloonsFactory, IGameField gameField, int activeRow, int activeCol)
 {
     this.balloonsFactory = balloonsFactory;
     this.gameField = gameField;
     this.activeRow = activeRow;
     this.activeCol = activeCol;
     this.Name = "pop";
 }
 public void Setup()
 {
     this.renderer = new ConsoleRenderer();
     this.field = new GameField(2, 2);
     this.fieldMemoryManager = new FieldMemoryManager();
     this.balloonsFactory = new BalloonsFactory();
     this.field[0, 0] = new BalloonOne();
     this.field[0, 1] = new BalloonTwo();
     this.field[1, 0] = new BalloonThree();
     this.field[1, 1] = new BalloonFour();
 }
 private void SwapWithNextUnpopedBalloon(IGameField gameField, int activeRow, int activeCol, int rows)
 {
     for (int row = activeRow + 1; row < rows; row++)
     {
         if (gameField[row, activeCol].Symbol != GameConstants.PopedBalloonSymbol)
         {
             var oldValue = gameField[activeRow, activeCol];
             gameField[activeRow, activeCol] = gameField[row, activeCol];
             gameField[row, activeCol] = oldValue;
             return;
         }
     }
 }
        /// <summary>
        /// Simulates one step in the Game of Life.
        /// </summary>
        /// <param name="oldGameField">The IGameField from the last simulation step.</param>
        /// <param name="newGameField">The IGameField to fill with this simulation step.</param>
        public void SimulateStep( IGameField oldGameField, IGameField newGameField )
        {
            Debug.Assert( oldGameField.Width == newGameField.Width );
            Debug.Assert( oldGameField.Height == newGameField.Height );

            int width = oldGameField.Width;
            int height = oldGameField.Height;

            for( int x = 0; x < width; ++x )
            {
                for( int y = 0; y < height; ++y )
                {                    
                    newGameField.SetCellState( x, y, this.SimulateCell( x, y, oldGameField ) );
                }
            }
        }
        /// <summary>
        /// Gets how many 'alive' neighbors the given cell has.
        /// </summary>
        /// <param name="x">The position of the cell on the x-axis.</param>
        /// <param name="y">The position of the cell on the y-axis.</param>
        /// <param name="gameField">The IGameField to pull the data from.</param>
        /// <returns>
        /// The number of alive neighbors.
        /// </returns>
        private int GetAliveNeighborCount( int x, int y, IGameField gameField )
        {
            int count = 0;

            count += this.GetCellState( x + 1, y, gameField );
            count += this.GetCellState( x - 1, y, gameField );
            count += this.GetCellState( x, y + 1, gameField );
            count += this.GetCellState( x, y - 1, gameField );

            count += this.GetCellState( x + 1, y + 1, gameField );
            count += this.GetCellState( x + 1, y - 1, gameField );
            count += this.GetCellState( x - 1, y - 1, gameField );
            count += this.GetCellState( x - 1, y + 1, gameField );

            return count;
        }
Example #6
0
        private void StartInteraction(IGameField field)
        {
            string readBuffer = null;
            int blownMines = 0;

            while (field.ContainsMines())
            {
                try
                {
                    field.DrawField();
                    Console.Write(GameMessage.CoordinatesPrompt);
                    readBuffer = Console.ReadLine();
                    Mine mineToBlow = GameServices.ExtractMineFromString(readBuffer);

                    while (mineToBlow == null)
                    {
                        Console.Write(GameMessage.CoordinatesPrompt);
                        readBuffer = Console.ReadLine();
                        mineToBlow = GameServices.ExtractMineFromString(readBuffer);
                    }

                    bool isValidMove = GameServices.IsValidMove(field.Field, mineToBlow.X, mineToBlow.Y);
                    if (!isValidMove)
                    {
                        Console.WriteLine(GameMessage.InvalidMove);
                        continue;
                    }

                    Explosion.Explode(field.Field, mineToBlow);
                    blownMines++;
                }
                catch (InvalidMineCoordinatesException)
                {
                    Console.WriteLine(GameMessage.InvalidIndex);
                    continue;
                }

            }

            field.DrawField();
            Console.WriteLine("{0} {1}", GameMessage.GameOverMessage, blownMines);
        }
        /// <summary>
        /// Orders matrix cells that have numbers in them in a smaller row number and those with "." at a bigger row.
        /// </summary>
        /// <param name="gameField">Field to reorder.</param>
        public override void ReorderBalloons(IGameField gameField)
        {
            if (ObjectValidator.IsGameObjectNull(gameField))
            {
                throw new ArgumentNullException(FieldNullErrorMessage);
            }

            int rows = gameField.Rows;
            int columns = gameField.Columns;

            for (int col = 0; col < columns; col++)
            {
                for (int row = 0; row < rows; row++)
                {
                    if (gameField[row, col].Symbol == GameConstants.PopedBalloonSymbol)
                    {
                        this.SwapWithNextUnpopedBalloon(gameField, row, col, rows);
                    }
                }
            }
        }
        /// <summary>
        /// Simulates the state of the cell at the given position.
        /// </summary>
        /// <param name="x">The position of the cell on the x-axis.</param>
        /// <param name="y">The position of the cell on the y-axis.</param>
        /// <param name="gameField">The IGameField to pull the data from.</param>
        /// <returns>
        /// Whether the given cell is 'dead' or 'alive'.
        /// </returns>
        private bool SimulateCell( int x, int y, IGameField gameField )
        {
            int neighborCount = this.GetAliveNeighborCount( x, y, gameField );

            if( gameField.GetCellStateStrict( x, y ) )
            {
                // For a space that is 'populated':
                //  Each cell with one or no neighbors dies, as if by loneliness.
                //  Each cell with four or more neighbors dies, as if by overpopulation.
                //  Each cell with two or three neighbors survives.
                
                return neighborCount == 2 ||  neighborCount == 3;
            }
            else
            {
                // For a space that is 'empty' or 'unpopulated'
                //  Each cell with three neighbors becomes populated.

                return neighborCount == 3;
            }
        }
        private void Pop(int activeRow, int activeCol, string activeCell, IGameField field)
        {
            bool isValidPop = this.IsPopValid(activeRow, field.Rows) && this.IsPopValid(activeCol, field.Columns);

            if (isValidPop && (field[activeRow, activeCol].Symbol == activeCell) && (field[activeRow, activeCol].Symbol != GameConstants.PopedBalloonSymbol))
            {
                field[activeRow, activeCol] = this.balloonsFactory.GetBalloon(GameConstants.PopedBalloonSymbol);

                // Up
                this.Pop(activeRow - 1, activeCol, activeCell, field);

                // Down
                this.Pop(activeRow + 1, activeCol, activeCell, field);

                // Left
                this.Pop(activeRow, activeCol + 1, activeCell, field);

                // Right
                this.Pop(activeRow, activeCol - 1, activeCell, field);
            }
        }
Example #10
0
        public bool CheckPossibilityToKill(Coord CurrentCoord, Coord DestCoord, IGameField field)
        {
            if (DestCoord.Row < 1 || DestCoord.Row > 8 || DestCoord.Column < 1 || DestCoord.Column > 8)
            {
                return(false); //за пределы поля
            }
            if (field.Grid[DestCoord.Row][DestCoord.Column] != null)
            {
                return(false); //там занято
            }
            int dRow    = DestCoord.Row - CurrentCoord.Row;
            int dColumn = DestCoord.Column - CurrentCoord.Column;

            if (Math.Abs(dRow) == 2 && Math.Abs(dColumn) == 2)                                                  //если хотим бить
            {
                IChecker neigbour = field.Grid[CurrentCoord.Row + dRow / 2][CurrentCoord.Column + dColumn / 2]; //ищем кого бить
                if (neigbour != null && neigbour is WhiteChecker)                                               //если там враг
                {
                    return(true);
                }
            }

            return(false);
        }
        private void MakeBorders(IGameField gameField)
        {
            int rows = gameField.Board.GetLength(0);
            int columns = gameField.Board.GetLength(1);

            base.Engine.Writer.WriteLine("\n    0 1 2 3 4 5 6 7 8 9");
            base.Engine.Writer.WriteLine("   ---------------------");

            for (int row = 0; row < rows; row++)
            {
                base.Engine.Writer.Write(string.Format("{0} | ", row));

                for (int col = 0; col < columns; col++)
                {
                    base.Engine.Writer.Write(string.Format("{0} ", gameField.Board[row, col]));
                }

                base.Engine.Writer.Write("|");

                Console.WriteLine();
            }

            base.Engine.Writer.WriteLine("   ---------------------\n");
        }
Example #12
0
        public override bool CanMove(GameSide side, IGameField field)
        {
            switch (side)
            {
            case GameSide.Left:
                if (_gameBlock.Right.Column == 0)
                {
                    return(false);
                }
                return(field[_gameBlock.Right.Row, _gameBlock.Right.Column - 1].Type == GameCellType.None);

            case GameSide.Right:
                if (_gameBlock.Left.Column + 1 == field.Width)
                {
                    return(false);
                }
                return(field[_gameBlock.Left.Row, _gameBlock.Left.Column + 1].Type == GameCellType.None);

            case GameSide.Down:
                return(_gameBlock.Left.CanFallDown(field) && _gameBlock.Right.CanFallDown(field));

            default: throw new ArgumentException("Неверно указана сторона side (GameSide)");
            }
        }
Example #13
0
        public IChecker GetVictim(Coord CurrentCoord, Coord DestCoord, IGameField field)
        {
            if (DestCoord.Row < 1 || DestCoord.Row > 8 || DestCoord.Column < 1 || DestCoord.Column > 8)
            {
                return(null); //за пределы поля
            }
            if (field.Grid[DestCoord.Row][DestCoord.Column] != null)
            {
                return(null); //там занято
            }
            int dRow    = DestCoord.Row - CurrentCoord.Row;
            int dColumn = DestCoord.Column - CurrentCoord.Column;

            if (Math.Abs(dRow) == 2 && Math.Abs(dColumn) == 2)                                                  //если хотим бить
            {
                IChecker neigbour = field.Grid[CurrentCoord.Row + dRow / 2][CurrentCoord.Column + dColumn / 2]; //ищем кого бить
                if (neigbour != null && neigbour is BlackChecker)                                               //если там враг
                {
                    return(neigbour);
                }
            }

            return(null);
        }
Example #14
0
 //Init
 private void InitGame()
 {
     _pool      = new GamePool(_blockPrefab, _config.fieldWidth * _config.fieldHeight);
     _field     = new GameField(_config, _pool);
     _uIManager = new UIManager(GameObject.Find("Canvas").transform);
 }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExplosionHandler" /> class.
 /// </summary>
 /// <param name="gameField">Accepts an instance of the game field.</param>
 public ExplosionHandler(IGameField gameField)
 {
     this.FieldBlastRepresentation = DEFAULT_FIELD_BLAST_REPRESENTATION;
     this.GameField = gameField;
 }
 public SlowPokeWarsGame(IGameField gameField)
 {
     _gameGuid  = Guid.NewGuid();
     _gameField = gameField;
 }
Example #17
0
 public RandomPlayer(IGameField selfField) : base(selfField)
 {
 }
Example #18
0
 protected PlayerBase(IGameField selfField)
 {
     SelfField = selfField;
     OpponentFieldKnowledge = new GameFieldKnowledge(SelfField.Size);
 }
 public override bool CanTurn(IGameField field)
 {
     return(_gameBlock.Left.Column > 0 && field[_gameBlock.Left.Row + 1, _gameBlock.Left.Column - 1].Type == GameCellType.None);
 }
 public void Setup()
 {
     this.renderer = new ConsoleRenderer();
     this.field = new GameField(5, 5);
     this.fieldMemoryManager = new FieldMemoryManager();
     this.balloonsFactory = new BalloonsFactory();
 }
Example #21
0
 public void AcceptField(IGameField field)
 {
     _field = field;
     _field.AddObject(this);
 }
        /// <summary>
        /// Refreshes the cell at the given position.
        /// </summary>
        /// <param name="x">The position of the cell on the x-axis.</param>
        /// <param name="y">The position of the cell on the y-axis.</param>
        /// <param name="gameField">The IGameField to pull the data from.</param>
        private void RefreshCell( int x, int y, IGameField gameField )
        {
            bool isAlive = gameField.GetCellStateStrict( x, y );
            Brush brush = this.GetBrush( isAlive );
            Rectangle rect = this.cellField[x, y];

            if( rect.Fill != brush )
            {
                rect.Fill = brush;
            }
        }
        /// <summary>
        /// Refreshes this IGameFieldView based on the given IGameField.
        /// </summary>
        /// <param name="gameField">
        /// The IGameField to 'visualize'.
        /// </param>
        public void Refresh( IGameField gameField )
        {
            int width = gameField.Width;
            int height = gameField.Height;

            for( int x = 0; x < width; ++x )
            {
                for( int y = 0; y < height; ++y )
                {
                    this.RefreshCell( x, y, gameField );
                }
            }
        }
 public SaveCommand(IFieldMemoryManager fieldMemoryManager, IGameField field)
 {
     this.field = field;
     this.fieldMemoryManager = fieldMemoryManager;
     this.Name = "save";
 }
 public void AddField(IGameField field)
 {
     this.allfields.Add(field);
 }
 private void PrepareNewGameRound(IFieldFactory fieldFactory, GameDifficulty gameDifficulty)
 {
     this.field = fieldFactory.CreateGameField(gameDifficulty);
     this.field.Filler = this.engineContext.GameFieldFiller;
     this.field.Fill();
 }
Example #27
0
 public IChecker GetVictim(Coord coord, IGameField field)
 {
     return(CheckerState.GetVictim(CurrentCoord, coord, field));
 }
Example #28
0
 public bool CanFallDown(IGameField field) => _gameBlock.Left.CanFallDown(field) && _gameBlock.Right.CanFallDown(field);
        private bool IsGameFinished(IGameField gameField)
        {
            int rows = gameField.Rows;
            int columns = gameField.Columns;
            for (int row = 0; row < rows; row++)
            {
                for (int column = 0; column < columns; column++)
                {
                    if (gameField[row, column].Symbol != GameConstants.PopedBalloonSymbol)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
Example #30
0
 public abstract bool CanTurn(IGameField field);
Example #31
0
 public void AcceptField(IGameField field)
 {
     _field = field;
 }
Example #32
0
 public abstract bool CanMove(GameSide side, IGameField field);
        private char CountMines(IGameField field, int row, int column)
        {
            int counter = 0;
            int rows = field.Board.GetLength(0);
            int columns = field.Board.GetLength(1);

            if (row - 1 >= 0)
            {
                if (field.Board[row - 1, column] == '*')
                {
                    counter++;
                }
            }

            if (row + 1 < rows)
            {
                if (field.Board[row + 1, column] == '*')
                {
                    counter++;
                }
            }

            if (column - 1 >= 0)
            {
                if (field.Board[row, column - 1] == '*')
                {
                    counter++;
                }
            }

            if (column + 1 < columns)
            {
                if (field.Board[row, column + 1] == '*')
                {
                    counter++;
                }
            }

            if ((row - 1 >= 0) && (column - 1 >= 0))
            {
                if (field.Board[row - 1, column - 1] == '*')
                {
                    counter++;
                }
            }

            if ((row - 1 >= 0) && (column + 1 < columns))
            {
                if (field.Board[row - 1, column + 1] == '*')
                {
                    counter++;
                }
            }

            if ((row + 1 < rows) && (column - 1 >= 0))
            {
                if (field.Board[row + 1, column - 1] == '*')
                {
                    counter++;
                }
            }

            if ((row + 1 < rows) && (column + 1 < columns))
            {
                if (field.Board[row + 1, column + 1] == '*')
                {
                    counter++;
                }
            }

            return char.Parse(counter.ToString());
        }
Example #34
0
 public SmartestPlayer(IGameField selfField) : base(selfField)
 {
 }
Example #35
0
 public void SetUp()
 {
     rules      = GameRules.Default;
     shipsCount = rules.ShipsCount.ToDictionary(x => x.Key, x => x.Value);
     field      = FromLines(rules, SampleField);
 }
Example #36
0
 protected Level(IGameField gameField, IWriter writer, IReader reader)
 {
     this.GameField = gameField;
     this.Writer    = writer;
     this.Reader    = reader;
 }
Example #37
0
 public FirstLevel(IGameField gameField, IWriter writer, IReader reader)
     : base(gameField, writer, reader)
 {
 }
Example #38
0
 public void MovePiece(ref IGameField currentField, ref IGameField fieldToMove)
 {
     // TODO Implement movement
 }
        /// <summary>
        /// Gets whether the given cell is considered 'alive'.
        /// </summary>
        /// <param name="x">The position of the cell on the x-axis.</param>
        /// <param name="y">The position of the cell on the y-axis.</param>
        /// <param name="gameField">The IGameField to pull the data from.</param>
        /// <returns>
        /// Returns 0 if the index is out of valid range or the cell is 'dead';
        /// returns 1 if the cell is 'alive'.
        /// </returns>
        private int GetCellState( int x, int y, IGameField gameField )
        {
            if( this.hasSolidWalls )
            {
                if( x < 0 || x >= gameField.Width )
                    return 0;
                if( y < 0 || y >= gameField.Height )
                    return 0;

                return gameField.GetCellStateStrict( x, y ) ? 1 : 0;
            }
            else
            {
                return gameField.GetCellState( x, y ) ? 1 : 0;
            }
        }
        private void PrintMatrix(IGameField field)
        {
            int rows = field.Rows;
            int columns = field.Columns;

            for (int row = 0; row < rows; row++)
            {
                // Prints rows index
                this.consoleWriter.Write(FieldLeftBorderSymbol, row + 1);

                for (int column = 0; column < columns; column++)
                {
                    if (ObjectValidator.IsGameObjectNull(field[row, column]))
                    {
                        throw new ArgumentNullException(FieldCellNullErrorMessage);
                    }

                    string symbol = field[row, column].Symbol;
                    BalloonsColors symbolColor = field[row, column].Color;

                    ConsoleHelper.ChangeForegroundColorDependingOnSymbol(symbolColor);
                    this.consoleWriter.Write(field[row, column].Symbol + " ");
                }

                Console.ForegroundColor = ConsoleColor.Gray;
                this.consoleWriter.Write(FieldRigthBorderSymbol);
                Console.WriteLine();
            }
        }
 private void ReorderBallons(ReorderBalloonsStrategy reorderStrategy, IGameField gameField)
 {
     reorderStrategy.ReorderBalloons(gameField);
 }
        /// <summary>
        /// Method which knows how to render on console game field matrix.
        /// </summary>
        /// <param name="field">Field to render.</param>
        public void RenderGameField(IGameField field)
        {
            if (ObjectValidator.IsGameObjectNull(field))
            {
                throw new ArgumentNullException(FieldNullErrorMessage);
            }

            int columns = field.Columns;

            // Prints columns index
            this.consoleWriter.Write(Indent);
            for (int i = 0; i < columns; i++)
            {
                this.consoleWriter.Write(" {0}", i + 1);
            }

            Console.WriteLine();

            this.PrintBorder(columns);
            this.PrintMatrix(field);
            this.PrintBorder(columns);
        }
Example #43
0
 public bool CheckPossibilityToKill(Coord coord, IGameField field)
 {
     return(CheckerState.CheckPossibilityToKill(CurrentCoord, coord, field));
 }
Example #44
0
 public override bool CanTurn(IGameField field)
 {
     return(_gameBlock.Right.Row > 0 && field[_gameBlock.Right.Row - 1, _gameBlock.Right.Column + 1].Type == GameCellType.None);
 }
Example #45
0
 public Game(IGameConfiguration gameConfiguration)
 {
     gameField  = new GameField(gameConfiguration.Rows, gameConfiguration.Columns, gameConfiguration.BombsCount);
     bombsCount = gameConfiguration.BombsCount;
 }
 public RestoreCommand(IFieldMemoryManager fieldMemorizerManager, IGameField field)
 {
     this.field = field;
     this.fieldMemorizerManager = fieldMemorizerManager;
     this.Name = "restore";
 }
        public ICommand ProcessCommand(
            string commandString,
            IRenderer renderer,
            IGameField field,
            IFieldMemoryManager fieldMemoryManager,
            IBalloonsFactory balloonsFactory)
        {
            var commandParts = this.SplitCommandString(commandString);
            string commandName = commandParts[0];
            int rowPosition = -1;
            int colPosition = -1;

            if (commandParts.Length == 3)
            {
                bool rowAndColumnPopulated = !(string.IsNullOrWhiteSpace(commandParts[1]) && string.IsNullOrWhiteSpace(commandParts[2]));
                bool rowAsInteger = int.TryParse(commandParts[1], out rowPosition);
                bool columnAsInteger = int.TryParse(commandParts[2], out colPosition);

                if (rowAndColumnPopulated && rowAsInteger && columnAsInteger)
                {
                    rowPosition--;
                    colPosition--;
                }
                else
                {
                    rowPosition = InvalidRowAndColumnPosition;
                    colPosition = InvalidRowAndColumnPosition;
                }
            }

            switch (commandName)
            {
                case "pop":
                    {
                        return new PopBalloonsCommand(balloonsFactory, field, rowPosition, colPosition);
                    }

                case "top":
                    {
                        return new TopScoresCommand(renderer);
                    }

                case "save":
                    {
                        return new SaveCommand(fieldMemoryManager, field);
                    }

                case "restore":
                    {
                        return new RestoreCommand(fieldMemoryManager, field);
                    }

                case "help":
                    {
                        return new HelpCommand(renderer);
                    }

                case "exit":
                    {
                        return new ExitCommand(renderer);
                    }

                default:
                    {
                        throw new InvalidOperationException("Invalid command request!");
                    }
            }
        }
Example #48
0
 public void StartTurn(IGameField field) => turnController.MakeTurn(pos => OnMadeTurn?.Invoke(this, pos));
        /// <summary>
        /// Adds the given ObjectTemplate to the given IGameField.
        /// </summary>
        /// <param name="template">
        /// The template to add.
        /// </param>
        /// <param name="offsetX">
        /// The offset to apply on the x-axis.
        /// </param>
        /// <param name="offsetY">
        /// The offset to apply on the y-axis.
        /// </param>
        /// <param name="gameField">
        /// The IGameField to fill with data.
        /// </param>
        public void AddTemplate( ObjectTemplate template, int offsetX, int offsetY, IGameField gameField )
        {
            this.offsetX = offsetX;
            this.offsetY = offsetY;
            this.gameField = gameField;

            switch( template )
            {
                case ObjectTemplate.Glider:
                    this.AddGlider();
                    break;

                case ObjectTemplate.Chaos:
                    this.AddChaos();
                    break;

                case ObjectTemplate.Laser0:
                    this.AddLaser0();
                    break;

                case ObjectTemplate.Laser2:
                    this.AddLaser2();
                    break;

                case ObjectTemplate.Horseshoe:
                    this.AddHorseshoe();
                    break;

                case ObjectTemplate.Flower:
                    this.AddFlower();
                    break;

                case ObjectTemplate.Claphand:
                    this.AddToad();
                    break;

                case ObjectTemplate.Acorn:
                    this.AddAcorn();
                    break;

                case ObjectTemplate.Octagon:
                    this.AddOctagon();
                    break;

                case ObjectTemplate.Pentadecathlon:
                    this.AddPentadecathlon();
                    break;

                case ObjectTemplate.Bugface:
                    this.AddBugface();
                    break;

                case ObjectTemplate.Tumbler:
                    this.AddTumbler();
                    break;

                case ObjectTemplate.Diehard:
                    this.AddDiehard();
                    break;

                case ObjectTemplate.Pulsar:
                    this.AddPulsar();
                    break;
                
                case ObjectTemplate.QueenBeeShuttle:
                    this.AddQueenBeeShuttle();
                    break;
    
                case ObjectTemplate.SpaceshipLightweight:
                    this.AddLightweightSpaceship();
                    break;

                default:
                    throw new NotImplementedException( template.ToString() );
            }
        }
Example #50
0
 public async Task <ICommand> MakeStep(IGameField grid)
 {
     return(await Task <ICommand> .Run <ICommand>(new Func <ICommand>(MakeTurn)));
 }
 /// <summary>
 /// Abstract interface of a method for reordering matrix.
 /// </summary>
 /// <param name="gameField">The field which will be reordered.</param>
 public abstract void ReorderBalloons(IGameField gameField);
Example #52
0
 public ApplicationControllerTestable()
 {
     _gameField = new GameField();
 }
Example #53
0
 public void Launch(Vector3 direction, bool recochet, IGameField gameField)
 {
     this.direction = direction;
     this.recochet  = recochet;
     this.gameField = gameField;
 }
Example #54
0
 public ApplicationControllerTestable(IGameField gameField)
 {
     _gameField = gameField;
 }
        private void ChancheTurns(IGameField field, IGameField mines, int row, int column)
        {
            char numberOfMines = CountMines(mines, row, column);

            mines.Board[row, column] = numberOfMines;
            field.Board[row, column] = numberOfMines;
        }
Example #56
0
 public SecondLevel(IGameField gameField, IWriter writer, IReader reader)
     : base(gameField, writer, reader)
 {
 }
        public void Run()
        {
            this.isStarted = true;

            IExecutable command = null;

            while (this.isStarted)
            {
                if (flag)
                {
                    this.Writer.WriteLine(
                        "Lets play “Mini4KI”. Try your luck to find all cells wuthout mines."
                        + " Command 'top' showes the scores, 'restart' starts new game, 'exit' quits the game!");

                    MakeBorders(gameField);

                    this.flag = false;
                }

                this.Writer.Write("Enter row[0...4] and column[0...9], separated by space: ");

                this.input = Console.ReadLine().Trim();

                string line = this.Reader.ReadNextLine().Trim();

                // string[] inputArgs = line.Split(' ');
                //
                // command = this.commandManager.ManageCommand(line);
                //
                // try
                // {
                //     command.OnExecuting += (sender, args) =>
                //     {
                //         this.isStarted = !args.Stopped;
                //     };
                //
                //     command.Execute();
                // }
                // catch (Exception e)
                // {
                //     this.Writer.WriteLine(e.Message);
                // }

                if (this.input.Length >= 3)
                {
                    int row = 0;
                    int column = 0;

                    if (int.TryParse(this.input[0].ToString(), out row) && int.TryParse(this.input[2].ToString(), out column)
                        && row <= this.gameField.Board.GetLength(0) && column <= this.gameField.Board.GetLength(1))
                    {
                        this.input = "turn";
                    }
                }

                switch (this.input)
                {
                    case "top":
                        ShowScores(this.players);
                        break;
                    case "restart":
                        this.gameField = FieldsFactory.Create();
                        this.mines = InsertMines();
                        MakeBorders(this.gameField);
                        this.grum = false;
                        this.flag = false;
                        break;
                    case "exit":
                        this.Writer.WriteLine("Bye, bye, bye!");

                        break;
                    case "turn":
                        if (this.mines.Board[row, column] != '*')
                        {
                            if (this.mines.Board[row, column] == '-')
                            {
                                ChancheTurns(this.gameField, this.mines, row, column);
                                this.counter++;
                            }

                            if (maks == this.counter)
                            {
                                this.flag2 = true;
                            }
                            else
                            {
                                MakeBorders(gameField);
                            }
                        }
                        else
                        {
                            grum = true;
                        }

                        break;
                    default:
                        this.Writer.WriteLine("\nError! Invalid input\n");
                        break;
                }

                if (grum)
                {
                    MakeBorders(mines);

                    this.Writer.Write(string.Format("\nHrrrrrr! You have died with {0} scores. " + "Enter nickName: ", counter));

                    string nickName = this.Reader.ReadNextLine();

                    Player player = new Player(nickName, counter);

                    if (players.Count < 5)
                    {
                        players.Add(player);
                    }
                    else
                    {
                        for (int i = 0; i < players.Count; i++)
                        {
                            if (players[i].Scores < player.Scores)
                            {
                                players.Insert(i, player);
                                players.RemoveAt(players.Count - 1);
                                break;
                            }
                        }
                    }

                    players.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name));

                    players.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Scores.CompareTo(firstPlayer.Scores));
                    ShowScores(players);

                    gameField = FieldsFactory.Create();
                    mines = InsertMines();
                    counter = 0;
                    grum = false;
                    flag = true;
                }

                if (flag2)
                {
                    this.Writer.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    MakeBorders(mines);
                    this.Writer.WriteLine("Enter your name: ");

                    string name = this.Reader.ReadNextLine();

                    Player player = new Player(name, counter);
                    players.Add(player);
                    ShowScores(players);
                    gameField = FieldsFactory.Create();
                    mines = InsertMines();
                    counter = 0;
                    flag2 = false;
                    flag = true;
                }

                this.Writer.WriteLine("Made in Bulgaria - Uauahahahahaha!");
                this.Writer.WriteLine("AREEEEEEeeeeeee.");

                Console.Read();
            }
        }
Example #58
0
 public virtual IViewModel BuildMainViewModel(IGameField gameField, IGameScoreManager gameScoreManager, INewViewFactory newViewFactory) =>
 new MainViewModel(gameField, gameScoreManager, newViewFactory);