Ejemplo n.º 1
0
        public void TestRefresh()
        {
            string tempTile = Path.GetTempFileName();
            File.Copy("a.htm", tempTile, true);
            try
            {
                var config = new MockConfiguration(tempTile, new DateTime(2007, 1, 1)) {Factory = _factory };
                var ts = new TilesSet(config);

                Assert.That(RequiresRefresh(ts, "a"), Is.False);
                Assert.That(RequiresRefresh(ts, "b"), Is.False);

                File.SetLastWriteTime(tempTile, DateTime.Now.AddDays(-1));
                config.ConfigurationLastModified = config.ConfigurationLastModified.Value.AddDays(1);

                Assert.That(RequiresRefresh(ts, "a"), Is.True);
                Assert.That(RequiresRefresh(ts, "b"), Is.False);

                ts.Refresh();

                Assert.That(RequiresRefresh(ts, "a"), Is.False);
                Assert.That(RequiresRefresh(ts, "b"), Is.False);
            }
            finally
            {
                File.Delete(tempTile);
            }
        }
        public void GenerationOtherPageRunsWithOutErrors()
        {
            var    set    = new TilesSet(new TileXmlConfigurator(_lib, "tiles.config.xml", "Integration/"));
            string result = set["otherpage"].Render(new TagModel(book));

            OutputEquals(result, "Integration\\expected.result.otherpage.html");
        }
Ejemplo n.º 3
0
        public void TestRefresh()
        {
            string tempTile = Path.GetTempFileName();

            File.Copy("a.htm", tempTile, true);
            try
            {
                var config = new MockConfiguration(tempTile, new DateTime(2007, 1, 1))
                {
                    Factory = _factory
                };
                var ts = new TilesSet(config);

                Assert.That(RequiresRefresh(ts, "a"), Is.False);
                Assert.That(RequiresRefresh(ts, "b"), Is.False);

                File.SetLastWriteTime(tempTile, DateTime.Now.AddDays(-1));
                config.ConfigurationLastModified = config.ConfigurationLastModified.Value.AddDays(1);

                Assert.That(RequiresRefresh(ts, "a"), Is.True);
                Assert.That(RequiresRefresh(ts, "b"), Is.False);

                ts.Refresh();

                Assert.That(RequiresRefresh(ts, "a"), Is.False);
                Assert.That(RequiresRefresh(ts, "b"), Is.False);
            }
            finally
            {
                File.Delete(tempTile);
            }
        }
Ejemplo n.º 4
0
 private void InitTilesCache()
 {
     if (_cache == null)
     {
         _cache = new TilesSet(new TileXmlConfigurator(_lib, _factory));
     }
 }
Ejemplo n.º 5
0
 private static void Tile()
 {
     try
     {
         Console.WriteLine("Rendering tile");
         var set   = new TilesSet(new TileXmlConfigurator("tiles.xml"));
         var model = new TagModel(new Hashtable
         {
             {
                 "Key",
                 new List <Person>
                 {
                     new Person {
                         Name = "Ruth Kingsley", Age = 42
                     },
                     new Person {
                         Name = "Jacob van Dijk", Age = 23
                     },
                     new Person {
                         Name = "Stuward Langley", Age = 66
                     }
                 }
             }
         }).UpdateFactory(new FileLocatorFactory());
         Console.WriteLine(set["template"].Render(model));
     }
     catch (ExceptionWithContext EWC)
     {
         Console.WriteLine(EWC.Message);
         Console.WriteLine(EWC.Context);
     }
     Console.WriteLine("Hit enter");
     Console.ReadLine();
 }
Ejemplo n.º 6
0
        public void GenerateGameOverWindow2()
        {
            var BoardIter = new TilesCollection();

            for (int i = 0; i < 20; i++)
            {
                for (int y = 0; y < 20; y++)
                {
                    BoardIter[i, y] = TilesSet.GetTile(i, y);
                }
            }

            AbstractIterator iter = BoardIter.CreateIterator();

            object item = iter.First();

            while (item != null)
            {
                Rectangle ColorBlock = new Rectangle();
                ColorBlock.Name = "";

                ColorBlock.Fill = Brushes.Black;
                Tile tile = (Tile)item;
                Grid.SetColumn(ColorBlock, tile.x);
                Grid.SetRow(ColorBlock, tile.y);
                gridMain.Children.Add(ColorBlock);
                item = iter.Next();
            }
        }
Ejemplo n.º 7
0
 public void GenerationFirstDifferentRunsWithOutErrors()
 {
     var set = new TilesSet(new TileXmlConfigurator(_lib,"tiles.config.xml", "Integration/"));
     string result = set["firstdifferent"].Render(new TagModel(book));
     //            Console.WriteLine(result);
     OutputEquals(result, "Integration\\expected.result.firstdifferent.html");
 }
