public IPlayer CreatePlayer(IRegistration playerParameters)
        {
            string name, spaceshipModel, engineModel, armourModel, weaponModel;

            name           = playerParameters.ParametersForPlayer["name"];
            spaceshipModel = playerParameters.ParametersForPlayer["ship"];
            engineModel    = playerParameters.ParametersForPlayer["engine"];
            armourModel    = playerParameters.ParametersForPlayer["armour"];
            weaponModel    = playerParameters.ParametersForPlayer["weapon"];

            ISpaceshipEngine engine = engineFactory.CreateEngine(engineModel);
            IArmour          armour = armourFactory.CreateArmour(armourModel);
            IWeapon          weapon = weaponFactory.CreateWeapon(weaponModel.ToLower());

            weapon.Bullet = bulletFactory.CreateBullet();
            ISpaceShip spaceship = spaceshipFactory.CreateSpaceship(spaceshipModel, engine, armour, weapon);
            IPlayer    player    = playerFactory.CreatePlayer(name, spaceship);

            return(player);
        }
示例#2
0
        public void Run()
        {
            var gameOver = false;

            var engine = engineFactory.CreateEngine(8, 20);

            SetNextActiveShape(engine);

            var inputTask = Task.Factory.StartNew(() => inputService.HandleCommand(engine));

            var moveStep = new Stopwatch();

            moveStep.Start();

            while (!gameOver)
            {
                if (moveStep.ElapsedMilliseconds > Math.Max((int)(1500 - (engine.rowsCompleted / 10) * 100), 250))
                {
                    var activeShapeStatus = MoveShape(engine.field, MoveDirection.DOWN);
                    fieldService.DrawField(engine.field, engine.rowsCompleted);

                    moveStep.Restart();

                    gameOver = HandleMovedShape(activeShapeStatus, engine);
                }
                else if (engine.keyPressed != KeyInput.NO_COMMAND)
                {
                    Console.WriteLine(engine.keyPressed);

                    //hook up all the commands
                    switch (engine.keyPressed)
                    {
                    case KeyInput.QUIT:
                        gameOver = true;
                        break;

                    case KeyInput.MOVE_LEFT:
                    {
                        var activeShapeStatus = MoveShape(engine.field, MoveDirection.LEFT);
                        fieldService.DrawField(engine.field, engine.rowsCompleted);

                        gameOver = HandleMovedShape(activeShapeStatus, engine);
                        break;
                    }

                    case KeyInput.MOVE_RIGHT:
                    {
                        var activeShapeStatus = MoveShape(engine.field, MoveDirection.RIGHT);
                        fieldService.DrawField(engine.field, engine.rowsCompleted);

                        gameOver = HandleMovedShape(activeShapeStatus, engine);
                        break;
                    }

                    case KeyInput.MOVE_DOWN:
                    {
                        var activeShapeStatus = MoveShape(engine.field, MoveDirection.DOWN);
                        fieldService.DrawField(engine.field, engine.rowsCompleted);
                        moveStep.Restart();

                        gameOver = HandleMovedShape(activeShapeStatus, engine);
                        break;
                    }

                    case KeyInput.ROTATE_LEFT:
                        RotateShape(engine.field, RotationDirection.COUNTER_CLOCKWISE);
                        fieldService.DrawField(engine.field, engine.rowsCompleted);
                        break;

                    case KeyInput.ROTATE_RIGHT:
                        RotateShape(engine.field, RotationDirection.CLOCKWISE);
                        fieldService.DrawField(engine.field, engine.rowsCompleted);
                        break;

                    default:
                        break;
                    }

                    engine.keyPressed = KeyInput.NO_COMMAND;
                }
            }

            Console.WriteLine("Game over.");
        }