private void RehydrateHashTable() { saveObject.sushiObjects.Clear(); foreach (GameObject go in sushis) { Sushi sushi = new Sushi(); sushi.position = new SerializeVector3(go.transform.position.x, go.transform.position.y, go.transform.position.z); sushi.rotation = new SerializeQuaternion(go.transform.rotation.x, go.transform.rotation.y, go.transform.rotation.z, go.transform.rotation.w); sushi.sushiType = go.name; sushi.sauceType = go.GetComponent <Saucable>().sauce_type; saveObject.sushiObjects.Add(go.GetInstanceID(), sushi); } saveObject.sauceObjects.Clear(); foreach (GameObject go in saucebottles) { Saucebottle saucebottle = new Saucebottle(); saucebottle.position = go.transform.position; saucebottle.rotation = go.transform.rotation; saucebottle.sauceType = go.GetComponent <SauceType>().sauce_type; saveObject.sauceObjects.Add(go.GetInstanceID(), saucebottle); } }
public ActionResult AddNewItem(Sushi model, HttpPostedFileBase upload) { if (ModelState.IsValid) { if (upload != null) { // получаем имя файла string fileName = System.IO.Path.GetFileName(upload.FileName); // сохраняем файл в папку Files в проекте string Extention = System.IO.Path.GetExtension(upload.FileName); string NewFileName = Crypto.HashPassword(fileName); NewFileName = NewFileName.Remove(0, 20); NewFileName += Extention; NewFileName = NewFileName.Replace('/', 'w'); NewFileName = NewFileName.Replace('\\', 'a'); NewFileName = NewFileName.Replace('+', 't'); upload.SaveAs(Server.MapPath("~/Photos/" + NewFileName)); model.Photo = "/Photos/" + NewFileName; } DataBaseContext db = new DataBaseContext(); db.Sushis.Add(model); db.SaveChanges(); ModelState.AddModelError("add", "Товар добавлен"); return(RedirectToAction("AddNewItem", "AdminMenu")); } else { ModelState.AddModelError("add", "Ошбика ввода данных"); return(RedirectToAction("AddProduct", "AdminMenu")); } return(View()); }
public List <Sushi> GetSushi() { Logger.Logger.LoggerCreat("Project_minibot", "GetSushi", Logger.Logger.LogStatus.DEBUG, "Считывание данных всех объектов из базы данных"); List <Sushi> sushiList = new List <Sushi>(); SqlConnection connection = new SqlConnection(connectionString: _connection); SqlCommand command = new SqlCommand(cmdText: $"select * from Sushi", connection: connection); Sushi sushiGet = new Sushi(); connection.Open(); SqlDataReader reader = command.ExecuteReader(); using (reader) { while (reader.Read()) { sushiGet = new Sushi(); sushiGet.Number = (int)reader["number"]; sushiGet.Name = (string)reader[name : "name"]; if (!(reader[name : "price"] is DBNull)) { sushiGet.Price = (int)reader[name : "price"]; } else { Logger.Logger.LoggerCreat("Project_minibot.Database", "GetSushi", Logger.Logger.LogStatus.ERROR, "Пустая ссылка. Значение NULL"); throw new MyExceptionMessage(message: "Попытка использовать пустую ссылку"); } sushiList.Add(sushiGet); } } return(sushiList); }
public Sushi GetSushiNumber(int numberList) { Logger.Logger.LoggerCreat("Project_minibot", "GetSushiNumber", Logger.Logger.LogStatus.DEBUG, "Считывание данных объекта из базы данных"); SqlConnection connection = new SqlConnection(_connection); SqlCommand command = new SqlCommand($"select * from Sushi where Sushi.number={numberList}", connection); Sushi sushiGet = new Sushi(); connection.Open(); SqlDataReader reader = command.ExecuteReader(); using (reader) { while (reader.Read()) { sushiGet.Number = (int)reader["number"]; sushiGet.Name = (string)reader["name"]; if (!(reader[name : "price"] is DBNull)) { sushiGet.Price = (int)reader[name : "price"]; } else { Logger.Logger.LoggerCreat("Project_minibot", "GetSushiNumber", Logger.Logger.LogStatus.ERROR, "Пустая ссылка. Значение NULL"); throw new MyExceptionMessage(message: "Попытка использовать пустую ссылку"); } } } return(sushiGet); }
public void CreatSushi(Sushi sushi) { Logger.Logger.LoggerCreat("Project_minibot", "CreatSushi", Logger.Logger.LogStatus.DEBUG, "Создание объекта в базе данных"); string query = $"insert into Sushi values({sushi.Number},'{sushi.Name}',{sushi.Price})"; ConnectionAndCommand(query); }
private void UpdateObjects() { //update sushi positions foreach (GameObject sushi in sushis) { int instanceID = sushi.GetInstanceID(); Sushi temp = (Sushi)saveObject.sushiObjects[instanceID]; temp.position = sushi.transform.position; temp.rotation = sushi.transform.rotation; temp.sauceType = sushi.GetComponent <Saucable>().sauce_type; saveObject.sushiObjects[instanceID] = temp; } //update sauce positions foreach (GameObject saucebottle in saucebottles) { int instanceID = saucebottle.GetInstanceID(); Saucebottle temp = (Saucebottle)saveObject.sauceObjects[instanceID]; temp.position = saucebottle.transform.position; temp.rotation = saucebottle.transform.rotation; temp.sauceType = saucebottle.GetComponent <SauceType>().sauce_type; saveObject.sauceObjects[instanceID] = temp; } //update sauce dish GameObject dishTemp = GameObject.Find("SauceDish"); saveObject.dish.position = dishTemp.transform.position; saveObject.dish.rotation = dishTemp.transform.rotation; saveObject.dish.sauceType = dishTemp.GetComponentInChildren <Saucable>().sauce_type; }
//히트 처리. void OnCollisionEnter2D(Collision2D col) { Sushi sushi = m_sushiModel.GetComponent <Sushi>(); PlayerInfo info = PlayerInfo.GetInstance(); int ballId = col.gameObject.GetComponent <BallScript>().GetPlayerId(); m_life--; if (m_life <= 0) { // 스코어 가산. if (ballId == info.GetPlayerId()) { //자신의 스코어를 더합니다. GameObject score = GameObject.Find("PlayerScore"); score.GetComponent <UserScore>().PushScore(m_sushiType); } else { //상대 플레이어의 스코어를 더합니다. GameObject score = GameObject.Find("OpponentScore"); score.GetComponent <UserScore>().PushScore(m_sushiType); } // 자기자신을 제거. Destroy(gameObject); } //초밥 모델을 애니메이션 시킵니다. if (m_life == 1) { sushi.PlayAnimation(Sushi.AnimationType.jump); } }
static void Main(string[] args) { var burger = new Burger(); var sushi = new Sushi(); var pizza = new Pizza(); var foods = new FoodBase[] { burger, sushi, pizza }; foreach (var food in foods) { food.GetType(); food.Organic(); } //burger.GetType(); //burger.Organic(); //Console.WriteLine(); //sushi.GetType(); //sushi.Organic(); //Console.WriteLine(); //pizza.GetType(); //pizza.Organic(); //Console.WriteLine(); Console.ReadLine(); }
public override IEnumerable <object> Solve(TextReader inputStream) { var(sushiCount, length) = inputStream.ReadValue <int, long>(); var sushis = new Sushi[sushiCount]; for (int i = 0; i < sushis.Length; i++) { var(x, v) = inputStream.ReadValue <long, long>(); sushis[i] = new Sushi(x, v); } var clockwise = new long[sushis.Length + 1]; var clockwiseDoubled = new long[sushis.Length + 1]; var counterClockwise = new long[sushis.Length + 1]; var counterClockwiseDoubled = new long[sushis.Length + 1]; long cal = 0; for (int i = 0; i + 1 < clockwise.Length; i++) { cal += sushis[i].Calorie; clockwise[i + 1] = cal - sushis[i].Position; clockwiseDoubled[i + 1] = cal - sushis[i].Position * 2; } cal = 0; for (int i = 0; i + 1 < counterClockwise.Length; i++) { cal += sushis[^ (i + 1)].Calorie;
static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var n = long.Parse(inputs[0]); var k = long.Parse(inputs[1]); var list = new List <Sushi>(); for (var i = 0; i < n; i++) { var inputs1 = Console.ReadLine().Split(" "); var t = int.Parse(inputs1[0]); var d = int.Parse(inputs1[1]); var s = new Sushi() { t = t, d = d, }; list.Add(s); } list.Sort((a, b) => a.d - b.d); var result = 0; Console.WriteLine(result); }
public Sushi UpdateSushi(Sushi updatedSushi) { var entity = dbS.Attach(updatedSushi); entity.State = EntityState.Modified; return(updatedSushi); }
public ActionResult EditItem(int id) { DataBaseContext db = new DataBaseContext(); Sushi model = new Sushi(); model = db.Sushis .Where(m => m.SushiId == id) .FirstOrDefault(); List <string> _tempList = new List <string>(); _tempList.Add("СушиРрито"); _tempList.Add("Нигири"); _tempList.Add("Маки"); _tempList.Add("Гунканы"); SelectList _categoryList = new SelectList(_tempList, 0); for (int i = 0; i < _tempList.Count; i++) { if (model.Type == _tempList[i]) { _categoryList = new SelectList(_tempList, i); } } ViewBag._categoryList = _categoryList; return(View(model)); }
void Fill() { //build the available supply List <Sushi> supply_list = new List <Sushi>(); foreach (Sushi fish in inventory.Keys) { Debug.Log(fish.name + ": " + inventory[fish]); int how_many = Mathf.Min(fish.maxActive, inventory[fish]); for (int i = 0; i < how_many; i++) { supply_list.Add(fish); } } //subtract any that have already been placed foreach (Sushi fish in activeIngredients.Values) { if (fish != null) { supply_list.Remove(fish); } } //fill in randomly List <int> keys = new List <int>(activeIngredients.Keys); foreach (int key in keys) { //deactivate any that were selected metaNode.SpriteWithName("fill_" + key).gameObject.SetActive(false); if (activeIngredients[key] == null) { if (key == 5 && supply_list.IndexOf(rice) >= 0) { int which = supply_list.IndexOf(rice); Sushi fish = supply_list[which]; supply_list.RemoveAt(which); activeIngredients[key] = fish; metaNode.LabelWithName("label_" + key).text = fish.fish; metaNode.Get <SuperTab>("tab_sushi_" + key).currentState = fish.name; } else if (supply_list.Count > 0) { int which = Random.Range(0, supply_list.Count); Sushi fish = supply_list[which]; supply_list.RemoveAt(which); activeIngredients[key] = fish; metaNode.LabelWithName("label_" + key).text = fish.fish; metaNode.Get <SuperTab>("tab_sushi_" + key).currentState = fish.name; } else { metaNode.LabelWithName("label_" + key).text = "EMPTY"; metaNode.Get <SuperTab>("tab_sushi_" + key).currentState = "none"; } } } }
private void CreateNewSushi() { Sushi sushi = sushiTypes[Random.Range(0, sushiTypes.Count)]; orderedSushis.Add(sushi); newSushiEvent.Invoke(sushi); }
public override IEnumerable <object> Solve(TextReader inputStream) { const int Max = 2000001; (_, _) = inputStream.ReadValue <int, int>(); var sharis = inputStream.ReadIntArray(); var netas = inputStream.ReadIntArray(); var sushis = new Sushi[Max].SetAll(_ => new Sushi(-1, -1)); for (int shariIndex = 0; shariIndex < sharis.Length; shariIndex++) { for (int netaIndex = 0; netaIndex < netas.Length; netaIndex++) { var total = sharis[shariIndex] + netas[netaIndex]; if (sushis[total] != new Sushi(-1, -1)) { var(shari2, neta2) = sushis[total]; yield return($"{shari2} {neta2} {shariIndex} {netaIndex}"); yield break; } sushis[total] = new Sushi(shariIndex, netaIndex); } } yield return(-1); }
public ActionResult EditItem(Sushi model, HttpPostedFileBase upload) { if (upload != null) { // получаем имя файла string fileName = System.IO.Path.GetFileName(upload.FileName); // сохраняем файл в папку Files в проекте string Extention = System.IO.Path.GetExtension(upload.FileName); string NewFileName = Crypto.HashPassword(fileName); NewFileName = NewFileName.Remove(0, 20); NewFileName += Extention; NewFileName = NewFileName.Replace('/', 'w'); NewFileName = NewFileName.Replace('\\', 'a'); NewFileName = NewFileName.Replace('+', 't'); upload.SaveAs(Server.MapPath("~/Photos/" + NewFileName)); model.Photo = "/Photos/" + NewFileName; } DataBaseContext db = new DataBaseContext(); var EditProduct = db.Sushis .Where(m => m.SushiId == model.SushiId) .FirstOrDefault(); EditProduct.Name = model.Name; EditProduct.Price = model.Price; EditProduct.Type = model.Type; EditProduct.Colorie = model.Colorie; EditProduct.Composition = model.Composition; if (!String.IsNullOrEmpty(model.Photo)) { EditProduct.Photo = model.Photo; } db.SaveChanges(); return(RedirectToAction("Index")); }
public void AddTest() { CollectionOfShushi c = new CollectionOfShushi(); Sushi a = new Sushi("hz", 1, 1, "1"); c.Add(a); Assert.AreEqual(c.list.Count, 1); }
//Метод удаления блюдв public void DeleteDish() { if (SelectedDish != null) { Sushi.Remove(SelectedDish); SelectedDish = null; } }
public void UnfinishedSushi(Sushi sushi) { unfinishedSushis.Add(sushi); if (unfinishedSushis.Count == 3) { GameOver(); } }
public async Task <IActionResult> PageEditSushi(string Id) { Sushi sushi = db.GetSushi(int.Parse(Id)); return(View(new UpdateSushiModel { Name = sushi.Name, Category = sushi.Category, Description = sushi.Description, Price = sushi.Price, Id = sushi.Id })); }
public void ReadTest() { collection.Read(@"C:\Users\Home\Desktop\C#\WPF\Team_Aaa\Task3\Test\data.txt"); Sushi a = new Sushi("sushi", 1, 1, "1"); Assert.AreEqual(collection.list[0].ToString(), a.ToString()); a = new Sushi("AnotherSushi", 2, 2, "2"); Assert.AreEqual(collection.list[1].ToString(), a.ToString()); }
public RedirectToRouteResult RemoveFromCart(int productId, string returnUrl) { Sushi product = repository.Products .FirstOrDefault(g => g.SushiId == productId); if (product != null) { GetCart().RemoveLine(product); } return(RedirectToAction("Index", new { returnUrl })); }
private void FinishSushi(Sushi sushi) { if (!sushi.enabled) { return; } Digested.Invoke(sushi); _sushiPool.Despawn(_sushiQueue.Dequeue()); //_sushiPool.Despawn(sushi); }
void Purchase(Sushi fish) { if (cashMoney > fish.fishPrice) { cashMoney -= fish.fishPrice; inventory[fish] += fish.quantity; } //RefreshIngredients(); Fill(); Refresh(); }
void ExitRecipeView(Sushi sushi) { foreach (GameObject view in recipeViewList) { if (view != null && view.GetComponent <RecipeView>().Sushi.Equals(sushi)) { view.GetComponent <RecipeView>().ExitScene(); recipeViewList.Remove(view); return; } } }
public int SaveItem(Sushi item) { if (item.Id != 0) { database.Update(item); return(item.Id); } else { return(database.Insert(item)); } }
//Метод добавления блюда public void AddDish() { if (!string.IsNullOrEmpty(SelectedSushiType)) { if (SelectedSushiType.Equals("Унаги")) { if (!string.IsNullOrEmpty(SushiName)) { Sushi.Add(new Unagi(SushiName)); } else { Sushi.Add(new Unagi()); } } else if (SelectedSushiType.Equals("Радуга")) { if (!string.IsNullOrEmpty(SushiName)) { Sushi.Add(new Rainbow(SushiName)); } else { Sushi.Add(new Rainbow()); } } else if (SelectedSushiType.Equals("С Фугу")) { if (!string.IsNullOrEmpty(SushiName)) { Sushi.Add(new Fugu(SushiName)); } else { Sushi.Add(new Fugu()); } } else if (SelectedSushiType.Equals("Хотатэ")) { if (!string.IsNullOrEmpty(SushiName)) { Sushi.Add(new Hotate(SushiName)); } else { Sushi.Add(new Hotate()); } } } }
void AddRecipeView(Sushi sushi) { GameObject recipeViewObject = Instantiate( Resources.Load($"Sushi Recipe Views/{sushi.name} recipe view") as GameObject, transform.position, Quaternion.identity ); recipeViewObject.transform.SetParent(transform); recipeViewObject.transform.localPosition = new Vector3(-400, 0, 0); recipeViewObject.GetComponent <RecipeView>().EnterScene(); recipeViewObject.GetComponent <RecipeView>().SetSushi(sushi); recipeViewList.Add(recipeViewObject); }
public override IEnumerable <object> Solve(TextReader inputStream) { var nk = inputStream.ReadIntArray(); var sushis = new Sushi[nk[0]]; var canEat = nk[1]; for (int i = 0; i < sushis.Length; i++) { var td = inputStream.ReadIntArray(); sushis[i] = new Sushi(td[0], td[1]); } Array.Sort(sushis); Array.Reverse(sushis); var eatenSushiTypes = new HashSet <long>(); var duplicatedSushis = new PriorityQueue <Sushi>(false); long sum = 0; foreach (var sushi in sushis.Take(canEat)) { sum += sushi.Deliciousness; if (!eatenSushiTypes.Add(sushi.Type)) { duplicatedSushis.Enqueue(sushi); } } var valiousSushis = new Queue <Sushi>(sushis.Skip(canEat) .Where(s => !eatenSushiTypes.Contains(s.Type)) .GroupBy(s => s.Type, (t, s) => s.First())) .ToArray(); var points = new long[Math.Min(valiousSushis.Length, duplicatedSushis.Count) + 1]; points[0] = sum + (long)eatenSushiTypes.Count * eatenSushiTypes.Count; for (int i = 1; i < points.Length; i++) { var sushi = valiousSushis[i - 1]; var duplicatedSushi = duplicatedSushis.Dequeue(); long diff = sushi.Deliciousness - duplicatedSushi.Deliciousness; long variety = eatenSushiTypes.Count; points[i] = points[i - 1] + diff + (variety + 1) * (variety + 1) - (variety * variety); eatenSushiTypes.Add(sushi.Type); } yield return(points.Max()); }
public void GetListTest() { List <Sushi> l = new List <Sushi>(); collection.list.Clear(); collection.Read(@"C:\Users\Home\Desktop\C#\WPF\Team_Aaa\Task3\Test\data.txt"); Sushi a = new Sushi("sushi", 1, 1, "1"); l.Add(a); Sushi b = new Sushi("AnotherSushi", 2, 2, "2"); l.Add(b); Assert.AreEqual(l[0].ToString(), new Sushi("sushi", 1, 1, "1").ToString()); Assert.AreEqual(l[1].ToString(), new Sushi("AnotherSushi", 2, 2, "2").ToString()); }