コード例 #1
0
        public void When_Observing_Key_During_Remove_Durability_Constraint_Is_Reached()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new PooledIOService(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
#pragma warning disable 618
                new DefaultTranscoder(new DefaultConverter(), new DefaultSerializer()));

#pragma warning restore 618

            var configInfo = provider.GetConfig("default");

            var clusterController = new Mock <IClusterController>();
            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());

            var pending = new ConcurrentDictionary <uint, IOperation>();

            var observer          = new KeyObserver(pending, configInfo, clusterController.Object, 10, 500);
            var constraintReached = observer.ObserveRemove("Test_Timeout_Remove", 0, ReplicateTo.Zero, PersistTo.One);
            Assert.IsTrue(constraintReached);
        }
コード例 #2
0
ファイル: Indicator.cs プロジェクト: Vascord/LP2_2project
 /// <summary>
 /// Public override method which initiates at the first frame.
 /// </summary>
 public override void Start()
 {
     keyObserver = ParentGameObject.GetComponent <KeyObserver>();
     position    = ParentGameObject.GetComponent <Position>();
     x           = position.Pos.X;
     option      = 0;
 }
コード例 #3
0
        public async void When_Observing_Key_During_RemoveAsync_Durability_Constraint_Is_Reached()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

            var configInfo = provider.GetConfig("default");

            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveRemoveAsync("Test_Timeout_Remove_Async", 0, ReplicateTo.Zero, PersistTo.One);

            Assert.IsTrue(constraintReached);
        }
コード例 #4
0
 /// <summary>
 /// Initialize player controller
 /// </summary>
 public override void Start()
 {
     _player      = ParentGameObject as Player;
     _keyObserver = _player.GetComponent <KeyObserver>();
     _transform   = _player.GetComponent <Transform>();
     _collider    = _player.GetComponent <ObjectCollider>();
     _rndr        = new Render();
 }
コード例 #5
0
        public void When_PersistTo_Is_Greater_Than_ReplicateTo_Length_Of_Replicas_Is_PersistTo()
        {
            var vBucket  = new VBucket(null, 0, 0, new[] { 0, 2, 1 });
            var expected = new[] { 0, 2 };
            var observer = new KeyObserver(null, 10, 500);
            var actual   = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(actual.Count, (int)PersistTo.Two);
        }
コード例 #6
0
        public void When_No_Replicas_Are_Found_GetReplicas_Returns_Empty_List()
        {
            var vBucket  = new VBucket(null, 0, 0, new[] { -1, -1, -1 });
            var expected = new int[] {};
            var observer = new KeyObserver(null, 10, 500);
            var actual   = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expected.Count(), actual.Count());
        }
コード例 #7
0
        public async Task Test_Timeout_Add_PersistTo_Master_Async()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new PooledIOService(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

            var configInfo = provider.GetConfig("default");

            var key = "Test_Timeout_Add_PersistTo_Master_Async";
            IOperationResult result;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove(key);
                    result = bucket.Insert(key, "");
                }
            }

            var clusterController = new Mock <IClusterController>();

            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());

            var pending = new ConcurrentDictionary <uint, IOperation>();

            var observer = new KeyObserver(pending, configInfo, clusterController.Object, 10, 500);

            using (var cts = new CancellationTokenSource(configuration.ObserveTimeout))
            {
                var constraintReached =
                    await observer.ObserveAddAsync(key, result.Cas, ReplicateTo.Zero, PersistTo.Zero, cts);

                Assert.IsTrue(constraintReached);
            }
        }
コード例 #8
0
        public void When_No_Replicas_Are_Found_GetReplicas_Returns_Empty_List()
        {
            var vBucket = new VBucket(null, 0, 0, new[] { -1, -1, -1 }, 0, new VBucketServerMap {
                ServerList = new string[] { }
            }, "default");
            var expected = new int[] {};

            var clusterController = new Mock <IClusterController>();

            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());
            var pending  = new ConcurrentDictionary <uint, IOperation>();
            var observer = new KeyObserver(pending, null, clusterController.Object, 10, 500);

            var actual = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expected.Count(), actual.Count());
        }