Ejemplo n.º 8
0
        public void TestRefreshConfigByFile()
        {
            string tempTile = Path.GetTempFileName();

            File.Copy("Configuration\\tiles.smallconfig.xml", tempTile, true);
            File.SetLastWriteTime(tempTile, DateTime.Now.AddDays(-1));
            try
            {
                var config = new TileXmlConfigurator(_lib, tempTile);
                var ts     = new TilesSet(config);

                Assert.That(ts.Contains("a"));
                Assert.That(ts.Contains("b"));
                Assert.That(!ts.Contains("c"));

                File.Copy("Configuration\\tiles.config.xml", tempTile, true);
                ts.Refresh();

                Assert.That(ts.Contains("a"));
                Assert.That(ts.Contains("b"));
                Assert.That(ts.Contains("c"));
            }
            finally
            {
                File.Delete(tempTile);
            }
        }
Ejemplo n.º 9
0
        private static bool RequiresRefresh(TilesSet ts, String name)
        {
            var templateTile = (TemplateTile)ts[name];
            var fileTemlpate = (FileTemplate)templateTile.Template;

            return(fileTemlpate.RequiresRefresh());
        }
Ejemplo n.º 10
0
        public void TilesWithAutoAttributesShouldLoadCorrectly()
        {
            var xmlConfig = new TileXmlConfigurator(_lib, "Configuration/tiles.with.auto.properties.xml");
            var set       = new TilesSet(xmlConfig);

            Assert.That(set.Tiles.Count, Is.EqualTo(3));
            Assert.That(set["a"], Is.Not.Null);
        }
Ejemplo n.º 11
0
        public void TilesWithExtendsReltionssAttributesShouldLoadCorrectly()
        {
            var xmlConfig = new TileXmlConfigurator(_lib, "Configuration/tiles.with.extends.xml");
            var set       = new TilesSet(xmlConfig);

            Assert.That(set.Tiles.Count, Is.EqualTo(4));
            Assert.That(set["a"], Is.Not.Null);
        }
Ejemplo n.º 12
0
        public void GenerationFirstDifferentRunsWithOutErrors()
        {
            var    set    = new TilesSet(new TileXmlConfigurator(_lib, "tiles.config.xml", "Integration/"));
            string result = set["firstdifferent"].Render(new TagModel(book));

            //            Console.WriteLine(result);
            OutputEquals(result, "Integration\\expected.result.firstdifferent.html");
        }
Ejemplo n.º 13
0
        public void Deserialize()
        {
            var set = new TilesSet(new TileXmlConfigurator(_lib, "Configuration/tiles.config.xml"));

            Assert.That(set.Tiles.Count, Is.EqualTo(3));
            Assert.That(GetPath(set["a"]), Is.EqualTo(Path.GetFullPath("a.htm")));
            Assert.That(GetPath(set["b"]), Is.EqualTo(Path.GetFullPath("b.htm")));
            Assert.That(GetPath(set["c"]), Is.EqualTo(Path.GetFullPath("c.htm")));
        }
Ejemplo n.º 14
0
 public Model(Dictionary.Dictionary GameDictionary, Language.Language Language)
 {
     this.GameLanguage = Language;
     TilesSet = new TilesSet(Language);
     this.Players = new List<Player.Player>();
     this.GameBoard = new Board.Board();
     this.GameDictionary = GameDictionary;
     this.PassCounter = 0;
 }
Ejemplo n.º 15
0
 public void LoadingOfConfigFile()
 {
     var set = new TilesSet(new TileXmlConfigurator(_lib, "tiles.config.xml", "Integration/"));
     Assert.That(set.Contains("base.html.book.page"));
     Assert.That(set.Contains("firstpage"));
     Assert.That(set.Contains("otherpage"));
     Assert.That(set.Contains("menu.bar"));
     Assert.That(set.Contains("contents.page"));
     Assert.That(set.Contains("firstdifferent"));
     Assert.That(set.Tiles.Count, Is.EqualTo(6));
 }
Ejemplo n.º 16
0
        public void TestCache()
        {
            var   ts = new TilesSet();
            ITile a  = new TemplateTile("a", _factory.Handle("a.htm", true), new List <TileAttribute>());
            ITile b  = new TemplateTile("b", _factory.Handle("b.htm", true), new List <TileAttribute>());

            ts.Map.AddTile(a);
            ts.Map.AddTile(b);

            Assert.That(ts["a"], Is.SameAs(a));
            Assert.That(ts["b"], Is.SameAs(b));
        }
Ejemplo n.º 17
0
        public void TestCache()
        {
            var ts = new TilesSet();
            ITile a = new TemplateTile("a", _factory.Handle("a.htm",true), new List<TileAttribute>());
            ITile b = new TemplateTile("b", _factory.Handle("b.htm",true), new List<TileAttribute>());

            ts.Map.AddTile(a);
            ts.Map.AddTile(b);

            Assert.That(ts["a"], Is.SameAs(a));
            Assert.That(ts["b"], Is.SameAs(b));
        }
