public void Ties(Pick p1, Pick p2) { List<IPlayer> players = new List<IPlayer>(); IPlayer player1 = Substitute.For<IPlayer>(); player1.Pick.Returns(p1); player1.Slot.Returns(1); players.Add(player1); IPlayer player2 = Substitute.For<IPlayer>(); player2.Pick.Returns(p2); player2.Slot.Returns(2); players.Add(player2); var game = new Game(players); var gameResult = Result.None; var victor = -1; game.GameEnds = (result, i) => { gameResult = result; victor = i; }; game.StartGame(); Thread.Sleep(100); Assert.AreEqual(Result.Tie, gameResult); }
public ActionResult Create(PickUploadVM pick) { ApplicationUser currentUser = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name); Pick pi = new Pick { PostedBy = currentUser, PostedOn = DateTime.Now, Description = pick.Description, PictureUrl = pick.Url, }; if (pick.File != null) { using (var ms = new MemoryStream()) { pick.File.InputStream.CopyTo(ms); pi.Image = Pick.ScaleImage(ms.ToArray(), 150, 150); } } else { pi.Image = pi.GetBytes(pi.PictureUrl); } db.Picks.Add(pi); db.SaveChanges(); var result = new { Id = pi.Id, Description = pi.Description, PostedOn = pi.PostedOn.ToString(), PostedBy = pi.PostedBy.UserName }; return Json(result, JsonRequestBehavior.AllowGet); }
public ActionResult GetImage(int id) { var dbRow = db.Picks.Find(id); if (dbRow.Image == null) { Pick noImage = new Pick(); noImage.Image = noImage.GetBytes("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTLna360D4lNuRMj_2nBHnO-vtIh9QhpDXJPnfadeaMQEPJbGNoLdSZ4A"); return File(noImage.Image, "image"); } return File(dbRow.Image, "image"); }
public Form1() { InitializeComponent(); int left = 0; int top = 0; int width = 352; int height = 288; if (pick == null) { pick = new Pick(panelPreview.Handle, left, top, width, height); } }
/// Internal implementation detail. internal override void TryAlt(ref Worker wr, int i, Pick pkSelf, Cont <T> aK) { Spin: var state = this.State; if (state == Locked) { goto Spin; } if (state != Interlocked.CompareExchange(ref this.State, Locked, state)) { goto Spin; } if (state <= Empty) { goto EmptyOrDemand; } TryPick: var stSelf = Pick.TryPick(pkSelf); if (stSelf > 0) { goto AlreadyPicked; } if (stSelf < 0) { goto TryPick; } T value = this.Value; this.Value = default(T); this.State = Empty; aK.DoCont(ref wr, value); return; AlreadyPicked: this.State = Full; return; EmptyOrDemand: WaitQueue.AddTaker(ref this.Takers, i, pkSelf, aK); this.State = Demand; aK.TryNext(ref wr, i + 1, pkSelf); return; }
public UserPickResponse UserPick(string name, int pick1, int pick2, int pick3, int pick4, int pick5, int powerball) { UserPickResponse response = new UserPickResponse(); //check to make sure all numbers are unique List <int> numbers = new List <int>() { pick1, pick2, pick3, pick4, pick5 }; if (numbers.Distinct().Count() != 5) { response.Success = false; response.Message = "Your numbers are not all unique. There is a duplicate somewhere."; return(response); } if (numbers.Where(n => n < 1 || n > 69).Count() > 0) { response.Success = false; response.Message = "One or more of the pick is not between 1-69."; return(response); } if (powerball < 1 || powerball > 26) { response.Success = false; response.Message = "The powerball is not between 1-26"; return(response); } //create new pick then add it to the repository Pick userPick = new Pick { Name = name, NumberOne = pick1, NumberTwo = pick2, NumberThree = pick3, NumberFour = pick4, NumberFive = pick5, Powerball = powerball }; response.Success = true; response.PickResponse = userPick; repo.AddPick(userPick); return(response); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (m_MouseGroup.CalculateEntityCount() == 0) { return(inputDeps); } var handle = JobHandle.CombineDependencies(inputDeps, m_BuildPhysicsWorldSystem.FinalJobHandle); if (Input.GetMouseButtonDown(0) && (Camera.main != null)) { Vector2 mousePosition = Input.mousePosition; UnityEngine.Ray unityRay = Camera.main.ScreenPointToRay(mousePosition); var mice = m_MouseGroup.ToComponentDataArray <MousePick>(Allocator.TempJob); var IgnoreTriggers = mice[0].IgnoreTriggers != 0; mice.Dispose(); // Schedule picking job, after the collision world has been built handle = new Pick { CollisionWorld = m_BuildPhysicsWorldSystem.PhysicsWorld.CollisionWorld, NumDynamicBodies = m_BuildPhysicsWorldSystem.PhysicsWorld.NumDynamicBodies, SpringData = SpringDatas, RayInput = new RaycastInput { Start = unityRay.origin, End = unityRay.origin + unityRay.direction * k_MaxDistance, Filter = CollisionFilter.Default, }, Near = Camera.main.nearClipPlane, Forward = Camera.main.transform.forward, IgnoreTriggers = IgnoreTriggers, }.Schedule(JobHandle.CombineDependencies(handle, m_BuildPhysicsWorldSystem.FinalJobHandle)); PickJobHandle = handle; handle.Complete(); // TODO.ma figure out how to do this properly...we need a way to make physics sync wait for // any user jobs that touch the component data, maybe a JobHandle LastUserJob or something that the user has to set } if (Input.GetMouseButtonUp(0)) { SpringDatas[0] = new SpringData(); } return(handle); }
public void AddPick(Pick pick) { List <Pick> newPicks = GetPicksList(); pick.ID = currentId; newPicks.Add(pick); currentId++; using (StreamWriter sw = new StreamWriter(filePath)) { foreach (var p in newPicks) { sw.WriteLine($"{p.ID},{p.Name},{p.NumberOne},{p.NumberTwo},{p.NumberThree},{p.NumberFour},{p.NumberFive},{p.Powerball}"); } } }
public void ShouldBeAbleToPickUsingBetweenPickerConstraint() { var builderSetup = new BuilderSettings(); var simpleClasses = Builder <SimpleClass> .CreateListOfSize(10).Build(); var products = Builder <MyClass> .CreateListOfSize(10) .All() .With(x => x.SimpleClasses = Pick <SimpleClass> .UniqueRandomList(With.Between(1, 5).Elements).From(simpleClasses)).Build(); for (int i = 0; i < products.Count; i++) { Assert.That(products[i].SimpleClasses.Count, Is.AtLeast(1)); Assert.That(products[i].SimpleClasses.Count, Is.AtMost(5)); } }
void Awake() { m_box = GetComponent <BoxCollider>(); m_t = transform; //m_gap = -transform.localPosition.x; if (m_world == null) { Debug.LogWarning("Can not dig without World instance"); } if (instance) { Debug.LogError("multi instance if player found!"); } instance = this; lastPosition = new Vector2(Mathf.RoundToInt(m_t.position.x - m_gap), Mathf.RoundToInt(m_t.position.y - m_gap)); }
public PackPickItemModel() // new item { PackItem = new Pick(); (PackItem as Pick).Properties = new List <PickProperty>(); Items = new ObservableCollection <PackPropertyItemModel>(); Items.CollectionChanged += (a, b) => { (PackItem as Pick).Properties = Items.Select(x => x.PropertyDef).ToList(); }; Items.Add(new PackPropertyItemModel() { ParentCollection = Items }); AddPropertyCommand = new RelayCommand(AddProperty); RemoveCommand = new RelayCommand(Remove); }
// Use this for initialization void Save() { Pick option = new Pick(); option._pick = _UIManager.GetComponent <UIManagerScript>()._pick; // сохраняет выбор перса if (!Directory.Exists(Application.dataPath + "/saves")) // проверяем наличие папки сохранения { Directory.CreateDirectory(Application.dataPath + "/saves"); // если нет то создаем } FileStream fs = new FileStream(Application.dataPath + "/saves/save.sav", FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, option); fs.Close(); }
public void Ignore(int pickId) { // Locate the pick Pick pick = _database.Picks.Find(pickId); // Locate the currently logged in user Models.User user = Authentication.GetCurrentUser(); // Add the logged in user to the followers of the pick if (pick != null) { user.SubscribedPicks.Remove(pick); _database.SaveChanges(); } }
public void ShouldBeAbleToPickUsingBetweenPickerConstraint() { var builderSetup = new BuilderSettings(); var simpleClasses = Builder <SimpleClass> .CreateListOfSize(10).Build(); var products = Builder <MyClass> .CreateListOfSize(10) .All() .With(x => x.SimpleClasses = Pick <SimpleClass> .UniqueRandomList(With.Between(1, 5).Elements).From(simpleClasses)).Build(); for (int i = 0; i < products.Count; i++) { products[i].SimpleClasses.Count.ShouldBeGreaterThanOrEqualTo(1); products[i].SimpleClasses.Count.ShouldBeLessThanOrEqualTo(5); } }
public void CreatingAListOfProductsAndAddingThemToCategories() { var categories = Builder <Category> .CreateListOfSize(50).Build(); var products = Builder <Product> .CreateListOfSize(500) .All() .With(x => x.Categories = Pick <Category> .UniqueRandomList(With.Between(5, 10).Elements).From(categories)) .Build(); foreach (var product in products) { Assert.That(product.Categories.Count, Is.AtLeast(5)); Assert.That(product.Categories.Count, Is.AtMost(10)); } }
/// <summary> /// Creates a new <see cref="Pick"/> that waits for any of the given <see cref="Activity"/>s to complete. /// </summary> /// <param name="activities"></param> /// <returns></returns> public static Pick PickAny(params Activity[] activities) { if (activities == null) { throw new ArgumentNullException(nameof(activities)); } var pick = new Pick(); foreach (var activity in activities) { pick.Branch(activity); } return(pick); }
public Pick PickCard(Draft draft, Member member, Card card) { var pick = new Pick() { Draft = draft, Member = member, Card = card, CreatedDate = DateTime.Now }; using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Save(pick); transaction.Commit(); } return(pick); }
internal override void TryAlt(ref Worker wr, int i, Cont <X> xK, Else xE) { var pk = xE.pk; if (0 == Pick.Claim(pk)) { Job <xA> xAJ; try { xAJ = Do(); } catch (Exception e) { Pick.PickClaimedAndSetNacks(ref wr, i, pk); xAJ = new AltFail <xA>(e); } xAJ.DoJob(ref wr, new PrepareAltCont <X, xA>(i, xK, xE)); } }
public void UsingTheWithBetween_And_SyntaxForGreaterReadability() { var categories = Builder <Category> .CreateListOfSize(50).Build(); var products = Builder <Product> .CreateListOfSize(500) .All() .With(x => x.Categories = Pick <Category> .UniqueRandomList(With.Between(5).And(10).Elements).From(categories)) .Build(); foreach (var product in products) { Assert.That(product.Categories.Count, Is.AtLeast(5)); Assert.That(product.Categories.Count, Is.AtMost(10)); } }
public static void FindPickByID() { Console.Clear(); int identifier = 0; bool validIdentifier = false; while (!validIdentifier) { Console.Write("Enter a three digit ID number to display pick : "); string input = Console.ReadLine(); if (!int.TryParse(input, out identifier)) { Console.Clear(); Console.WriteLine("That was not even a number!"); } else if (identifier < 100 || identifier > 999) { Console.Clear(); Console.WriteLine("That was not a three digit number!"); } else { validIdentifier = true; } } PickRepository pickFinder = new PickRepository(); Pick result = pickFinder.FindById(identifier); if (result.Identifier < 100 || result.Identifier > 999) { Console.Clear(); Console.WriteLine("That ID is not linked to any existing pick."); Console.WriteLine(); Console.WriteLine("Press enter to return to the Main Menu."); Console.ReadLine(); } else { Console.Clear(); PickDisplay.DisplayHeader(); PickDisplay.DisplayPick(result); Console.WriteLine(); Console.WriteLine("Press enter to return to the Main Menu."); Console.ReadLine(); } }
static void Main(string[] args) { var client = new RestClient("http://localhost:5000"); //the default address of Cashier node API var mre = new ManualResetEventSlim(); var random = new Random(); var drinkTypes = Builder <BeverageType> .CreateListOfSize(10) .All() .With(x => x.Name = Pick <string> .RandomItemFrom( new [] { "Frappuccino", "Americano", "Mocha", "Iced Tea", "Latte", "Machiato", "Hot Chocolate" })) .With(x => x.Price = random.Next(2, 12)) .Build(); var orders = Builder <Order> .CreateListOfSize(100) .All() .With(x => x.CustomerName = Faker.Name.First()) .With(x => x.Type = Pick <BeverageType> .RandomItemFrom(drinkTypes)) .With(x => x.WhenCompleted = null) .Build(); Console.WriteLine("Client simulator, sending random orders to the cashier"); Task.Run(() => { while (!mre.IsSet) { var request = new RestRequest("/orders", Method.POST); request.AddJsonBody(Pick <Order> .RandomItemFrom(orders)); client.Execute(request); Thread.Sleep(random.Next(1000, 3000)); } }); Console.ReadKey(); mre.Set(); }
/// <summary> /// Create activity metadata /// </summary> /// <param name="metadata">Metadata</param> protected override void CacheMetadata(NativeActivityMetadata metadata) { // Initialize Approve activity _initializeApprove = CreateInitializeApprove(); // Handle web service call. It will wait till task approved/rejected. _sendReceiveApprove = CreateSendReceiveApprove(); // Use a pick activity to handle expiring time _waitForApproveCompletion = CreateWaitForApprove(); // Approve activities _approveSequence = CreateApproveBody(); // Set up the activity metadata SetupMetadata(metadata); }
private void SetComputerPickPicture(Pick ComputerPickPicture) { switch (ComputerPickPicture) { case Pick.Rock: ComputerPictureBox.Image = Properties.Resources.rock; break; case Pick.Paper: ComputerPictureBox.Image = Properties.Resources.paper; break; case Pick.Scissor: ComputerPictureBox.Image = Properties.Resources.scissors; break; } }
public override void OnPick(ObjectBase pick, ObjectBase picker) { base.OnPick (pick, picker); if (pick == null || picker == null) return; Pick obj = pick as Pick; if (obj == null) return; PickTableItem pti = obj.GetCurPickTableItem(); if (pti == null) return; if (!ObjectType.IsPlayer(picker.Type)) return; if (pti.resID == mGoldId1 || pti.resID == mGoldId2 || pti.resID == mGoldId3) { if (mCurPickCount >= mMaxPickCount) return; mCurPickCount++; MaoStageUpdateGoldEvent eUI = new MaoStageUpdateGoldEvent(); eUI.CurrentGold = mCurPickCount; eUI.TotalGold = mMaxPickCount; eUI.PickPos = obj.GetPosition(); EventSystem.Instance.PushEvent(eUI); if (mCurPickCount >= mMaxPickCount) { EventSystem.Instance.PushEvent(new MaoStageSucceedEvent()); } } else { FindPickEvent e = new FindPickEvent(); e.OwnerId = (int)picker.InstanceID; e.PickResId = pti.resID; e.Position = obj.GetPosition(); EventSystem.Instance.PushEvent(e); } }
/// <summary> /// Create activity metadata /// </summary> /// <param name="metadata">Metadata</param> protected override void CacheMetadata(NativeActivityMetadata metadata) { // wait to start request and then run client activities _startWorkflowSequence = CreateStartWorkflowSequence(); // wait for any terminate request _terminate = CreateTerminateSendReceive(); // Use a Pick activity to handle user terminate requests _startWorkflowBody = CreateStartWorkflowBody(); // wrap everything in a catch activity _startWorkflowCatch = CreateStartWorkflowCatch(); // Set up the activity metadata SetupMetadata(metadata); }
public void PersistingUsingPick_UpTo_AndDoForEach() { var builderSetup = new SetupFixture().SetUp(); Database.Clear(); var categories = new Builder <Category>(builderSetup).CreateListOfSize(10).Persist(); new Builder <Product>(builderSetup) .CreateListOfSize(50) .All() .DoForEach((x, y) => x.AddToCategory(y), Pick <Category> .UniqueRandomList(With.UpTo(4).Elements).From(categories)) .Persist(); DataTable productCategoriesTable = Database.GetContentsOf(Database.Tables.ProductCategory); Assert.That(productCategoriesTable.Rows.Count, Is.LessThanOrEqualTo(50 * 4)); }
private void GAFStreamTool_FormClosing(object sender, FormClosingEventArgs e) { if (Program.SettingsForm != null && !Program.SettingsForm.Closed) { Program.SettingsForm.Close(); } Pick.StopAutoPickUpdate(); if (Program.Client != null && Program.Client.CurrentState != Network.Client.State.Failed && Program.Client.CurrentState != Network.Client.State.Disconnected && Program.Client.CurrentState != Network.Client.State.Disconnecting) { Program.Client.Dispose(); } }
public override void OnPick(ObjectBase pick, ObjectBase picker) { base.OnPick(pick, picker); if (pick == null || picker == null) { return; } Pick obj = pick as Pick; if (obj == null) { return; } PickTableItem pti = obj.GetCurPickTableItem(); if (pti == null) { return; } //switch(pti.resID) //{ // case 5: //齿轮碎片; // BattleUIEvent bue1 = new BattleUIEvent(BattleUIEvent.BATTLE_UI_PICK_GEAR); // bue1.msg = pick.GetPosition(); // EventSystem.Instance.PushEvent(bue1); // break; // case 3: //捡到金币; // BattleUIEvent bue2 = new BattleUIEvent(BattleUIEvent.BATTLE_UI_PICK_GOLD); // bue2.msg = pick.GetPosition(); // EventSystem.Instance.PushEvent(bue2); // break; //} int pickId = (int)ConfigManager.GetVal <int>(ConfigItemKey.ZOMBIE_PICK_ID); //Debug.LogError(pti.resID); if (pti.resID == pickId) { BattleUIEvent bue1 = new BattleUIEvent(BattleUIEvent.BATTLE_UI_ZOMBIE_PICK1); //bue1.msg = pick.GetPosition(); EventSystem.Instance.PushEvent(bue1); } }
internal override void TryAlt(ref Worker wr, int i, Cont <X> xK, Else xE) { var pk = xE.pk; if (0 == Pick.Claim(pk)) { Alt <X> xA; try { xA = Do(Randomizer.Next(ref wr.RandomLo, ref wr.RandomHi)); Pick.Unclaim(pk); } catch (Exception e) { Pick.PickClaimedAndSetNacks(ref wr, i, pk); xA = new AltFail <X>(e); } xA.TryAlt(ref wr, i, xK, xE); } }
internal override void TryAlt(ref Worker wr, int i, Cont <X> xK, Else xE) { Spin: var st = this.state; if (st > 0) { goto Done; } if (st < 0) { goto Spin; } if (0 != Interlocked.CompareExchange(ref this.state, -1, st)) { goto Spin; } var pk = xE.pk; TryPick: var stPk = Pick.TryPick(pk); if (stPk > 0) { goto AlreadyPicked; } if (stPk < 0) { goto TryPick; } this.state = 1; Pick.SetNacks(ref wr, i, pk); var x = this.value; this.value = default(X); Cont.Do(xK, ref wr, x); return; AlreadyPicked: st = 0; Done: xE.TryElse(ref wr, i); }
/// <summary> /// Creates a new <see cref="PickBranch"/> that waits for the given bookmark before running <paramref name="action"/>. /// </summary> /// <param name="pick"></param> /// <param name="bookmarkName"></param> /// <param name="action"></param> /// <returns></returns> public static Pick BranchWait(this Pick pick, InArgument <string> bookmarkName, Activity action) { if (pick == null) { throw new ArgumentNullException(nameof(pick)); } if (bookmarkName == null) { throw new ArgumentNullException(nameof(bookmarkName)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } return(pick.Branch(Wait(bookmarkName), action)); }
/// <summary> /// Creates a new <see cref="PickBranch"/> with the given <paramref name="trigger"/> and <paramref name="action"/>. /// </summary> /// <param name="pick"></param> /// <param name="trigger"></param> /// <param name="action"></param> /// <returns></returns> public static Pick Branch(this Pick pick, Func <Task> trigger, Func <Task> action) { if (pick == null) { throw new ArgumentNullException(nameof(pick)); } if (trigger == null) { throw new ArgumentNullException(nameof(trigger)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } return(pick.Branch(Invoke(trigger), Invoke(action))); }
private void Start() { var playerPrefab = Globals.Tools.ObjectPooling.Grab(PoolType.Player); #region Camera new CameraFollow(playerPrefab, 2); #endregion #region Audio new AudioSystem(clips, this); #endregion #region Player var pistol = new WeaponFeature(PoolType.Bullet, 20, .1f, 1); var rocket = new WeaponFeature(PoolType.Rocket, 15, .3f, 5); var weapons = new IWeapon[2]; weapons[(int)WeaponType.Pistol] = new Pistol(pistol); weapons[(int)WeaponType.RocketLauncher] = new RocketLauncher(rocket); var playerBehaviours = new IBehaviour[8]; playerBehaviours[0] = new GrowndCheck(); playerBehaviours[1] = new LookAt(); playerBehaviours[2] = new Move(2, 4); playerBehaviours[3] = new Duck(); playerBehaviours[4] = new Jump(18); playerBehaviours[5] = new Shoot(weapons); playerBehaviours[6] = new Stab(); playerBehaviours[7] = new Pick(); new Player(playerPrefab, playerBehaviours, this); #endregion #region Rewards var loot = new Loot(lootsContainer); #endregion Globals.Tools.Event.Fire(EventType.OnSFX, Globals.SoundEffects.MissionStart); // SFX }
static void SeedData() { using (var db = new DataContext()) { IList <Category> categories = null; IList <Person> people = null; if (db.Categories.Any() == false) { categories = Builder <Category> .CreateListOfSize(5).Build(); db.Categories.AddRange(categories); } if (db.People.Any() == false) { people = Builder <Person> .CreateListOfSize(5).Build(); db.People.AddRange(people); } if (db.Books.Any() == false) { if (categories == null) { categories = db.Categories.ToList(); } if (people == null) { people = db.People.ToList(); } var books = Builder <Book> .CreateListOfSize(10) .All() .With(b => b.Category = Pick <Category> .RandomItemFrom(categories)) .With(b => b.Authors = Pick <Person> .UniqueRandomList(With.Between(1).And(3).Elements).From(people)) .Build(); db.Books.AddRange(books); } db.SaveChanges(); } }
public void Consider(IReadOnlyList<Pick> previousPicks) { SuggestedPick = (Pick) new Random().Next(1, 4); }
protected override void Start() { base.Start(); //frame = GameObject.Find("Frame"); //backplate = GameObject.Find("Backplate"); player = GameObject.FindWithTag("Player").GetComponent<Pick>(); //PlaySound("intro_controls"); StartCoroutine(StartGame()); }
private void setImageForPick(Pick pick, Image image) { switch (pick) { case Pick.None: image.Source = new BitmapImage(); break; case Pick.Paper: image.Source = new BitmapImage(new Uri(@"/paper.png", UriKind.Relative)); break; case Pick.Rock: image.Source = new BitmapImage(new Uri(@"/rock.png", UriKind.Relative)); break; case Pick.Scissors: image.Source = new BitmapImage(new Uri(@"/scissors.png", UriKind.Relative)); break; } }