Example #1
0
 public PrayerReserved(long intentionId, Mystery mystery, long userId, long prayerId)
 {
     IntentionId     = intentionId;
     MysteryReserved = mystery;
     UserId          = userId;
     PrayerId        = prayerId;
 }
        public void LoadTest()
        {
            string tmpFilename = Path.GetTempFileName();

            MysteryCreator mysteryCreator1 = new MysteryCreator();

            mysteryCreator1.NumberOfColumns = 7;
            mysteryCreator1.NumberOfRows    = 7;
            mysteryCreator1.NumberOfShips   = 12;
            Mystery mystery1 = mysteryCreator1.Create();

            SaveLoadService.Save(mystery1, tmpFilename);

            MysteryCreator mysteryCreator2 = new MysteryCreator();

            mysteryCreator2.NumberOfColumns = 2;
            mysteryCreator2.NumberOfRows    = 2;
            mysteryCreator2.NumberOfShips   = 1;
            Mystery mystery2 = mysteryCreator2.Create();

            mystery2 = SaveLoadService.Load(mystery2, tmpFilename);
            Assert.IsTrue(mystery2.FieldList.Count == mystery1.FieldList.Count && mystery1.ShipList.Count == mystery2.ShipList.Count);
            if (File.Exists(tmpFilename))
            {
                File.Delete(tmpFilename);
            }
        }
Example #3
0
        private Prayer _getReservedPrayer(long userId, Func <Rosary, Mystery> getNextMystery)
        {
            Prayer prayer;
            var    hasFreeMystery    = new RosaryHasAviablePrayers();
            var    hasExpiredMystery = new RosaryHasExpiredMysteries();
            var    rosarySpec        = hasFreeMystery.Or(hasExpiredMystery);
            var    rosary            = Rosaries.First(rosarySpec.IsSatisfiedBy);
            var    mystery           = getNextMystery(rosary);

            if (Mystery.Empty == mystery)
            {
                Rosary nextRosary = new Rosary();
                this.Rosaries.Add(nextRosary);
                Mystery nextMystery = getNextMystery(nextRosary);
                prayer = new Prayer(nextRosary, nextMystery);
                RaiseDomainEvent(new PrayerReserved(Id, nextMystery, userId, prayer.Id));
            }
            else
            {
                prayer = new Prayer(rosary, mystery);
                RaiseDomainEvent(new PrayerReserved(Id, mystery, userId, prayer.Id));
            }

            return(prayer);
        }
Example #4
0
        static void Main(string[] args)
        {
            Mystery mystery1 = new Mystery("KC02122006", 13, "Female", "Drapery");
            Mystery mystery2 = new Mystery("NT21102021", 48, "Male", "Electrical");
            Mystery mystery3 = new Mystery("KZ18072013", 29, "Female", "Tourism");
            Regular regular  = new Regular("XM19111996", 23, "Male", "Marx");

            Shopper shopper;

            shopper = mystery1;
            Console.WriteLine(shopper.GetDisplayShopperInfo("\n"));
            Console.WriteLine();

            shopper = mystery2;
            Console.WriteLine(shopper.GetDisplayShopperInfo("\n"));
            Console.WriteLine();

            shopper = mystery3;
            Console.WriteLine(shopper.GetDisplayShopperInfo("\n"));

            Console.WriteLine();
            //shopper = regular;
            Console.WriteLine(regular.GetDisplayShopperInfo("\n"));

            Console.ReadKey();
        }
        public async Task<Mystery> UpdateMystery(Mystery mystery)
        {
            var result = await mysteryContext.Mysteries
                .FirstOrDefaultAsync(m => m.Id == mystery.Id);

            if (result != null)
            {
                result.Name = mystery.Name;
                result.Attribute1 = mystery.Attribute1;
                result.Attribute2 = mystery.Attribute2;
                result.Jutsu1 = mystery.Jutsu1;
                result.Jutsu2 = mystery.Jutsu2;
                result.Causing = mystery.Causing;
                result.Effects = mystery.Effects;
                result.Description = mystery.Description;
                result.ImagePath = mystery.ImagePath;
                result.Prompt = mystery.Prompt;
                result.BfCooldown = mystery.BfCooldown;
                result.Cooldown = mystery.Cooldown;
                result.Chakra = mystery.Chakra;

                await mysteryContext.SaveChangesAsync();

                return result;
            }

            return null;
        }