Ejemplo n.º 18
0
        public void DeserializeFromAssemlbyWithTilesConfigurationFileShouldLoadTilesSet()
        {
            var configurator = new TileXmlConfigurator(
                _lib,
                Assembly.GetAssembly(typeof(TileXmlConfiguratorTest)));
            var set = new TilesSet(configurator);

            Assert.That(set.Tiles.Count, Is.EqualTo(3));
            Assert.That(GetPath(set["a"]), Is.EqualTo("embedded_a.htm"));
            Assert.That(GetPath(set["b"]), Is.EqualTo("embedded_b.htm"));
            Assert.That(GetPath(set["c"]), Is.EqualTo("embedded_c.htm"));
        }
Ejemplo n.º 19
0
        public void LoadingOfConfigFile()
        {
            var set = new TilesSet(new TileXmlConfigurator(_lib, "tiles.config.xml", "Integration/"));

            Assert.That(set.Contains("base.html.book.page"));
            Assert.That(set.Contains("firstpage"));
            Assert.That(set.Contains("otherpage"));
            Assert.That(set.Contains("menu.bar"));
            Assert.That(set.Contains("contents.page"));
            Assert.That(set.Contains("firstdifferent"));
            Assert.That(set.Tiles.Count, Is.EqualTo(6));
        }
Ejemplo n.º 20
0
        public override void SendDebuff()
        {
            _chatService.SendMessage("BlackSplash", 1, "0 0 0", MessageType.debuffBlackSplash, 4, 4);

            if (TilesSet.GetTile(4, 4).IsColored)
            {
                TilesSet.AddTile(4, 4, new Tile(true, true, TileType.DebuffBlackSplash, 4, 4));
            }
            else
            {
                TilesSet.AddTile(4, 4, new Tile(false, true, TileType.DebuffBlackSplash, 4, 4));
            }
        }
Ejemplo n.º 21
0
        public override void SendBuff()
        {
            _chatService.SendMessage("buff", 1, "100 100 200", MessageType.buffFreezeOthers, 11, 11);

            if (TilesSet.GetTile(11, 11).IsColored)
            {
                TilesSet.AddTile(11, 11, new Tile(true, true, TileType.BuffFreezeOthers, 11, 11));
            }
            else
            {
                TilesSet.AddTile(11, 11, new Tile(false, true, TileType.BuffFreezeOthers, 11, 11));
            }
        }
Ejemplo n.º 22
0
        public override void SendBuff()
        {
            _chatService.SendMessage("SplashBomb", 1, "255 51 51", MessageType.buffSplashBomb, 5, 5);

            if (TilesSet.GetTile(5, 5).IsColored)
            {
                TilesSet.AddTile(5, 5, new Tile(true, true, TileType.BuffColorSplash, 5, 5));
            }
            else
            {
                TilesSet.AddTile(5, 5, new Tile(false, true, TileType.BuffColorSplash, 5, 5));
            }
        }
Ejemplo n.º 23
0
        public override void SendDebuff()
        {
            _chatService.SendMessage("playerFreeze", 1, "100 149 237", MessageType.debuffFreezeYourself, 10, 10);

            if (TilesSet.GetTile(10, 10).IsColored)
            {
                TilesSet.AddTile(10, 10, new Tile(true, true, TileType.DebuffFreezeYourself, 10, 10));
            }
            else
            {
                TilesSet.AddTile(10, 10, new Tile(false, true, TileType.DebuffFreezeYourself, 10, 10));
            }
        }
Ejemplo n.º 24
0
        public void TestUnkownTile()
        {
            var ts = new TilesSet();

            try
            {
                var x = ts["?"];
                Assert.Fail("Expected exception on " + x);
            }
            catch (TemplateException Te)
            {
                Assert.That(Te.Message, Is.EqualTo(TemplateException.TemplateNotFound("?").Message));
            }
        }
Ejemplo n.º 25
0
 public void ClearBoard()
 {
     for (int x = 0; x < 20; x++)
     {
         for (int y = 0; y < 20; y++)
         {
             TilesSet.AddTile(x, y, new Tile(false, true, TileType.Neutral, x, y));
             Rectangle ColorBlock = new Rectangle();
             ColorBlock.Fill = Brushes.White;
             Grid.SetColumn(ColorBlock, x);
             Grid.SetRow(ColorBlock, y);
             gridMain.Children.Add(ColorBlock);
         }
     }
 }
Ejemplo n.º 26
0
        static TemplateField()
        {
            TagLib = new TagLib();

            TilesConfigurationSection config = TilesConfigurationSection.Get();
            var prefix = TemplateFieldPrefixHelper.BuildPrefix(HostingEnvironment.ApplicationPhysicalPath, config.FilePrefix);

            RefreshJob.REFRESH_INTERVAL = config.RefreshIntervalSeconds;
            _configuration = new TileXmlConfigurator(
                TagLib,
                config.ConfigFilePath,
                prefix
                );
            TILES = new TilesSet(_configuration);
        }