コード例 #9
0
    public void SetButtonType(int playerIndex, int upgradeLevel, UpgradeTabContentComponent.UpgradeType type)
    {
        switch (type)
        {
        case UpgradeTabContentComponent.UpgradeType.Attackiness:
            // upgradeKey = PlayerAttributes.GetAttackinessUpgradeKey(upgradeLevel, playerIndex);
            break;

        case UpgradeTabContentComponent.UpgradeType.Healthiness:
            upgradeKey = "";
            break;

        default:
            throw new System.Exception("Unknown Upgradetype " + type);
        }
        observer = new KeyObserver <string, Upgrade>(SingletonProvider.MainUpgradeManager, upgradeKey, UpdateText);
        UpdateText(SingletonProvider.MainUpgradeManager.GetUpgrade(upgradeKey));
    }
コード例 #10
0
        public void When_PersistTo_Is_Greater_Than_ReplicateTo_Length_Of_Replicas_Is_PersistTo()
        {
            var vBucket = new VBucket(null, 0, 0, new[] { 0, 2, 1 }, 0, new VBucketServerMap {
                ServerList = new string[] { }
            }, "default");
            var expected = new[] { 0, 2 };

            var clusterController = new Mock <IClusterController>();

            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());
            var pending  = new ConcurrentDictionary <uint, IOperation>();
            var observer = new KeyObserver(pending, null, clusterController.Object, 10, 500);

            var actual = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(actual.Count, (int)PersistTo.Two);
        }
コード例 #11
0
        public void When_Mutation_Happens_Observe_Fails()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new PooledIOService(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

            var configInfo = provider.GetConfig("default");

            ulong cas = 0;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove("When_Mutation_Happens_Observe_Fails");
                    cas = bucket.Insert("When_Mutation_Happens_Observe_Fails", "").Cas;
                    bucket.Upsert("When_Mutation_Happens_Observe_Fails", "");
                }
            }
            var clusterController = new Mock <IClusterController>();

            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());

            var pending = new ConcurrentDictionary <uint, IOperation>();

            var observer          = new KeyObserver(pending, configInfo, clusterController.Object, 10, 500);
            var constraintReached = observer.ObserveAdd("When_Mutation_Happens_Observe_Fails", cas, ReplicateTo.One, PersistTo.One);

            Assert.IsFalse(constraintReached);
        }
コード例 #12
0
        public async void When_Mutation_Happens_Observe_Fails_Async()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

            var configInfo = provider.GetConfig("default");

            var   key = "When_Mutation_Happens_Observe_Fails_async";
            ulong cas = 0;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove(key);
                    cas = bucket.Insert(key, "").Cas;
                    bucket.Upsert(key, "");
                }
            }
            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveAddAsync(key, cas, ReplicateTo.One, PersistTo.One);

            Assert.IsFalse(constraintReached);
        }
コード例 #13
0
        public async void Test_Timeout_Add_PersistTo_Master_Async()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

            var configInfo = provider.GetConfig("default");

            var key = "Test_Timeout_Add_PersistTo_Master_Async";
            IOperationResult result;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove(key);
                    result = bucket.Insert(key, "");
                }
            }

            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveAddAsync(key, result.Cas, ReplicateTo.Zero, PersistTo.Zero);

            Assert.IsTrue(constraintReached);
        }
コード例 #14
0
        public async Task When_Observing_Key_During_AddAsync_Durability_Constraint_Is_Reached()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new PooledIOService(pool),
                (config, endpoint) => new ConnectionPool <Connection>(config, endpoint),
                SaslFactory.GetFactory(),
                new DefaultConverter(),
                new DefaultTranscoder(new DefaultConverter()));

            var configInfo = provider.GetConfig("default");

            var   key = "Test_Timeout_Add_Async";
            ulong cas = 0;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove(key);
                    bucket.Insert(key, "");
                    cas = bucket.Upsert(key, "").Cas;
                }
            }
            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = await observer.ObserveAddAsync(key, cas, ReplicateTo.Zero, PersistTo.Zero);

            Assert.IsTrue(constraintReached);
        }
