public BlackjackGame(StreamReader inputStream, StreamWriter outputStream, IKeyReader keyReader) { this.inputStream = inputStream; this.outputStream = outputStream; this.keyReader = keyReader; this.Title = "♠♥♣♦ House of Payne Blackjack ♦♣♥♠"; }
public Task InvokeAsync(HttpContext context, AcManContext dbContext, IKeyReader keyReader) { CurrentConnection.Key = keyReader?.GetKeyFromRequest(context.Request) ?? AcmanHelper.GetKeyFromRequest(context.Request); //TODO: remove this if (System.Diagnostics.Debugger.IsAttached && string.IsNullOrEmpty(CurrentConnection.Key)) { CurrentConnection.Key = AcmanConstants.DemoKeyName; } if (!string.IsNullOrEmpty(CurrentConnection.Key)) { CurrentConnection.CurrentUser = AcmanHelper.GetUserByKey(CurrentConnection.Key, dbContext); } return(this._next(context)); }
public NinjaGame(IPlayer playerOne, IPlayer playerTwo, IGrid <IInteractable, IPlayer> layout, IKeyReader keyReader) { this.playerOne = playerOne; this.playerTwo = playerTwo; this.keyReader = keyReader; this.currentPlayer = this.playerOne; this.layout = layout; this.Winner = null; this.players = new List <IPlayer>() { this.playerTwo, this.playerOne }; this.playerEnumerator = this.players.GetEnumerator(); }
public MapReader() { _line = 0; _eventReceiverList = new List<EventRecievers>(); _keyReader = new KeyReader(); }
public DateTime Deserialize(IKeyReader reader) { var ticks = reader.ReadBeLong(); return(new DateTime(ticks)); }
public static void Execute(IQueue queue, IStorage storage, IKeyReader reader) { while (true) { // Get the next message string msgId; string popReceipt; string retrievedMessage = queue.GetMessage(out msgId, out popReceipt); //Process the message in less than 30 seconds, and then delete the message if (!String.IsNullOrEmpty(retrievedMessage)) { Console.WriteLine("Top message"); Console.WriteLine("Json:"); Console.WriteLine(retrievedMessage); try { PrintModel print = JsonConvert.DeserializeObject<PrintModel>(retrievedMessage); Console.WriteLine("Deserialized Print Model"); Console.WriteLine("First Name: " + print.FirstName); Console.WriteLine("Last Name: " + print.LastName); Console.WriteLine("Phrase: " + print.Phrase); // download the blob // deserialize it // add the new print // serialize it // upload the blob // the container where we'll put existing prints and the new print var prints = new PrintsModel(); if (storage.Exists()) { // existing content string blobJson = storage.DownloadText(); // try to deserialize it try { prints = JsonConvert.DeserializeObject<PrintsModel>(blobJson); } catch (Exception) { // couldn't deserialize the blob, so forget it, the new blob will // overwrite it } } else { // no existing blob } // add the new print prints.Add(print); // serialize it string jsonWithNewPrint = JsonConvert.SerializeObject(prints); // upload the blob storage.UploadText(jsonWithNewPrint); } catch (Exception) { Console.WriteLine("Error deserializing object"); } finally { Console.WriteLine("Deleting message"); queue.DeleteMessage(msgId, popReceipt); } } else { Console.WriteLine("No messages"); } // check again in 5 seconds System.Threading.Thread.Sleep(5000); if (reader.KeyAvailable) { break; } } }
public ListNavigator(IKeyReader keyReader, IItemsView printer) { _keyReader = keyReader; _printer = printer; }
//For Category tree and ICategory related types navigate and display public ICategory Navigate(IList <T> tree, IKeyReader reader, ITreePrinter <T> printer, bool autoExpandChildren) { List <T> sortedTree = (List <T>)tree; sortedTree.Sort((x, y) => x.Id - y.Id); T currentCategory = tree[0]; var neighbors = tree.Where(x => x.ParentId == currentCategory.Id).ToArray(); int parentId = 0; int horizontal = 0; sortedTree[0].Active = true; //Highlight root category currentCategory.Visible = true; printer.PrintTree(sortedTree); while (true) { Destination destination = reader.GetDestination(); if (destination == Destination.MoveDown) { if (currentCategory.ParentId == 0) // if top category move down opens childs { foreach (var id in neighbors) { sortedTree[id.Id - 1].Visible = true; //all Id in sorted list == index + 1 } parentId = currentCategory.ParentId; } else { SwitchCategory(false, currentCategory, sortedTree, autoExpandChildren); if (parentId != 0 && neighbors.Length > horizontal + 1) //can we move down? { horizontal++; currentCategory = neighbors[horizontal]; } } } else if (destination == Destination.MoveUp) { SwitchCategory(false, currentCategory, sortedTree, autoExpandChildren); if (0 <= horizontal - 1) { horizontal--; if (parentId != 0) { currentCategory = neighbors[horizontal]; } } } else if (destination == Destination.MoveRight) { SwitchCategory(false, currentCategory, sortedTree, autoExpandChildren); var children = tree.Where(x => x.ParentId == currentCategory.Id).ToArray(); if (children.Length != 0) { horizontal = 0; parentId = currentCategory.Id; currentCategory = children[horizontal]; neighbors = tree.Where(x => x.ParentId == parentId).ToArray(); foreach (var id in neighbors) { sortedTree[id.Id - 1].Visible = true; } } } else if (destination == Destination.MoveLeft) { if (currentCategory.ParentId != 0) { SwitchCategory(false, currentCategory, sortedTree, autoExpandChildren); if (parentId != 0) { foreach (var id in neighbors) { sortedTree[id.Id - 1].Visible = false; } currentCategory = sortedTree[currentCategory.ParentId - 1]; } parentId = currentCategory.ParentId; neighbors = tree.Where(x => x.ParentId == parentId).ToArray(); if (parentId != 0) { horizontal = Array.IndexOf(neighbors, currentCategory); } } } else if (destination == Destination.Select) { ResetActive(tree, currentCategory); return(currentCategory); } else if (destination == Destination.Esc) { ResetActive(sortedTree, currentCategory); HideAllCategories(sortedTree); printer.ClearView(sortedTree); return(null); } SwitchCategory(true, currentCategory, sortedTree, autoExpandChildren); printer.ClearView(sortedTree); printer.PrintTree(sortedTree); } }
protected void SetUp() { reader = A.Fake <TextReader>(); writer = A.Fake <TextWriter>(); keyReader = A.Fake <IKeyReader>(); }
public UserController(UserRepository repository, IKeyReader keyReader) : base(repository, keyReader) { }
public EndSystemController(EndSystemRepository repository, IKeyReader keyReader) : base(repository, keyReader) { }
public Control Navigate(IKeyReader reader, IField field, IFieldPrinter printer) { field.FieldCells[field.ActiveIndex].Active = true; int indexX = field.FieldCells[field.ActiveIndex].PositionX; int indexY = field.FieldCells[field.ActiveIndex].PositionY; printer.Print(); while (true) { Destination destination = reader.GetDestination(); if (destination == Destination.MoveDown) { if (indexY < Settings.FieldSize - 1) { field.FieldCells[indexY * Settings.FieldSize + indexX].Active = false; previousCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; indexY++; field.FieldCells[indexY * Settings.FieldSize + indexX].Active = true; currentCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; } } if (destination == Destination.MoveUp) { if (indexY > 0) { field.FieldCells[indexY * Settings.FieldSize + indexX].Active = false; previousCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; indexY--; field.FieldCells[indexY * Settings.FieldSize + indexX].Active = true; currentCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; } } if (destination == Destination.MoveRight) { if (indexX < Settings.FieldSize - 1) { field.FieldCells[indexY * Settings.FieldSize + indexX].Active = false; previousCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; indexX++; field.FieldCells[indexY * Settings.FieldSize + indexX].Active = true; currentCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; } } if (destination == Destination.MoveLeft) { if (indexX > 0) { field.FieldCells[indexY * Settings.FieldSize + indexX].Active = false; previousCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; indexX--; field.FieldCells[indexY * Settings.FieldSize + indexX].Active = true; currentCell = field.FieldCells[indexY * Settings.FieldSize + indexX]; } } if (destination == Destination.Esc) { return(Control.Exit); } if (destination == Destination.Select) { field.ActiveIndex = indexY * Settings.FieldSize + indexX; return(Control.Open); } if (destination == Destination.Flag) { field.ActiveIndex = indexY * Settings.FieldSize + indexX; field.FieldCells[field.ActiveIndex].Flagged = field.FieldCells[field.ActiveIndex].Flagged == false; return(Control.Flag); } printer.Print(currentCell, previousCell); } }
public UserInSystemController(UserInSystemRepository repository, IKeyReader keyReader) : base(repository, keyReader) { }
public BaseController(T1 repository, IKeyReader keyReader) { _repository = repository; _keyReader = keyReader; }
public MapReader() { _line = 0; _eventReceiverList = new List <EventRecievers>(); _keyReader = new KeyReader(); }
public CurrentActivityController(ActivityRepository repository, IKeyReader keyReader) : base(repository, keyReader) { }
public OneTimePasCryptoStream(TextReader reader, TextWriter writer, IKeyReader keyReader) { UnderlayingReader = reader; UnderlayingWriter = writer; this.keyReader = keyReader; }
public void Run() { Settings settings = new Settings(); FieldFiller filler = new FieldFiller(); WinChecker winChecker = new WinChecker(); SettingsView settingsView = new SettingsView(); KeySwitcher switcher = new KeySwitcher(); while (true) { settingsView.GetSettings(settings); IField field = new Field(); Console.SetWindowSize(settings.FieldSize * 3, settings.FieldSize * 3 + 5); filler.Randomize(settings, field); FieldPrinter printer = new FieldPrinter(settings, field); CellPrinter cellPrinter = new CellPrinter(settings, field); OpenChecker checker = new OpenChecker(settings); MessageView message = new MessageView(settings); FieldNavigator navigator = new FieldNavigator(settings); IKeyReader keyReader = switcher.SwitchKeyboard(settings); bool gameRun = true; while (gameRun) { //printer.Print(); Control action = navigator.Navigate(keyReader, field, cellPrinter); if (action == Control.Exit) { if (message.ShowMessage(settings.ExitMsg, settings.YesNoMsg)) { return; } } else if (action == Control.Open) { bool result = checker.Check(field, field.FieldCells[field.ActiveIndex]); if (result) //Boom! { printer.Print(); if (message.ShowMessage(settings.LooseMsg, settings.ExitNewMsg)) { return; } else { gameRun = false; } } if (winChecker.Check(field)) //Win! { printer.Print(); if (message.ShowMessage(settings.WinMsg, settings.ExitNewMsg)) { return; } else { gameRun = false; } } } else if (action == Control.Flag) { if (winChecker.Check(field)) //Win! { printer.Print(); if (message.ShowMessage(settings.WinMsg, settings.ExitNewMsg)) { return; } else { gameRun = false; } } } } } }