Ejemplo n.º 27
0
        public override void SendBonus()
        {
            Random randNum = new Random();
            int    Randx   = randNum.Next(0, 20);
            int    Randy   = randNum.Next(0, 20);

            _chatService.SendMessage("buff", 1, ColorOptions[YellowColorShades.Light].ReceiveColorCode(), MessageType.bonusJoke, Randx, Randy);

            if (TilesSet.GetTile(Randx, Randy).IsColored)
            {
                TilesSet.AddTile(Randx, Randy, new Tile(true, true, TileType.BonusJoke, Randx, Randy));
            }
            else
            {
                TilesSet.AddTile(Randx, Randy, new Tile(false, true, TileType.BonusJoke, Randx, Randy));
            }
        }
Ejemplo n.º 28
0
 public void AddTiles()
 {
     for (int x = 0; x < 20; x++)
     {
         for (int y = 0; y < 20; y++)
         {
             TilesSet.AddTile(x, y, new Tile(false, true, TileType.Neutral, x, y));
             MessageBox.Show("Hello I am created");
             Rectangle ColorBlock = new Rectangle();
             ColorBlock.Name = "Tile" + x + y;
             ColorBlock.Fill = Brushes.Aqua;
             Grid.SetColumn(ColorBlock, x);
             Grid.SetRow(ColorBlock, y);
             gridMain.Children.Add(ColorBlock);
         }
     }
 }
Ejemplo n.º 29
0
        public void TestRefreshConfig()
        {
            var config = new MockConfiguration(new DateTime(2007, 1, 1))
            {
                Factory = _factory
            };
            var ts = new TilesSet(config);

            Assert.That(ts.Contains("a"));
            Assert.That(ts.Contains("b"));
            Assert.That(!ts.Contains("c"));

            config.RefreshAndChange(new DateTime(2008, 1, 1));
            ts.Refresh();

            Assert.That(ts.Contains("a"));
            Assert.That(ts.Contains("b"));
            Assert.That(ts.Contains("c"));
        }
Ejemplo n.º 30
0
        public void TestSetTiles()
        {
            var           set  = new TilesSet();
            IList <ITile> list = new List <ITile>();
            ITile         a    = new TemplateTile("a", _factory.Handle("a.htm", true), new List <TileAttribute>());
            ITile         b    = new TemplateTile("b", _factory.Handle("b.htm", true), new List <TileAttribute>());
            ITile         c    = new TemplateTile("c", _factory.Handle("c.htm", true), new List <TileAttribute>());

            list.Add(b);
            list.Add(c);

            set.Map.AddTile(a);
            Assert.IsTrue(set.Contains("a"));
            Assert.IsFalse(set.Contains("b"));
            Assert.IsFalse(set.Contains("c"));
            set.SetTiles(list);
            Assert.IsFalse(set.Contains("a"));
            Assert.IsTrue(set.Contains("b"));
            Assert.IsTrue(set.Contains("c"));
        }