Example #6
0
        public void NextMystery_Returns_expired_mystery()
        {
            int numberOfCalls = 0;

            Func <DateTime> mockedTime = () => {
                if (++numberOfCalls > 1)
                {
                    return(DateTime.UtcNow.AddMinutes(15)); // current time
                }
                else
                {
                    return(DateTime.UtcNow); // lock time
                }
            };

            Rosary rosary = new Rosary();

            Mystery mystery01 = rosary.NextMystery();           // Joyful1
            Mystery mystery02 = rosary.NextMystery();           // Joyful2
            Mystery mystery1  = rosary.NextMystery(mockedTime); // Joyful3 expire...
            Mystery mystery2  = rosary.NextMystery(mockedTime); // Joyful3
            Mystery mystery3  = rosary.NextMystery(mockedTime); // Joyful4

            mystery2.Should().Be(mystery1);
            mystery3.Should().Be(Mystery.Joyful4);
        }
        public Mystery CreateMystery(Mystery val)
        {
            int id = _db.ExecuteScalar <int>(@"
      INSERT INTO mysteries(name, description, userId)
      VALUES(@Name, @Description, @UserId);
      SELECT LAST_INSERT_ID();
      ", val);

            val.Id = id;
            return(val);
        }
Example #8
0
    public void UpdateMysteryInfo()
    {
        mysteriesSolvedText.text = App.Model.mysteryModel.mysteriesSolved + " / " + App.Model.ancientOneModel.ancientOne.numMysteries;

        Mystery m = App.Model.mysteryModel.activeMystery;

        mysteryTitle.text       = m.mysteryName;
        mysteryDescription.text = m.mysteryDescription;
        mysteryProgress.text    = App.Model.mysteryModel.mysteryProgress + " / " + m.requirement;
        mysteryText.text        = m.mysteryText;
    }
        public async Task<Mystery> AddMystery(Mystery mystery)
        {
            if (mystery is null)
            {
                throw new ArgumentNullException(nameof(mystery));
            }

            var result = await mysteryContext.Mysteries.AddAsync(mystery);
            await mysteryContext.SaveChangesAsync();
            return result.Entity;
        }
        /// <summary>
        /// Erstellt ein PDF mit der Lösung vom Rätsel
        /// </summary>
        /// <param name="mystery">Rätsel von welchem die Lösung exportiert werden soll</param>
        /// <param name="filePath">Der Pfad von der PDF Datei</param>
        public static void ExportSolution(Mystery mystery, string filePath)
        {
            Document  doc   = new Document();
            PdfPTable table = CreateTable(mystery, true);

            PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));

            doc.Open();
            doc.Add(table);
            doc.Close();
        }
Example #11
0
    public void DrawNewMystery()
    {
        int index = Random.Range(0, activeMysteryDeck.Count);

        activeMystery = activeMysteryDeck[index];
        activeMystery.StartMystery();
        // activeMysteryDeck.RemoveAt(index);
        mysteryProgress = 0;
        App.View.mysteryView.UpdateMysteryInfo();
        App.View.mysteryView.NewMystery();
    }
        /// <summary>
        /// Erstellt ein PDF und schreibt das Rästel in das PDF
        /// </summary>
        /// <param name="mystery">Das Räsel, welches exportiert werden soll</param>
        /// <param name="filePath">Der Pfad von der PDF Datei</param>
        public static void Export(Mystery mystery, string filePath)
        {
            Document  doc   = new Document();
            PdfPTable table = CreateTable(mystery, false);

            PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));

            doc.Open();
            doc.Add(table);
            doc.Add(new Phrase(CreateShipInformations(mystery)));
            doc.Close();
        }
        public PlayingFieldViewModel(Mystery mystery)
        {
            Mystery = mystery;

            HelpCommand               = new HelpCommand(GetHelp);
            CorrectCommand            = new CorrectCommand(CorrectMystery);
            BackCommand               = new BackCommand(Back);
            SaveVirtualMysteryCommand = new SaveVirtualMysteryCommand(SaveVirtualMystery);
            LoadVirtualMysteryCommand = new LoadVirtualMysteryCommand(LoadVirtualMystery);
            SafePDFCommand            = new SafePDFCommand(SavePDF);
            SafePDFSolutionCommand    = new SafePDFSolutionCommand(SavePDFSolution);
        }
        public void CreateTest()
        {
            MysteryCreator mysteryCreator = new MysteryCreator();

            mysteryCreator.NumberOfColumns = 7;
            mysteryCreator.NumberOfRows    = 7;
            mysteryCreator.NumberOfShips   = 12;
            Mystery mystery = mysteryCreator.Create();

            Assert.IsTrue(mystery != null);
            Assert.IsTrue(mystery.FieldList.Count == 49 && mystery.FieldList.Where(f => f.IsShipField == true).ToList().Count == 12);
        }
