public static void Main(string[] args) { // Load story file string storyJson = File.ReadAllText("Stories/musgraveritual.json"); StoryModel model = StoryModel.Create(storyJson); // Load story into player StoryPlayer player = new StoryPlayer(model, new Inklewriter.MarkupConverters.ConsoleMarkupConverter()); // Display header Console.Clear(); Console.WriteLine(); Console.WriteLine(player.Title); Console.WriteLine("by " + player.Author); // Main loop Stitch lastStitch = player.InitialStitch; while (lastStitch != null) { Console.WriteLine(); DrawHorizontalLine(); Console.WriteLine(); var nextChunk = player.CreateChunkForStitch(lastStitch); lastStitch = DisplayChunk(nextChunk); } }
private string StitchToString(Stitch type) { switch (type) { case Stitch.Straight: return("Straight Stitch"); case Stitch.Zigzag: return("Zigzag Stitch"); case Stitch.Overcasting: return("Overcasting Stitch"); case Stitch.Locking: return("Locking Stitch"); case Stitch.TripleStretch: return("Triple Stretch Stitch"); case Stitch.Saddle: return("Saddle Stitch"); case Stitch.Blind: return("Blind Stitch"); default: return("?"); } }
public IActionResult Import() { using (StreamReader lezer = new StreamReader(new FileStream("myCsv.txt", FileMode.Open))) { string lijn = lezer.ReadLine(); while (!lezer.EndOfStream) { lijn = lezer.ReadLine(); string[] splits = lijn.Split(';'); Stitch stitch = new Stitch(); stitch.DeliveryDate = Convert.ToDateTime(splits[4]); stitch.JobNumber = splits[1]; double aantal = double.Parse(splits[2]); stitch.Quantity = Convert.ToInt16(aantal); stitch.PaperBw = splits[8]; stitch.MachineId = 1; stitch.UserId = 1; _context.Stitches.Add(stitch); } } _context.SaveChanges(); return(RedirectToAction("Index", 1)); }
public void ConstructorWithStitch() { Stitch stitch = new Stitch(); Option option = new Option(stitch); Assert.AreSame(stitch, option.ParentStitch); }
public void ConstructorWithString() { string body = "This is a stitch."; Stitch stitch = new Stitch(body); Assert.AreEqual(stitch.Text, body); }
public void WordCount() { Stitch stitch = new Stitch(); stitch.Text = "One two three."; Assert.AreEqual(stitch.WordCount, 3); }
public void AutomaticPageLabel() { Stitch stitch = new Stitch(); stitch.PageNumber = 3; Assert.AreEqual("Section 3", stitch.PageLabel); }
public void CollectStitch(Player player) { LastStitch.Clear(); LastStitch.AddRange(Stitch); Stitch.Clear(); if (CurrentPlayer == player && GamePlayer == player && player.Game.Type == GameType.Null && player.Stitches.Any()) { foreach (var p in Players) { p.Cards.Clear(); } } if (player.Cards.Count == 0) { var game = GamePlayer.Game; GameValue = game.GetGameValue(MatadorsJackStraight, GamePlayer.Stitches, Skat, CurrentBidValue, false); GamePlayer.Score += GameValue.Score; CurrentHistory.GamePlayerScore = GetScore(GamePlayer); CurrentHistory.GameValue = GameValue.Score; SkatResult.History.Add(CurrentHistory); SkatResult.EndedUtc = DateTime.UtcNow; } }
public void GiveUp() { // add all cards on the game player's hand to the stitch of one opponent player Player opponentPlayer = null; foreach (var p in Players) { if (p != GamePlayer && opponentPlayer == null) { opponentPlayer = p; p.Stitches.AddRange(GamePlayer.Cards); p.Stitches.AddRange(GamePlayer.Stitches); p.Stitches.AddRange(p.Cards); p.Stitches.AddRange(Skat); p.Stitches.AddRange(Stitch); p.Cards.Clear(); GamePlayer.Cards.Clear(); GamePlayer.Stitches.Clear(); Skat.Clear(); Stitch.Clear(); } else if (p != GamePlayer && opponentPlayer != null) { opponentPlayer.Stitches.AddRange(p.Cards); p.Cards.Clear(); } } var game = GamePlayer.Game; GameValue = game.GetGameValue(MatadorsJackStraight, GamePlayer.Stitches, Skat, CurrentBidValue, true); GamePlayer.Score += GameValue.Score; }
public void PlayCard(Player player, Card card) { // move card to Skat if (GamePlayer == player && SkatTaken && !GameStarted) { if (Skat.Count < 2) { player.Cards.Remove(card); Skat.Add(card); } } else if (GameStarted && CurrentPlayer == player) { if (Stitch.Count == 3) { CollectStitch(player); if (player.Cards.Count == 0) { return; // game ended } } if (IsValidForStitch(card)) { player.Cards.Remove(card); CurrentPlayer = GetNextPlayer(player); Stitch.Add(card); if (Stitch.Count == 3) { var stichPlayer = GetStitchPlayer(); stichPlayer.Stitches.AddRange(Stitch); CurrentPlayer = stichPlayer; } } } }
public void IsDead() { Stitch stitch = new Stitch(); Assert.IsTrue(stitch.IsDead); stitch.Text = "Text"; Assert.IsFalse(stitch.IsDead); }
public void CreateLinkStitchIncrementsRefCount() { Option option = new Option(); Stitch linkStitch = new Stitch(); option.CreateLinkStitch(linkStitch); Assert.AreEqual(1, linkStitch.RefCount); }
public void CreateLinkStitch() { Option option = new Option(); Stitch linkStitch = new Stitch(); option.CreateLinkStitch(linkStitch); Assert.AreSame(linkStitch, option.LinkStitch); }
public void CalculateApproximateWordCount() { Stitch a = new Stitch("The quick brown fox"); Stitch b = new Stitch("jumped over the lazy dog."); int wordCount = StoryPlayer.CalculateApproximateWordCount(new List <Stitch> { a, b }); // Word count is rounded to the nearest 10 when under 100 words, otherwise rounded to 100 Assert.AreEqual(10, wordCount); }
public void Unlink() { Option option = new Option(); Stitch linkStitch = new Stitch(); option.CreateLinkStitch(linkStitch); option.Unlink(); Assert.IsNull(option.LinkStitch); }
public SewingRecipe(Bolt one, Bolt two, Stitch stitch, Bolt three, Stitch stitch2) { this.item1 = one; this.item2 = two; this.firstStitch = stitch; this.item3 = three; this.secondStitch = stitch2; }
public void ProcessFlagSetting() { List <FlagValue> flags = new List <FlagValue> { new FlagValue("a", true), new FlagValue("b", 5), new FlagValue("c", 10), new FlagValue("d", false), new FlagValue("e", true), new FlagValue("f", 1), new FlagValue("g", true), }; // Test new flags Stitch stitchA = new Stitch { Flags = new List <string> { "a = false", // set a boolean "b = 2", // set a number "c + 1", // add to a number "d = 7", // convert a boolean to a number "e + 1", // add a number to a boolean, which is weird, but valid "f + true", // add a boolean to a number, invalid "g + true" // add a boolean to a boolean, invalid } }; StoryModel.ProcessFlagSetting(stitchA, flags); Assert.AreEqual(0, flags [0].value); Assert.AreEqual(2, flags [1].value); Assert.AreEqual(11, flags [2].value); Assert.AreEqual(7, flags [3].value); Assert.AreEqual(2, flags [4].value); Assert.AreEqual(1, flags [5].value); Assert.AreEqual(1, flags [6].value); // Test updating flags Stitch stitchB = new Stitch { Flags = new List <string> { "b = 3", "a = true", "h = 5" // new flag } }; StoryModel.ProcessFlagSetting(stitchB, flags); Assert.AreEqual(1, flags [0].value); // a = true Assert.AreEqual(3, flags [1].value); // b = 3 Assert.AreEqual(5, flags [7].value); // h = 5 }
public void StartNewRound() { GameCounter += 1; foreach (var p in Players) { p.Stitches.Clear(); p.Cards.Clear(); p.Game = new Game(GameType.Grand); switch (p.Position) { case PlayerPosition.Middlehand: p.Position = PlayerPosition.Forehand; p.BidStatus = BidStatus.Accept; break; case PlayerPosition.Rearhand: p.Position = PlayerPosition.Middlehand; p.BidStatus = BidStatus.Bid; break; case PlayerPosition.Forehand: p.Position = PlayerPosition.Rearhand; p.BidStatus = BidStatus.Wait; break; default: break; } } MatadorsJackStraight = null; GameStarted = false; GamePlayer = null; GameValue = null; SkatTaken = false; CurrentPlayer = null; Stitch.Clear(); Skat.Clear(); LastStitch.Clear(); using (var rng = new RNGCryptoServiceProvider()) { var deck = Card.GenerateDeck(); foreach (var player in Players) { player.Cards.AddRange(Card.Draw(rng, deck, 10)); } Skat.AddRange(Card.Draw(rng, deck, 2)); } BidSaid = false; BidValueIndex = -1; BidExceeded = false; }
private void Button_Add_Click(object sender, RoutedEventArgs e) { var stitch = new Stitch() { Comments = comments.Text, StartDate = startTime.Value ?? DateTime.Now, EndDate = endTime.Value ?? DateTime.Now }; this.model.Stitches.Add(stitch); stitchList.Items.Refresh(); this.UpdateTotal(); this.SaveData(); }
public IActionResult PlanStitch4(int id) { Stitch s = new Stitch(); s = _context.Stitches.FirstOrDefault(e => e.Id == id); s.MachineId = 5; _context.Entry(s).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); StitchJobsListVM stitchJobsListVM = new StitchJobsListVM(); stitchJobsListVM.stitchJobsList = _context.Stitches.Where(e => e.MachineId == 5).ToList(); return(View("Index", stitchJobsListVM)); }
public void ExplicitPageLabel() { Stitch stitch = new Stitch(); string originalLabel = "Section 3"; string customLabel = "Custom Label"; stitch.PageNumber = 3; stitch.PageLabel = customLabel; Assert.AreEqual(customLabel, stitch.PageLabel); stitch.PageLabel = ""; Assert.AreEqual(originalLabel, stitch.PageLabel); stitch.PageLabel = null; Assert.AreEqual(originalLabel, stitch.PageLabel); }
/// <summary>Used to clear a stitch</summary> public void clearStitch() { currentStitch = null; currentDialogNumber = 0; foreach (OnScreenPerformer a in performers) { a.image.enabled = false; } textBox.text = ""; nameBox.text = ""; for (int i = 0; i < buttons.Length; i++) { buttons[i].button.interactable = false;//Stops space from activating the button buttons[i].gObject.SetActive(false); } }
public void SpeedUpConfirmed() { IsSpeedUp = false; var game = GamePlayer.Game; if (game.Type != GameType.Null) { // add all remaining cards to the stitch of game player GamePlayer.Stitches.AddRange(Stitch); Stitch.Clear(); foreach (var p in Players) { GamePlayer.Stitches.AddRange(p.Cards); p.Cards.Clear(); } } else { // add all remaining cards to the stitch of an opponent player Player opponentPlayer = null; foreach (var p in Players) { if (p != GamePlayer) { opponentPlayer = p; break; } } opponentPlayer.Stitches.AddRange(Stitch); Stitch.Clear(); foreach (var p in Players) { opponentPlayer.Stitches.AddRange(p.Cards); p.Cards.Clear(); } } GameValue = game.GetGameValue(MatadorsJackStraight, GamePlayer.Stitches, Skat, CurrentBidValue, true); GamePlayer.Score += GameValue.Score; CurrentHistory.GamePlayerScore = GetScore(GamePlayer); CurrentHistory.GameValue = GameValue.Score; SkatResult.History.Add(CurrentHistory); SkatResult.EndedUtc = DateTime.UtcNow; }
public void ShortName() { Stitch stitch = new Stitch(); string expected = "blankStitch"; string name = stitch.CreateShortName(); Assert.AreEqual(expected, name); stitch.Text = "!!!"; expected = "punctuatedStitch"; name = stitch.CreateShortName(); Assert.AreEqual(expected, name); stitch.Text = "A brand! NEW short name."; expected = "aBrandNewShortNa"; name = stitch.CreateShortName(); Assert.AreEqual(expected, name, string.Format("Expected short name '{0}', found '{1}'", expected, stitch.Name)); }
public void CollectStitch(Player player) { LastStitch.Clear(); LastStitch.AddRange(Stitch); Stitch.Clear(); if (CurrentPlayer == player && GamePlayer == player && player.Game.Type == GameType.Null && player.Stitches.Any()) { foreach (var p in Players) { p.Cards.Clear(); } } if (player.Cards.Count == 0) { var game = GamePlayer.Game; GameValue = game.GetGameValue(MatadorsJackStraight, GamePlayer.Stitches, Skat, CurrentBidValue, false); GamePlayer.Score += GameValue.Score; } }
public void EmptyConstructor() { Stitch stitch = new Stitch(); Assert.IsEmpty(stitch.Backlinks); Assert.IsNull(stitch.DivertStitch); Assert.IsEmpty(stitch.Flags); Assert.IsEmpty(stitch.IfConditions); Assert.IsNull(stitch.Image); Assert.IsNull(stitch.Name); Assert.IsEmpty(stitch.NotIfConditions); Assert.IsEmpty(stitch.Options); Assert.IsNull(stitch.PageLabel); Assert.AreEqual(-1, stitch.PageNumber); Assert.AreEqual(0, stitch.RefCount); Assert.IsFalse(stitch.RunOn); Assert.IsNull(stitch.Text); Assert.AreEqual(0, stitch.VerticalDistance); Assert.AreEqual(0, stitch.VerticalDistanceFromPageNumberHeader); Assert.AreEqual(0, stitch.WordCount); }
private static void AddSewingRecipes() { foreach (var j in File.ReadAllLines(Path.Combine("GrowtopiaItemDatabase", "RecipeData", "SewingRecipes.txt"))) { if (String.IsNullOrEmpty(j) || j.StartsWith("//")) { continue; } string[] str = j.Split('|'); if (String.Equals(str[1], "SEW")) { int id = Convert.ToInt32(str[0]); Bolt one = SewingRecipe.StringToBolt(str[2]); Bolt two = SewingRecipe.StringToBolt(str[3]); Stitch three = SewingRecipe.StringToStitch(str[4]); Bolt four = SewingRecipe.StringToBolt(str[5]); Stitch five = SewingRecipe.StringToStitch(str[6]); items[id].SewingRecipe = new SewingRecipe(one, two, three, four, five); } } }
/// <summary>Used to load a new stitch</summary> public void LoadStitch(Stitch nextStitch) { clearStitch(); currentStitch = nextStitch; if (nextStitch.background != null) { backgroundTexture.sprite = (Sprite)nextStitch.background; } //Load into local memory currentDialogs = nextStitch.dialogs; currentYarns = nextStitch.yarns; for (int i = 0; i < nextStitch.performers.Length; i++) { loadActor(performers[i], nextStitch.performers[i]); } if (nextStitch.dialogs.Length > 0) { loadDialog(nextStitch.dialogs[0]); } inputAllowed = true; }
public void PerformPlayerAction(Player player, ActionType actionType) { switch (actionType) { case ActionType.TakeSkat: SkatTaken = true; break; case ActionType.PlayHand: SetGameOption(player, player.Game.Option | GameOption.Hand); break; case ActionType.StartGame: StartGame(player); break; case ActionType.DoNotPlayHand: var gameOption = player.Game.Option & ~GameOption.Hand; if (player.Game.Type != GameType.Null) { gameOption &= ~GameOption.Ouvert; } SetGameOption(player, gameOption); break; case ActionType.Bid: BidSaid = true; MoveNextBidValue(); break; case ActionType.PassBid: player.BidStatus = BidStatus.Pass; foreach (var p in Players) { if (p.Position == PlayerPosition.Rearhand && p.BidStatus != BidStatus.Pass) { p.BidStatus = BidStatus.Bid; break; } } BidSaid = false; break; case ActionType.HoldBid: BidSaid = false; break; case ActionType.PassHold: BidSaid = false; player.BidStatus = BidStatus.Pass; foreach (var p in Players) { if (p.Position == PlayerPosition.Rearhand && p.BidStatus != BidStatus.Pass) // weitersagen { p.BidStatus = BidStatus.Bid; } else if (p.Position == PlayerPosition.Middlehand && p.BidStatus != BidStatus.Pass) // hoeren { p.BidStatus = BidStatus.Accept; } } break; default: break; } if (actionType == ActionType.PassBid || actionType == ActionType.PassHold || actionType == ActionType.Bid) { // find if all player have given up Player gamePlayer = null; var cntPassen = 0; foreach (var p in Players) { if (p.BidStatus != BidStatus.Pass) { gamePlayer = p; continue; } cntPassen++; } // all gave up if (cntPassen == 3) { GamePlayer = Players[0]; GameValue = new GameValue { Score = 0 }; GameStarted = true; foreach (var p in Players) { p.Cards.Clear(); p.Stitches.Clear(); } Skat.Clear(); Stitch.Clear(); CurrentHistory.GamePlayerScore = 0; CurrentHistory.GameValue = 0; SkatResult.History.Add(CurrentHistory); SkatResult.EndedUtc = DateTime.UtcNow; } // two player gave up, remaing playing is the game player else if (gamePlayer != null && cntPassen == 2) { if (gamePlayer.Position == PlayerPosition.Forehand && CurrentBidValue == 0) { gamePlayer.BidStatus = BidStatus.Bid; } else { GamePlayer = gamePlayer; GameStarted = false; SkatTaken = false; } } } }
/// <summary> /// Generates and returns a PlayChunk that begins with the given Stitch /// and continues through the first available block of options. /// </summary> public PlayChunk CreateChunkForStitch(Stitch stitch) { if (stitch == null) { return(null); } PlayChunk chunk = new PlayChunk(); // Reload all flags from the previous stitch AllFlagsCollected.Clear(); if (LastChunk != null) { AllFlagsCollected.AddRange(LastChunk.FlagsCollected); } var currentStitch = stitch; var compiledText = ""; // Loop through all linked stitches while (currentStitch != null) { visitedStitches.Add(currentStitch); if (currentStitch.PageNumber >= 1) { chunk.HasSectionHeading = true; } bool isStitchVisible = StoryModel.DoesArrayMeetConditions(currentStitch.IfConditions, currentStitch.NotIfConditions, AllFlagsCollected); // This stitch passes flag tests and should be included in this chunk if (isStitchVisible) { // Remove newlines in preparation for compiling run-on stitches into one paragraph compiledText += currentStitch.Text.Replace("\n", " ") + " "; // If no more processing is needed, apply text substitutions and store the paragraph bool isRunOn = Regex.IsMatch(currentStitch.Text, @"\[\.\.\.\]") || currentStitch.RunOn; if (!isRunOn || currentStitch.DivertStitch == null) { var styledText = ApplyRuleSubstitutions(compiledText, AllFlagsCollected); chunk.Paragraphs.Add(new Paragraph(styledText, currentStitch.Image, currentStitch.PageLabel)); compiledText = ""; } // Modify all flags with flag states from the current stitch if (currentStitch.Flags.Count > 0) { StoryModel.ProcessFlagSetting(currentStitch, AllFlagsCollected); } } // Add stitch to chunk chunk.Stitches.Add(new BlockContent <Stitch> (currentStitch, isStitchVisible)); currentStitch = currentStitch.DivertStitch; } WordCount = 0; foreach (var p in chunk.Paragraphs) { WordCount += WordCountOf(p.Text); } // Add options to chunk if (LastStitch.Options.Count > 0) { foreach (var option in LastStitch.Options) { var isVisible = StoryModel.DoesArrayMeetConditions(option.IfConditions, option.NotIfConditions, AllFlagsCollected); if (isVisible) { chunk.Options.Add(new BlockContent <Option> (option, isVisible)); } } } chunk.FlagsCollected.AddRange(AllFlagsCollected); allChunks.Add(chunk); return(chunk); }
/*********************************** * GAME CONSTANTS **********************************/ void Awake() { instance = this; kat = GameObject.FindWithTag("Player").GetComponent<Kat_Base>(); }