Ejemplo n.º 31
0
        private void ChatService_CoordinatesMessageReceived(BoardCoordinates coordinates)
        {
            string mess = coordinates.message;

            if (coordinates.messageType == MessageType.buffFreezeOthers)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
            }
            else if (coordinates.messageType == MessageType.debuffFreezeYourself)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
            }
            else if (coordinates.messageType == MessageType.buffSplashBomb)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
            }
            else if (coordinates.messageType == MessageType.debuffBlackSplash)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
            }
            else if (coordinates.messageType == MessageType.stepedOnColorSplash)
            {
                string[] words = coordinates.color.Split(' ');
                SetTile(coordinates.x + 1, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 1, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y + 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y - 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x + 2, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 2, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y + 2, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y - 2, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x + 1, coordinates.y + 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 1, coordinates.y + 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x + 1, coordinates.y - 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 1, coordinates.y - 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
            }
            else if (coordinates.messageType == MessageType.stepedOnBlackSplash)
            {
                string[] words = coordinates.color.Split(' ');
                SetTile(coordinates.x + 1, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 1, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y + 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y - 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x + 2, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 2, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y + 2, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x, coordinates.y - 2, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x + 1, coordinates.y + 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 1, coordinates.y + 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x + 1, coordinates.y - 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                SetTile(coordinates.x - 1, coordinates.y - 1, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
            }
            else if (coordinates.messageType == MessageType.enemy || coordinates.messageType == MessageType.dazePlayerEnemy || coordinates.messageType == MessageType.stealPointEnemy || coordinates.messageType == MessageType.teleportPlayerEnemy)
            {
                if (coordinates.messageType == MessageType.enemy)
                {
                    string[] words = coordinates.color.Split(' ');

                    SetTile(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(true, true, TileType.Enemy, coordinates.x, coordinates.y));
                }
                else
                {
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(true, true, TileType.EnemyWithAbilities, coordinates.x, coordinates.y));
                }
            }
            else if (coordinates.messageType == MessageType.bonusJackPot)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));

                if (TilesSet.GetTile(coordinates.x, coordinates.y).IsColored)
                {
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(true, true, TileType.BonusJackPot, coordinates.x, coordinates.y));
                }
                else
                {
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(false, true, TileType.BonusJackPot, coordinates.x, coordinates.y));
                }
            }
            else if (coordinates.messageType == MessageType.bonusNormal)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));

                if (TilesSet.GetTile(coordinates.x, coordinates.y).IsColored)
                {
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(true, true, TileType.BonusNormal, coordinates.x, coordinates.y));
                }
                else
                {
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(false, true, TileType.BonusNormal, coordinates.x, coordinates.y));
                }
            }
            else if (coordinates.messageType == MessageType.bonusJoke)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));

                if (TilesSet.GetTile(coordinates.x, coordinates.y).IsColored)
                {
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(true, true, TileType.BonusJoke, coordinates.x, coordinates.y));
                }
                else
                {
                    TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(false, true, TileType.BonusJoke, coordinates.x, coordinates.y));
                }
            }
            else if (coordinates.messageType == MessageType.gameOver)
            {
                GenerateGameOverWindow2();
            }
            else if (coordinates.messageType == MessageType.magician)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));

                TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(false, true, TileType.Magician, coordinates.x, coordinates.y));
            }
            else if (coordinates.messageType == MessageType.masterThief)
            {
                string[] words = coordinates.color.Split(' ');

                SetEllipse(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));

                TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(false, true, TileType.MasterThief, coordinates.x, coordinates.y));
            }
            else if (coordinates.messageType == MessageType.gamePause || coordinates.messageType == MessageType.gamePauseUndo)
            {
                ;
            }
            else if (coordinates.messageType == MessageType.reset)
            {
                ClearBoard();
                string[] words = coordinates.color.Split(' ');
                //SetTile(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
            }
            else if (coordinates.messageType == MessageType.darkHole)
            {
                string[] words = coordinates.color.Split(' ');
                SetTile(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(true, true, TileType.DarkHole, coordinates.x, coordinates.y));
            }
            else if (coordinates.messageType == MessageType.lightHole)
            {
                string[] words = coordinates.color.Split(' ');
                SetTile(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                TilesSet.AddTile(coordinates.x, coordinates.y, new Tile(true, true, TileType.LightHole, coordinates.x, coordinates.y));
            }
            else
            {
                if (TilesSet.GetTile(coordinates.x, coordinates.y).TileType == TileType.DarkHole || TilesSet.GetTile(coordinates.x, coordinates.y).TileType == TileType.LightHole)
                {
                }
                else
                {
                    string[] words = coordinates.color.Split(' ');

                    SetTile(coordinates.x, coordinates.y, new SolidColorBrush(Color.FromRgb(Byte.Parse(words[0]), Byte.Parse(words[1]), Byte.Parse(words[2]))));
                }
            }
        }