Example #15
0
    public void NewMystery()
    {
        newMysteryMenu.SetActive(true);
        App.Controller.openMenuController.OpenMenu(newMysteryMenu);
        newMysterySolvedText.text = "";
        newMysteryScreen.SetActive(true);

        Mystery m = App.Model.mysteryModel.activeMystery;

        newMysteryTitle.text      = m.mysteryName;
        newMysteryFlavorText.text = m.mysteryDescription;
        newMysteryText.text       = m.mysteryText;
    }
        /// <summary>
        /// Erstellt die Informationen, von welchem Schiffstyp, wieviele Schiffe existieren
        /// </summary>
        /// <param name="mystery">Das Mystery, welches für die Generation verwendet werden soll</param>
        /// <returns></returns>
        private static string CreateShipInformations(Mystery mystery)
        {
            string shipInformations = "Schiffe: \r\n\r\n";

            foreach (var oneShip in mystery.ShipList)
            {
                for (int i = 0; i < oneShip.Size; i++)
                {
                    shipInformations += "X";
                }
                shipInformations += "\r\n";
            }
            return(shipInformations);
        }
        public Mystery ChangeMystery(Mystery val, int id)
        {
            try
            {
                return(_db.QueryFirstOrDefault <Mystery>($@"
UPDATE mysteries SET
  Name = @Name,
  Description = @Description
  WHERE Id = @Id;
SELECT * FROM mysteries WHERE id = @Id;", val));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }
Example #18
0
        public void NextMystery_Returns_Proper_sequence()
        {
            Rosary rosary = new Rosary();

            Mystery mystery1  = rosary.NextMystery();
            Mystery mystery2  = rosary.NextMystery();
            Mystery mystery3  = rosary.NextMystery();
            Mystery mystery4  = rosary.NextMystery();
            Mystery mystery5  = rosary.NextMystery();
            Mystery mystery6  = rosary.NextMystery();
            Mystery mystery7  = rosary.NextMystery();
            Mystery mystery8  = rosary.NextMystery();
            Mystery mystery9  = rosary.NextMystery();
            Mystery mystery10 = rosary.NextMystery();
            Mystery mystery11 = rosary.NextMystery();

            rosary.NextMystery();
            rosary.NextMystery();
            rosary.NextMystery();
            rosary.NextMystery();

            Mystery mystery16 = rosary.NextMystery();

            rosary.NextMystery();
            rosary.NextMystery();
            rosary.NextMystery();
            Mystery mystery20 = rosary.NextMystery();


            mystery1.Should().Be(Mystery.Joyful1);
            mystery2.Should().Be(Mystery.Joyful2);
            mystery3.Should().Be(Mystery.Joyful3);
            mystery4.Should().Be(Mystery.Joyful4);
            mystery5.Should().Be(Mystery.Joyful5);
            mystery6.Should().Be(Mystery.Luminous1);
            mystery7.Should().Be(Mystery.Luminous2);
            mystery8.Should().Be(Mystery.Luminous3);
            mystery9.Should().Be(Mystery.Luminous4);
            mystery10.Should().Be(Mystery.Luminous5);
            mystery11.Should().Be(Mystery.Sorrowful1);
            mystery16.Should().Be(Mystery.Glorious1);
            mystery20.Should().Be(Mystery.Glorious5);
            rosary.LockedMysteries.Count().Should().Be(21);
        }
Example #19
0
        /// <summary>
        /// Speichere ein Mystery
        /// </summary>
        /// <param name="mystery"></param>
        /// <param name="filename"></param>
        public static void Save(Mystery mystery, string filename)
        {
            string text = "";

            foreach (Field field in mystery.FieldList)
            {
                text += field.XCoordinate + ":" + field.YCoordinate + ":" + (int)field.Status + ":" + field.IsShipField + "\r";
            }
            foreach (Ship ship in mystery.ShipList)
            {
                text += "s:" + ship.Size + "\r";
            }
            text += "c:x:" + mystery.MysteryCreator.NumberOfRows + "\r";
            text += "c:y:" + mystery.MysteryCreator.NumberOfColumns + "\r";
            using (StreamWriter sw = new StreamWriter(filename))
            {
                sw.Write(text);
            }
        }
Example #20
0
        public async Task <ActionResult <Mystery> > CreateMystery(Mystery mystery)
        {
            try
            {
                if (mystery == null)
                {
                    return(BadRequest());
                }

                var createdMystery = await mysteryRepository.AddMystery(mystery);

                return(CreatedAtAction(nameof(GetMystery), new { id = createdMystery.Id }, createdMystery));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error retrieving data from database"));
            }
        }
Example #21
0
        public ActionResult Index(Mystery model)
        {
            if (ModelState.IsValid)
            {
                Session["MYSTERY_OK"] = true;
                return(RedirectToAction("Mystery", "Home"));
            }

            var           clues     = new Dictionary <string, bool>();
            StringBuilder solutions = new StringBuilder();

            string[] keys = new string[] { "Clue1", "Clue2", "Clue3", "Clue4", "Clue5", "Clue6", "Clue7", "Clue8", "Clue9" };
            for (int i = 0; i < keys.Length; i++)
            {
                clues.Add(keys[i], false);
            }

            foreach (var key in ModelState.Keys)
            {
                if (ModelState[key].Errors.Count > 0)
                {
                    clues[key] = false;
                    solutions.AppendLine(key + ":");
                }
                else
                {
                    clues[key] = true;
                    solutions.AppendLine(key + ":" + ModelState[key].Value.AttemptedValue);
                }
            }
            ViewBag.ClueValid = clues;

            /*
             * string cookieValue = solutions.ToString().Replace("\r\n", "|");
             * HttpCookie cookie = new HttpCookie("MYSTERY_SOLUTIONS", cookieValue);
             * cookie.Expires = DateTime.Now.AddYears(1);
             *
             * HttpContext.Response.Cookies.Add(cookie);
             */
            return(View(model));
        }
Example #22
0
    public void CheckMystery()
    {
        Mystery m = App.Model.mysteryModel.activeMystery;

        if (App.Model.mysteryModel.mysteryProgress >= m.requirement)
        {
            if (App.Model.ancientOneModel.ancientOne.finalMysteryActive)
            {
                GameManager.SingleInstance.MysteryChecked();
            }
            else
            {
                // Mystery Solved
                App.Model.mysteryModel.MysterySolved();
            }
        }
        else
        {
            // Mystery Not Solved
            GameManager.SingleInstance.MysteryChecked();
        }
    }
        public void ExportSolutionTest()
        {
            string tmpFilename = Path.GetTempFileName();

            MysteryCreator mysteryCreator = new MysteryCreator();

            mysteryCreator.NumberOfColumns = 7;
            mysteryCreator.NumberOfRows    = 7;
            mysteryCreator.NumberOfShips   = 12;
            Mystery mystery = mysteryCreator.Create();

            ExportService.ExportSolution(mystery, tmpFilename);

            if (File.Exists(tmpFilename))
            {
                Assert.IsTrue(true);
                File.Delete(tmpFilename);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Example #24
0
        /// <summary>
        /// Contcrete Book maker based on type
        /// </summary>
        /// <param name="bookType">type of book to make</param>
        /// <returns></returns>
        public static Book CreateBook(string bookType)
        {
            Book book = null;

            switch (bookType.ToLower())
            {
            case "scifi":
                book = new SciFi();
                break;

            case "western":
                book = new Western();
                break;

            case "mystery":
                book = new Mystery();
                break;

            default:
                break;
            }
            return(book);
        }
Example #25
0
 /// <summary>
 /// Lade ein mystery
 /// </summary>
 /// <param name="mystery"></param>
 /// <param name="filename"></param>
 /// <returns></returns>
 public static Mystery Load(Mystery mystery, string filename)
 {
     mystery.FieldList.Clear();
     mystery.ShipList.Clear();
     using (var streamReader = File.OpenText(filename))
     {
         var lines = streamReader.ReadToEnd().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
         foreach (var line in lines)
         {
             var arguments = line.Split(":");
             if (arguments[0] == "s")
             {
                 Ship ship = new Ship(Convert.ToInt32(arguments[1]));
                 mystery.ShipList.Add(ship);
             }
             else if (arguments[0] == "c")
             {
                 if (arguments[1] == "y")
                 {
                     mystery.MysteryCreator.NumberOfColumns = Convert.ToInt32(arguments[2]);
                 }
                 if (arguments[1] == "x")
                 {
                     mystery.MysteryCreator.NumberOfRows = Convert.ToInt32(arguments[2]);
                 }
             }
             else
             {
                 Field field = new Field(Convert.ToInt32(arguments[0]), Convert.ToInt32(arguments[1]));
                 field.Status      = (Enum.FieldStatus)Convert.ToInt32(arguments[2]);
                 field.IsShipField = Convert.ToBoolean(arguments[3]);
                 mystery.FieldList.Add(field);
             }
         }
     }
     return(mystery);
 }
Example #26
0
        public async Task <ActionResult <Mystery> > UpdateMystery(int id, Mystery mystery)
        {
            try
            {
                if (id != mystery.Id)
                {
                    return(BadRequest("Chase ID mismatch"));
                }

                var mysteryToUpdate = await mysteryRepository.GetMystery(id);

                if (mysteryToUpdate == null)
                {
                    return(NotFound($"Chase with id {id} not found"));
                }

                return(await mysteryRepository.UpdateMystery(mystery));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error updating data"));
            }
        }
        /// <summary>
        /// Erstellt die Tabelle für den PDF Export
        /// </summary>
        /// <param name="mystery">Das Mystery welches für die Generation verwendet werden soll</param>
        /// <param name="isForSolution">Definiert, ob die Tabelle für die Lösung oder für das Rätsel generiert werden soll.</param>
        /// <returns></returns>
        private static PdfPTable CreateTable(Mystery mystery, bool isForSolution)
        {
            int[] shipColumnCounter = new int[mystery.MysteryCreator.NumberOfColumns];
            int[] shipRowCounter    = new int[mystery.MysteryCreator.NumberOfRows];


            PdfPTable table = new PdfPTable(mystery.MysteryCreator.NumberOfColumns + 1);

            table.AddCell("");


            for (int y = 1; y <= mystery.MysteryCreator.NumberOfColumns; y++)
            {
                int countedShips = mystery.FieldList.Where(f => f.IsShipField && f.XCoordinate == y).Count();

                table.AddCell(countedShips.ToString());
            }

            for (int y = 1; y <= mystery.MysteryCreator.NumberOfRows; y++)
            {
                for (int x = 1; x <= mystery.MysteryCreator.NumberOfColumns; x++)
                {
                    if (x == 1)
                    {
                        int countedShips = mystery.FieldList.Where(f => f.IsShipField && f.YCoordinate == y).Count();

                        table.AddCell(countedShips.ToString());
                    }


                    Field    field = mystery.FieldList.First(f => f.XCoordinate == x && f.YCoordinate == y);
                    PdfPCell cell  = new PdfPCell();

                    if (isForSolution)
                    {
                        if (field.IsShipField)
                        {
                            cell.BackgroundColor = BaseColor.ORANGE;
                            cell.Phrase          = new Phrase("X");
                        }
                        else
                        {
                            cell.BackgroundColor = BaseColor.BLUE;
                        }
                    }
                    else
                    {
                        switch (field.Status)
                        {
                        case Enum.FieldStatus.Unexplored:
                            cell.BackgroundColor = BaseColor.WHITE;
                            break;

                        case Enum.FieldStatus.Water:
                            cell.BackgroundColor = BaseColor.BLUE;
                            break;

                        case Enum.FieldStatus.Ship:
                            cell.BackgroundColor = BaseColor.ORANGE;
                            cell.Phrase          = new Phrase("X");
                            break;
                        }
                    }
                    table.AddCell(cell);

                    if (field.IsShipField)
                    {
                        shipRowCounter[y - 1]++;
                        shipColumnCounter[x - 1]++;
                        var no = field.IsShipField;
                    }
                }
            }
            return(table);
        }
Example #28
0
 public ActionResult <Mystery> Put([FromBody] Mystery val)
 {
     return(Ok(_repo.ChangeMystery(val, val.Id)));
 }
Example #29
0
        public ActionResult <Mystery> Post([FromBody] Mystery value)
        {
            Mystery answer = _repo.CreateMystery(value);

            return(Ok(_repo.GetForUser(answer.UserId)));
        }
Example #30
0
 public Prayer(Rosary rosary, Mystery mystery)
 {
     Rosary  = rosary;
     Mystery = mystery;
 }