コード例 #15
0
        public void When_Observing_Key_During_Add_Durability_Constraint_Is_Reached()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool <EapConnection>(config, endpoint),
                SaslFactory.GetFactory3(),
                new AutoByteConverter(),
                new DefaultTranscoder(new AutoByteConverter()));

            var configInfo = provider.GetConfig("default");

            ulong cas = 0;

            using (var cluster = new Cluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove("Test_Timeout_Add");
                    bucket.Insert("Test_Timeout_Add", "");
                    cas = bucket.Upsert("Test_Timeout_Add", "").Cas;
                }
            }
            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = observer.ObserveAdd("Test_Timeout_Add", cas, ReplicateTo.One, PersistTo.One);

            Assert.IsTrue(constraintReached);
        }
コード例 #16
0
        public void Test_Timeout_Add_PersistTo_Master()
        {
            var configuration = new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
                }
            };

            configuration.Initialize();

            var provider = new CarrierPublicationProvider(
                configuration,
                (pool) => new DefaultIOStrategy(pool),
                (config, endpoint) => new ConnectionPool <EapConnection>(config, endpoint),
                SaslFactory.GetFactory3(),
                new AutoByteConverter(),
                new TypeSerializer(new AutoByteConverter()));

            var configInfo = provider.GetConfig("default");

            using (var cluster = new CouchbaseCluster(configuration))
            {
                using (var bucket = cluster.OpenBucket())
                {
                    bucket.Remove("Test_Timeout_Add_PersistTo_Master");
                    bucket.Insert("Test_Timeout_Add_PersistTo_Master", "");
                }
            }

            var observer          = new KeyObserver(configInfo, 10, 500);
            var constraintReached = observer.ObserveAdd("Test_Timeout_Add_PersistTo_Master", 0, ReplicateTo.Zero, PersistTo.Zero);

            Assert.IsTrue(constraintReached);
        }
コード例 #17
0
        /// <summary>
        /// Private method which makes the scene and put the following
        /// game objects on it for the help menu.
        /// </summary>
        private void CreateHelp()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Enter };
            gameScene = new Scene(
                xdim,
                ydim,
                new InputHandler(quitKeys),
                new ConsoleRenderer(xdim, ydim, new ConsolePixel(' ')),
                new CollisionHandler(xdim, ydim));

            // Creates help instruction
            char[,] instructionsSprite =
            {
                { 'M', ' ', 'J', ' ', 'S', ' ', 'E' },
                { 'o', ' ', 'u', ' ', 't', ' ', 'x' },
                { 'v', ' ', 'm', ' ', 'r', ' ', 'i' },
                { 'e', ' ', 'p', ' ', 'a', ' ', 't' },
                { 'm', ' ', ':', ' ', 'i', ' ', ' ' },
                { 'e', ' ', ' ', ' ', 'g', ' ', 'T' },
                { 'n', ' ', 'S', ' ', 't', ' ', 'o' },
                { 't', ' ', 'p', ' ', ' ', ' ', ' ' },
                { ':', ' ', 'a', ' ', 'J', ' ', 'M' },
                { ' ', ' ', 'c', ' ', 'u', ' ', 'a' },
                { 'A', ' ', 'e', ' ', 'm', ' ', 'i' },
                { 'r', ' ', ' ', ' ', 'p', ' ', 'n' },
                { 'r', ' ', '+', ' ', ':', ' ', ' ' },
                { 'o', ' ', ' ', ' ', ' ', ' ', 'M' },
                { 'w', ' ', 'L', ' ', 'A', ' ', 'e' },
                { 's', ' ', 'a', ' ', 'r', ' ', 'n' },
                { ' ', ' ', 's', ' ', 'r', ' ', 'u' },
                { 'L', ' ', 't', ' ', 'o', ' ', ':' },
                { 'e', ' ', ' ', ' ', 'w', ' ', ' ' },
                { 'f', ' ', 'p', ' ', ' ', ' ', 'E' },
                { 't', ' ', 'r', ' ', 'U', ' ', 's' },
                { ' ', ' ', 'e', ' ', 'p', ' ', 'c' },
                { 'a', ' ', 's', ' ', ' ', ' ', 'a' },
                { 'n', ' ', 's', ' ', 't', ' ', 'p' },
                { 'd', ' ', 'e', ' ', 'h', ' ', 'e' },
                { ' ', ' ', 'd', ' ', 'e', ' ', ' ' },
                { 'R', ' ', ' ', ' ', 'n', ' ', ' ' },
                { 'i', ' ', 'A', ' ', ' ', ' ', ' ' },
                { 'g', ' ', 'r', ' ', 'S', ' ', ' ' },
                { 'h', ' ', 'r', ' ', 'p', ' ', ' ' },
                { 't', ' ', 'o', ' ', 'a', ' ', ' ' },
                { ' ', ' ', 'w', ' ', 'c', ' ', ' ' },
                { ' ', ' ', ' ', ' ', 'e', ' ', ' ' },
            };
            GameObject instructions    = new GameObject("Instructions");
            Position   instructionsPos = new Position(60f, 10f, 0f);

            instructions.AddComponent(instructionsPos);
            instructions.AddComponent(new ConsoleSprite(
                                          instructionsSprite, ConsoleColor.Red, ConsoleColor.Gray));
            gameScene.AddGameObject(instructions);

            // Creates the button to return to the menu
            char[,] buttonSprite =
            {
                { 'B' },
                { 'a' },
                { 'c' },
                { 'k' },
            };
            GameObject button    = new GameObject("Button");
            Position   buttonPos = new Position(73f, 23f, 1f);

            button.AddComponent(buttonPos);
            button.AddComponent(new ConsoleSprite(
                                    buttonSprite, ConsoleColor.Red, ConsoleColor.Blue));
            gameScene.AddGameObject(button);

            // Creates the indicator to press the buttons
            char[,] indicatorSprite =
            {
                { '>' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { '<' },
            };
            KeyObserver indicatorKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.W, ConsoleKey.S, ConsoleKey.Enter });
            GameObject indicator    = new GameObject("Indicator");
            Position   indicatorPos = new Position(72f, 23f, 0f);

            indicator.AddComponent(indicatorKeyListener);
            indicator.AddComponent(new ReturnMenu());
            indicator.AddComponent(indicatorPos);
            indicator.AddComponent(new ConsoleSprite(
                                       indicatorSprite, ConsoleColor.Red, ConsoleColor.DarkBlue));
            gameScene.AddGameObject(indicator);
        }