Ejemplo n.º 32
0
        private void ChatService_CoordinatesMessageReceived(BoardCoordinates coordinates)
        {
            if (!gameHasEnded)
            {
                if (coordinates.messageType == MessageType.playerMovement)
                {
                    if (StepsCount == 0)
                    {
                        board.State = new Darken();
                    }
                    else if (StepsCount == SpawnRates.StepsCount / 2)
                    {
                        board.State = new Lighten();
                    }

                    board.Request();
                    if (StepsCount >= SpawnRates.StepsCount)
                    {
                        StepsCount = -1;
                    }

                    //currByte -= 1;
                    //BackgroundColor = Color.FromRgb(255, currByte, currByte).ToString();
                    //OnPropertyChanged(nameof(BackgroundColor));

                    if (coordinates.id == UniqueID)
                    {
                        MainPlayer.Score++;
                    }

                    if (BonusCount > SpawnRates.BonusCount)
                    {
                        //var a = new BonusFactory();
                        Random randNum     = new Random();
                        int    BonusNumber = randNum.Next(1, 4);
                        //a.CreateBonus(BonusNumber, _chatService).SendBonus();
                        facade.CreateBonus(BonusNumber);
                        BonusCount = 0;
                        //MainPlayer.SetMemento(memento.Memento);
                    }

                    if (FreezeYourselfStepCount >= SpawnRates.FreezeYourselfStepCount)
                    {
                        facade.CreateDeBuff(TileType.DebuffFreezeYourself);
                        FreezeYourselfStepCount = 0;
                    }

                    if (FreezeOthersStepCount >= SpawnRates.FreezeOthersStepCount)
                    {
                        facade.CreateBuff(TileType.BuffFreezeOthers);
                        FreezeOthersStepCount = 0;
                    }

                    if (BlackSplashCount >= SpawnRates.BlackSplashCount)
                    {
                        facade.CreateDeBuff(TileType.DebuffBlackSplash);
                        BlackSplashCount = 0;
                    }
                    if (ColorSplashCount >= SpawnRates.ColorSplashCount)
                    {
                        facade.CreateBuff(TileType.BuffColorSplash);
                        ColorSplashCount = 0;
                    }

                    if (EnemyCount >= SpawnRates.EnemyCount)
                    {
                        MainEnemy.ChangePossition();
                        dazeEnemy.Operation(MainEnemy.PosX, MainEnemy.PosY, _connectionProxy);
                        EnemyCount = 0;
                    }

                    if (MagicianCount > SpawnRates.MagicianCount)
                    {
                        Thief newThief = new Magician();
                        newThief.Run(_connectionProxy);
                        MagicianCount = 0;
                    }

                    if (MasterThiefCount > SpawnRates.MasterThiefCount)
                    {
                        Thief newThief2 = new MasterThief();
                        newThief2.Run(_connectionProxy);
                        MasterThiefCount = 0;
                    }

                    StepsCount++;
                    BonusCount++;
                    FreezeYourselfStepCount++;
                    FreezeOthersStepCount++;
                    EnemyCount++;
                    BlackSplashCount++;
                    ColorSplashCount++;
                    MasterThiefCount++;
                    MagicianCount++;

                    //jei turi str count bet nedaro

                    if (coordinates.id == UniqueID)
                    {
                        _message = coordinates.message;
                        _x       = coordinates.x;
                        _y       = coordinates.y;


                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BonusJackPot)
                        {
                            root.AddPoint(ComponentType.JackPot);
                            MainPlayer.PlayerCalculateScore(Score.AddPoints(new BonusFactory().CreateBonus(1, _connectionProxy)));
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString() + MainPlayer.Score);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BonusNormal)
                        {
                            root.AddPoint(ComponentType.Normal);
                            MainPlayer.PlayerCalculateScore(Score.AddPoints(new BonusFactory().CreateBonus(3, _connectionProxy)));
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString() + MainPlayer.Score);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BonusJoke)
                        {
                            root.AddPoint(ComponentType.Joke);
                            MainPlayer.PlayerCalculateScore(Score.ReducePoints(new BonusFactory().CreateBonus(2, _connectionProxy)));
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString() + MainPlayer.Score);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.DebuffFreezeYourself)
                        {
                            IceDamageDealer.ProcessRequest(DamageDealerType.IceDamage, MainPlayer);
                            root.AddPoint(ComponentType.FreezeYourself);
                            MainPlayer.RequestStrategy(StrategyType.Frozen);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BuffFreezeOthers)
                        {
                            root.AddPoint(ComponentType.FreezeOthers);
                            MainPlayer.RequestStrategy(StrategyType.Frozen);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BuffColorSplash)
                        {
                            root.AddPoint(ComponentType.ColorSplash);
                            MainPlayer.SendSteppedOnColorSplash(_connectionProxy, _x, _y);
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString());
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.DebuffBlackSplash)
                        {
                            root.AddPoint(ComponentType.BlackSplash);
                            MainPlayer.SendSteppedOnBlackSplash(_connectionProxy, _x, _y);
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString());
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.DarkHole)
                        {
                            MainPlayer.Score -= 3;
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.LightHole)
                        {
                            MainPlayer.Score -= 2;
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.Magician)
                        {
                            Random randNum = new Random();
                            int    number  = randNum.Next(1, 1000);
                            string roman   = ToRoman(number);

                            ContextRoman context = new ContextRoman(roman);
                            foreach (ExpressionRoman exp in tree)
                            {
                                exp.Interpret(context);
                            }

                            string message = "Does " + roman + " = " + context.Output + " ?";
                            string title   = "Answer the question";

                            MessageBoxResult result = MessageBox.Show(message, title, MessageBoxButton.YesNo);
                            if (result == MessageBoxResult.No)
                            {
                                IceDamageDealer.ProcessRequest(DamageDealerType.MagitianDamage, MainPlayer);
                            }
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.MasterThief)
                        {
                            IceDamageDealer.ProcessRequest(DamageDealerType.ThiefDamage, MainPlayer);
                        }

                        if (TilesSet.GetTile(_x, _y).TileType == TileType.Enemy)
                        {
                            IceDamageDealer.ProcessRequest(DamageDealerType.EnemyDamage, MainPlayer);
                            MainPlayer.RequestStrategy(StrategyType.Confused);
                        }

                        TilesSet.AddTile(_x, _y, new Tile(true, true, TileType.Neutral, _x, _y));

                        OnPropertyChanged(nameof(Message));
                        OnPropertyChanged(nameof(x));
                        MainPlayer.PosX = x;
                        MainPlayer.PosY = y;
                        OnPropertyChanged(nameof(y));
                        OnPropertyChanged(nameof(CurrentPlayerScore));
                    }
                }

                if (coordinates.messageType == MessageType.gamePause || coordinates.messageType == MessageType.gamePauseUndo)
                {
                    SetGamePause();
                }

                if (MainPlayer.Score >= 100)
                {
                    MessageBox.Show(root.Display(1));
                    MainPlayer.SendGameOverMessage(_connectionProxy, UniqueID);
                    MainPlayer.Score = 0;
                }

                if (coordinates.messageType == MessageType.gameOver)
                {
                    gameHasEnded = true;
                }

                if (coordinates.messageType == MessageType.reset)
                {
                    MainPlayer.SetMemento(memento.Memento);
                    x = MainPlayer.PosX;
                    y = MainPlayer.PosY;
                    OnPropertyChanged(nameof(x));
                    OnPropertyChanged(nameof(y));
                    OnPropertyChanged(nameof(CurrentPlayerScore));
                }
            }
        }