コード例 #18
0
ファイル: Game.cs プロジェクト: FPTheFluffyPawed/lp2_2019_p2
        private Game()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Escape };
            gameScene = new Scene(xdim, ydim,
                                  new InputHandler(quitKeys),
                                  new ConsoleRenderer(xdim, ydim, new ConsolePixel('.')),
                                  new CollisionHandler(xdim, ydim));

            // Create quitter object
            GameObject  quitter = new GameObject("Quitter");
            KeyObserver quitSceneKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.Escape });

            quitter.AddComponent(quitSceneKeyListener);
            quitter.AddComponent(new Quitter());
            gameScene.AddGameObject(quitter);

            // Create player object
            char[,] playerSprite =
            {
                { '-', '|', '-' },
                { '-', '0', '-' },
                { '-', '|', '-' }
            };
            GameObject  player            = new GameObject("Player");
            KeyObserver playerKeyListener = new KeyObserver(new ConsoleKey[] {
                ConsoleKey.DownArrow,
                ConsoleKey.UpArrow,
                ConsoleKey.RightArrow,
                ConsoleKey.LeftArrow
            });

            player.AddComponent(playerKeyListener);
            Position playerPos = new Position(10f, 10f, 0f);

            player.AddComponent(playerPos);
            player.AddComponent(new Player());
            player.AddComponent(new ConsoleSprite(
                                    playerSprite, ConsoleColor.Red, ConsoleColor.DarkGreen));
            gameScene.AddGameObject(player);

            // Create walls
            GameObject   walls     = new GameObject("Walls");
            ConsolePixel wallPixel = new ConsolePixel(
                '#', ConsoleColor.Blue, ConsoleColor.White);
            Dictionary <Vector2, ConsolePixel> wallPixels =
                new Dictionary <Vector2, ConsolePixel>();

            for (int x = 0; x < xdim; x++)
            {
                wallPixels[new Vector2(x, 0)] = wallPixel;
            }
            for (int x = 0; x < xdim; x++)
            {
                wallPixels[new Vector2(x, ydim - 1)] = wallPixel;
            }
            for (int y = 0; y < ydim; y++)
            {
                wallPixels[new Vector2(0, y)] = wallPixel;
            }
            for (int y = 0; y < ydim; y++)
            {
                wallPixels[new Vector2(xdim - 1, y)] = wallPixel;
            }
            walls.AddComponent(new ConsoleSprite(wallPixels));
            walls.AddComponent(new Position(0, 0, 1));
            gameScene.AddGameObject(walls);

            // Create game object for showing date and time
            GameObject dtGameObj = new GameObject("Time");

            dtGameObj.AddComponent(new Position(xdim / 2 + 1, 0, 10));
            RenderableStringComponent rscDT = new RenderableStringComponent(
                () => DateTime.Now.ToString("F"),
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta, ConsoleColor.White);

            dtGameObj.AddComponent(rscDT);
            gameScene.AddGameObject(dtGameObj);

            // Create game object for showing position
            GameObject pos = new GameObject("Position");

            pos.AddComponent(new Position(1, 0, 10));
            RenderableStringComponent rscPos = new RenderableStringComponent(
                () => $"({playerPos.Pos.X}, {playerPos.Pos.Y})",
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta, ConsoleColor.White);

            pos.AddComponent(rscPos);
            gameScene.AddGameObject(pos);
        }
コード例 #19
0
 public override void Start()
 {
     keyObserver = ParentGameObject.GetComponent <KeyObserver>();
 }
コード例 #20
0
ファイル: Menu.cs プロジェクト: Vascord/LP2_2project
        /// <summary>
        /// Private method which makes the scene and put the following
        /// game objects on it for the menu.
        /// </summary>
        private void CreateMenu()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Enter };
            gameScene = new Scene(
                xdim,
                ydim,
                new InputHandler(quitKeys),
                new ConsoleRenderer(xdim, ydim, new ConsolePixel(' ')),
                new CollisionHandler(xdim, ydim));

            // Creates title
            char[,] titleSprite =
            {
                { '█', '█', '█', ' ', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', ' ', '█', ' ', ' ', '█', ' ', ' ', ' ' },
                { '█', ' ', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { ' ', ' ', ' ', ' ', '█', ' ', '█', ' ', '█', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', ' ', ' ', ' ', '█', ' ', '█', '█', ' ' },
                { '█', '█', '█', ' ', ' ', ' ', '█', '█', '█', ' ', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', ' ', ' ', ' ', '█' },
                { '█', ' ', '█', ' ', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', ' ', '█', ' ', '█', ' ', ' ', ' ', '█' },
                { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
                { '█', '█', '█', '█', '█', ' ', '█', '█', '█', '█', '█' },
                { '█', ' ', '█', '█', ' ', ' ', '█', ' ', ' ', ' ', '█' },
                { '█', '█', '█', ' ', '█', ' ', '█', '█', '█', '█', '█' },
            };
            GameObject title    = new GameObject("Title");
            Position   titlePos = new Position(65f, 3f, 0f);

            title.AddComponent(titlePos);
            title.AddComponent(new Title());
            title.AddComponent(new ConsoleSprite(
                                   titleSprite, ConsoleColor.Red, ConsoleColor.Gray));
            gameScene.AddGameObject(title);

            // Creates buttons
            char[,] buttonSprite1 =
            {
                { 'L' },
                { 'e' },
                { 'v' },
                { 'e' },
                { 'l' },
                { '1' },
            };
            char[,] buttonSprite2 =
            {
                { 'L' },
                { 'e' },
                { 'v' },
                { 'e' },
                { 'l' },
                { '2' },
            };
            char[,] buttonSprite3 =
            {
                { 'H' },
                { 'e' },
                { 'l' },
                { 'p' },
            };
            char[,] buttonSprite4 =
            {
                { 'Q' },
                { 'u' },
                { 'i' },
                { 't' },
            };
            GameObject button1    = new GameObject("Button1");
            GameObject button2    = new GameObject("Button2");
            GameObject button3    = new GameObject("Button3");
            GameObject button4    = new GameObject("Button4");
            Position   buttonPos1 = new Position(72f, 19f, 1f);
            Position   buttonPos2 = new Position(72f, 21f, 1f);
            Position   buttonPos3 = new Position(73f, 23f, 1f);
            Position   buttonPos4 = new Position(73f, 25f, 1f);

            button1.AddComponent(buttonPos1);
            button2.AddComponent(buttonPos2);
            button3.AddComponent(buttonPos3);
            button4.AddComponent(buttonPos4);
            button1.AddComponent(new ConsoleSprite(
                                     buttonSprite1, ConsoleColor.Red, ConsoleColor.Blue));
            button2.AddComponent(new ConsoleSprite(
                                     buttonSprite2, ConsoleColor.Red, ConsoleColor.Blue));
            button3.AddComponent(new ConsoleSprite(
                                     buttonSprite3, ConsoleColor.Red, ConsoleColor.Blue));
            button4.AddComponent(new ConsoleSprite(
                                     buttonSprite4, ConsoleColor.Red, ConsoleColor.Blue));
            gameScene.AddGameObject(button1);
            gameScene.AddGameObject(button2);
            gameScene.AddGameObject(button3);
            gameScene.AddGameObject(button4);

            // Creates indicator
            char[,] indicatorSprite =
            {
                { '>' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { ' ' },
                { '<' },
            };
            KeyObserver indicatorKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.UpArrow, ConsoleKey.DownArrow, ConsoleKey.Enter });
            GameObject indicator    = new GameObject("Indicator");
            Position   indicatorPos = new Position(70f, 19f, 0f);

            indicator.AddComponent(indicatorKeyListener);
            indicator.AddComponent(new Indicator());
            indicator.AddComponent(indicatorPos);
            indicator.AddComponent(new ConsoleSprite(
                                       indicatorSprite, ConsoleColor.Red, ConsoleColor.DarkBlue));
            gameScene.AddGameObject(indicator);
        }
コード例 #21
0
        /// <summary>
        /// Starts game by showing menu and instantiating player
        /// </summary>
        public void Start()
        {
            // Create quitter object
            GameObject  quitter = new GameObject("Quitter");
            KeyObserver quitSceneKeyListener = new KeyObserver(new ConsoleKey[]
                                                               { ConsoleKey.Escape });

            quitter.AddComponent(quitSceneKeyListener);
            quitter.AddComponent(new Quitter());
            _scene.AddGameObject(quitter);

            // Instance variables for player
            Role   role;
            string name;

            // Render Start menu with options
            _render.StartMenu(out role);
            name = _render.AssignName();

            // Instantiate dungeon with number of rooms
            Dungeon _dungeon;

            _dungeon = new Dungeon(_rnd.Next(2, 10), _rnd);
            _scene.AddGameObject(_dungeon);

            CreateDungeons(_scene);

            // Instantiate player
            char[,] playerSprite = { { 'O' } };
            _player = new Player(role, name);
            KeyObserver playerKeys = new KeyObserver(new ConsoleKey[]
            {
                ConsoleKey.W,
                ConsoleKey.A,
                ConsoleKey.S,
                ConsoleKey.D,
                ConsoleKey.C,
                ConsoleKey.E,
                ConsoleKey.Spacebar
            });

            _player.AddComponent(playerKeys);
            _player.AddComponent(new PlayerController());
            _player.AddComponent(new Transform(5f, _y / 6 + 1, 2f));
            _player.AddComponent(new ConsoleSprite(
                                     playerSprite, ConsoleColor.White, ConsoleColor.Blue));
            _player.AddComponent(new ObjectCollider());

            _scene.AddGameObject(_player);

            _scene.GameLoop(_frameLength);

            if (_player.Life <= 0)
            {
                // LOST
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Black;
                _render.Loser(_player);
            }
            if (_dungeon.CheckAliveDead())
            {
                // WIN
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Black;
                _render.Victory(_player);
            }
        }
コード例 #22
0
ファイル: Level1.cs プロジェクト: Vascord/LP2_2project
        /// <summary>
        /// Creates the first Level GameObjects.
        /// </summary>
        private void CreateLevel()
        {
            // Create scene
            ConsoleKey[] quitKeys = new ConsoleKey[] { ConsoleKey.Escape };
            gameScene = new Scene(
                xdim,
                ydim,
                new InputHandler(quitKeys),
                new ConsoleRenderer(xdim, ydim, new ConsolePixel(' ')),
                new CollisionHandler(xdim, ydim));

            // Create walls
            GameObject   walls     = new GameObject("Walls");
            ConsolePixel wallPixel = new ConsolePixel(
                ' ', ConsoleColor.Blue, ConsoleColor.DarkGray);
            Dictionary <Vector2, ConsolePixel> wallPixels =
                new Dictionary <Vector2, ConsolePixel>();

            for (int x = 0; x < xdim; x++)
            {
                // Ground and walls
                if ((x > 0 && x < 25) ||
                    (x > 30 && x < 127) ||
                    (x > 135 && x < xdim))
                {
                    wallPixels[new Vector2(x, ydim - 1)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 1));
                    wallPixels[new Vector2(x, ydim - 2)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 2));
                    wallPixels[new Vector2(x, ydim - 3)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 3));
                    wallPixels[new Vector2(x, ydim - 4)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 4));
                    wallPixels[new Vector2(x, ydim - 5)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 5));
                    wallPixels[new Vector2(x, ydim - 6)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 6));
                    wallPixels[new Vector2(x, ydim - 7)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 7));
                }

                // Platform
                if (x > 30 && x < 45)
                {
                    wallPixels[new Vector2(x, ydim - 18)] = wallPixel;
                    occupied.Add(new Vector2(x, ydim - 18));
                }
            }

            for (int y = 0; y < ydim; y++)
            {
                wallPixels[new Vector2(0, y)] = wallPixel;
                occupied.Add(new Vector2(0, y));
                wallPixels[new Vector2(xdim - 1, y)] = wallPixel;
                occupied.Add(new Vector2(xdim - 1, y));
            }

            // Create obstacles
            GameObject   obstacle      = new GameObject("Obstacle");
            ConsolePixel obstaclePixel = new ConsolePixel(
                ' ', ConsoleColor.Blue, ConsoleColor.Green);
            Dictionary <Vector2, ConsolePixel> obstaclePixels =
                new Dictionary <Vector2, ConsolePixel>();

            obstaclePixels[new Vector2(49, 19)] = obstaclePixel;
            occupied.Add(new Vector2(49, 19));

            obstaclePixels[new Vector2(52, 19)] = obstaclePixel;
            occupied.Add(new Vector2(52, 19));

            obstaclePixels[new Vector2(50, 20)] = obstaclePixel;
            occupied.Add(new Vector2(50, 20));

            obstaclePixels[new Vector2(50, 21)] = obstaclePixel;
            occupied.Add(new Vector2(50, 21));

            obstaclePixels[new Vector2(50, 19)] = obstaclePixel;
            occupied.Add(new Vector2(50, 19));

            obstaclePixels[new Vector2(50, 22)] = obstaclePixel;
            occupied.Add(new Vector2(50, 22));

            obstaclePixels[new Vector2(51, 20)] = obstaclePixel;
            occupied.Add(new Vector2(51, 20));

            obstaclePixels[new Vector2(51, 21)] = obstaclePixel;
            occupied.Add(new Vector2(51, 21));

            obstaclePixels[new Vector2(51, 19)] = obstaclePixel;
            occupied.Add(new Vector2(51, 19));

            obstaclePixels[new Vector2(51, 22)] = obstaclePixel;
            occupied.Add(new Vector2(51, 22));

            walls.AddComponent(new ConsoleSprite(wallPixels));
            walls.AddComponent(new Position(0, 0, 1));
            gameScene.AddGameObject(walls);

            obstacle.AddComponent(new ConsoleSprite(obstaclePixels));
            obstacle.AddComponent(new Position(0, 0, 0));
            gameScene.AddGameObject(obstacle);

            // Create game object for showing score
            GameObject score = new GameObject("Score");

            score.AddComponent(new Position(1, 0, 10));
            score.AddComponent(new Score());
            RenderableStringComponent visualScore = new RenderableStringComponent(
                () => "Score: " + 3000.ToString(),
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta,
                ConsoleColor.White);

            score.AddComponent(visualScore);
            gameScene.AddGameObject(score);

            // Create Coin Sprite
            char[,] coinSprite =
            {
                { '█' },
            };

            // Coin 1
            GameObject coin1 = new GameObject("Coin1");

            coin1.AddComponent(new ConsoleSprite(coinSprite));
            coin1.AddComponent(new Position(80, 19, 0f));
            coin1.AddComponent(new CoinConfirmation());
            gameScene.AddGameObject(coin1);
            coins.Add(coin1);

            // Coin 2
            GameObject coin2 = new GameObject("Coin2");

            coin2.AddComponent(new ConsoleSprite(coinSprite));
            coin2.AddComponent(new Position(35, 8, 0f));
            coin2.AddComponent(new CoinConfirmation());
            gameScene.AddGameObject(coin2);
            coins.Add(coin2);

            // Box sprite
            char[,] boxSprite =
            {
                { '█', '█', '█', '█' },
                { '█', '?', '?', '█' },
                { '█', '?', '?', '█' },
                { '█', '?', '?', '█' },
                { '█', '?', '?', '█' },
                { '█', '█', '█', '█' },
            };

            // Create Box1
            GameObject box = new GameObject("Box");

            box.AddComponent(new ConsoleSprite(
                                 boxSprite,
                                 ConsoleColor.Yellow,
                                 ConsoleColor.DarkGray));
            box.AddComponent(new Position(100, 8, 0f));
            box.AddComponent(new BoxConfirmation());
            gameScene.AddGameObject(box);
            boxes.Add(box);

            // Create Box2
            GameObject box2 = new GameObject("Box2");

            box2.AddComponent(new ConsoleSprite(
                                  boxSprite,
                                  ConsoleColor.Yellow,
                                  ConsoleColor.DarkGray));
            box2.AddComponent(new Position(150, 8, 0f));
            box2.AddComponent(new BoxConfirmation());
            gameScene.AddGameObject(box2);
            boxes.Add(box2);

            // Create dead text
            GameObject dead = new GameObject("Dead");

            dead.AddComponent(new Position(70, 10, 10));
            RenderableStringComponent deadString = new RenderableStringComponent(
                () => string.Empty,
                i => new Vector2(i, 0),
                ConsoleColor.Red,
                ConsoleColor.Gray);

            dead.AddComponent(deadString);
            gameScene.AddGameObject(dead);

            // Create player object
            // ─▄████▄▄
            // ▄▀█▀▐└─┐
            // █▄▐▌▄█▄┘
            // └▄▄▄▄▄┘
            char[,] playerSprite =
            {
                { '─', '▄', '█', '└' },
                { '▄', '▀', '▄', '▄' },
                { '█', '█', '▐', '▄' },
                { '█', '▀', '▐', '▄' },
                { '█', '▐', '▄', '▄' },
                { '█', '└', '█', '▄' },
                { '▄', '─', '▄', '┘' },
                { '▄', '┐', '┘', ' ' },
            };

            // Create player
            GameObject  player            = new GameObject("Player");
            KeyObserver playerKeyListener = new KeyObserver(
                new ConsoleKey[] {
                ConsoleKey.RightArrow,
                ConsoleKey.Spacebar,
                ConsoleKey.UpArrow,
                ConsoleKey.LeftArrow,
                ConsoleKey.Escape,
            });

            player.AddComponent(playerKeyListener);
            Position playerPos = new Position(1f, 19f, 0f);

            player.AddComponent(playerPos);
            player.AddComponent(new Player(
                                    occupied,
                                    score.GetComponent <Score>(),
                                    boxes,
                                    coins,
                                    dead,
                                    1));
            player.AddComponent(new ConsoleSprite(
                                    playerSprite, ConsoleColor.Red, ConsoleColor.Gray));
            gameScene.AddGameObject(player);

            // Create game object for showing time limit
            GameObject time = new GameObject("Time");

            time.AddComponent(new Position(190, 0, 10));
            time.AddComponent(new Time());
            RenderableStringComponent visualTime = new RenderableStringComponent(
                () => "Time: " + 200.ToString(),
                i => new Vector2(i, 0),
                ConsoleColor.DarkMagenta,
                ConsoleColor.White);

            time.AddComponent(visualTime);
            gameScene.AddGameObject(time);
        }