Ejemplo n.º 33
0
 public void GenerationOtherPageRunsWithOutErrors()
 {
     var set = new TilesSet(new TileXmlConfigurator(_lib, "tiles.config.xml", "Integration/"));
     string result = set["otherpage"].Render(new TagModel(book));
     OutputEquals(result, "Integration\\expected.result.otherpage.html");
 }
Ejemplo n.º 34
0
 private static bool RequiresRefresh(TilesSet ts, String name)
 {
     var templateTile = (TemplateTile)ts[name];
     var fileTemlpate = (FileTemplate)templateTile.Template;
     return fileTemlpate.RequiresRefresh();
 }
Ejemplo n.º 35
0
 public void TestUnkownTile()
 {
     var ts = new TilesSet();
     try
     {
         var x = ts["?"];
         Assert.Fail("Expected exception on " + x);
     }
     catch (TemplateException Te)
     {
         Assert.That(Te.Message, Is.EqualTo(TemplateException.TemplateNotFound("?").Message));
     }
 }
Ejemplo n.º 36
0
        public void TestSetTiles()
        {
            var set = new TilesSet();
            IList<ITile> list = new List<ITile>();
            ITile a = new TemplateTile("a", _factory.Handle("a.htm",true), new List<TileAttribute>());
            ITile b = new TemplateTile("b", _factory.Handle("b.htm",true), new List<TileAttribute>());
            ITile c = new TemplateTile("c", _factory.Handle("c.htm",true), new List<TileAttribute>());
            list.Add(b);
            list.Add(c);

            set.Map.AddTile(a);
            Assert.IsTrue(set.Contains("a"));
            Assert.IsFalse(set.Contains("b"));
            Assert.IsFalse(set.Contains("c"));
            set.SetTiles(list);
            Assert.IsFalse(set.Contains("a"));
            Assert.IsTrue(set.Contains("b"));
            Assert.IsTrue(set.Contains("c"));
        }
Ejemplo n.º 37
0
        public void TestRefreshConfigByFile()
        {
            string tempTile = Path.GetTempFileName();
            File.Copy("Configuration\\tiles.smallconfig.xml", tempTile, true);
            File.SetLastWriteTime(tempTile, DateTime.Now.AddDays(-1));
            try
            {

                var config = new TileXmlConfigurator(_lib, tempTile);
                var ts = new TilesSet(config);

                Assert.That(ts.Contains("a"));
                Assert.That(ts.Contains("b"));
                Assert.That(!ts.Contains("c"));

                File.Copy("Configuration\\tiles.config.xml", tempTile, true);
                ts.Refresh();

                Assert.That(ts.Contains("a"));
                Assert.That(ts.Contains("b"));
                Assert.That(ts.Contains("c"));
            }
            finally
            {
                File.Delete(tempTile);
            }
        }
Ejemplo n.º 38
0
        public void TestRefreshConfig()
        {
            var config = new MockConfiguration(new DateTime(2007, 1, 1)) { Factory = _factory };
            var ts = new TilesSet(config);

            Assert.That(ts.Contains("a"));
            Assert.That(ts.Contains("b"));
            Assert.That(!ts.Contains("c"));

            config.RefreshAndChange(new DateTime(2008, 1, 1));
            ts.Refresh();

            Assert.That(ts.Contains("a"));
            Assert.That(ts.Contains("b"));
            Assert.That(ts.Contains("c"));
        }
Ejemplo n.º 39
0
 public void ResetGame()
 {
     GameBoard = new Board.Board();
     Players.Clear();
     CurrentPlayer = null;
     TilesSet = new TilesSet(GameLanguage);
     PassCounter = 0;
     GameBoard.SetEmpty(true);
 }
Ejemplo n.º 40
0
        public BoardCoordinatesViewModel(ConnectionProxy connectionProxy, Player mainPlayer, Enemy mainEnemy)
        {
            _connectionProxy = connectionProxy;
            MainPlayer       = mainPlayer;

            memento         = new MementoCareTaker();
            memento.Memento = MainPlayer.CreateMemento();

            MainEnemy = mainEnemy;
            Random randNum = new Random();

            UniqueID  = randNum.Next(100, 255);
            UniqueID2 = randNum.Next(100, 255);
            UniqueID3 = randNum.Next(100, 255);

            CurrentPlayer.color = UniqueID.ToString() + " " + UniqueID2.ToString() + " " + UniqueID3.ToString();

            enemySteal    = new StealPointsAbility();
            teleportEnemy = new TeleportAbility();
            dazeEnemy     = new DazePlayerAbility();

            enemySteal.SetEnemy(MainEnemy);
            teleportEnemy.SetEnemy(enemySteal);
            dazeEnemy.SetEnemy(teleportEnemy);


            for (int x = 0; x < 20; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    TilesSet.AddTile(x, y, new Tile(false, true, TileType.Neutral, x, y));
                }
            }

            //playerColor = UniqueID.ToString() + " " + UniqueID2.ToString() + " " + UniqueID3.ToString();
            //playerColor.Color = Color.FromArgb(255, 255, 255, 0);

            //SendCoordinatesCommand = new SendCoordinatesChatMessageCommand(this, chatService);
            MoveDownChatMessageCommand  = new MoveDownChatMessageCommand(this, _connectionProxy, MainPlayer);
            MoveLeftChatMessageCommand  = new MoveLeftChatMessageCommand(this, _connectionProxy, MainPlayer);
            MoveRightChatMessageCommand = new MoveRightChatMessageCommand(this, _connectionProxy, MainPlayer);
            MoveUpChatMessageCommand    = new MoveUpChatMessageCommand(this, _connectionProxy, MainPlayer);
            Pause       = new Pause(this, _connectionProxy);
            RestartGame = new RestartGame(this, _connectionProxy);

            _message = "Waiting for response";

            x           = MainPlayer.PosX;
            y           = MainPlayer.PosY;
            playerColor = MainPlayer.Color;

            /* CHAIN OF RESPONSIBILITY */

            EnemyDamageDealer    = new EnemyDamage();
            MagicianDamageDealer = new MagicianDamage();
            ThiefDamageDealer    = new ThiefDamage();
            IceDamageDealer      = new IceDamage();

            IceDamageDealer.SetSuccessor(ThiefDamageDealer);
            ThiefDamageDealer.SetSuccessor(MagicianDamageDealer);
            MagicianDamageDealer.SetSuccessor(EnemyDamageDealer);

            /* CHAIN OF RESPONSIBILITY */

            CurrentPlayer.x = x;
            CurrentPlayer.y = y;

            _connectionProxy.AddMessageReceiver(ChatService_CoordinatesMessageReceived);

            //chatService.CoordinatesReceived += ChatService_CoordinatesMessageReceived;
            facade = new Facade(_connectionProxy);

            root = new Effect(ComponentType.Effect);
            //Buffai

            Effect buff         = new Effect(ComponentType.Buff);
            Effect negativeBuff = new Effect(ComponentType.Negative); //negative
            Effect positiveBuff = new Effect(ComponentType.Positive); //positive

            positiveBuff.Add(new CountLeaf(ComponentType.ColorSplash));
            positiveBuff.Add(new CountLeaf(ComponentType.FreezeOthers));

            negativeBuff.Add(new CountLeaf(ComponentType.BlackSplash));
            negativeBuff.Add(new CountLeaf(ComponentType.FreezeYourself));

            buff.Add(negativeBuff);
            buff.Add(positiveBuff);

            // /Buffai
            // Bonusai

            Effect bonus = new Effect(ComponentType.Bonus);

            bonus.Add(new CountLeaf(ComponentType.JackPot));
            bonus.Add(new CountLeaf(ComponentType.Normal));
            bonus.Add(new CountLeaf(ComponentType.Joke));

            //Bonusai

            root.Add(buff);
            root.Add(bonus);

            /* INTERPRETER DESIGN PATTERN IMPLEMENTATION */
            tree = new List <ExpressionRoman>();
            tree.Add(new ThousandExpression());
            tree.Add(new HundredExpression());
            tree.Add(new TenExpression());
            tree.Add(new OneExpression());
            /* INTERPRETER DESIGN PATTERN IMPLEMENTATION */


            /* VISITOR DESIGN PATTERN IMPLEMENTATION */
            game = new GameStructure();
            game.Attach(new Hard());

            BonusSpawnRate  bonusSpawn  = new BonusSpawnRate();
            BuffSpawnRate   buffSpawn   = new BuffSpawnRate();
            DebuffSpawnRate debuffSpawn = new DebuffSpawnRate();

            game.Accept(bonusSpawn);
            game.Accept(buffSpawn);
            game.Accept(debuffSpawn);
            /* VISITOR DESIGN PATTERN IMPLEMENTATION */

            /* Flyweight design pattern */


            /* Flyweight design pattern */
        }