static void Main(string[] args) { Console.WriteLine("Welcome to C#"); var riddler = new Cat(); riddler.Name = "Riddler"; riddler.Breed = "House Cat"; riddler.Speak(); var amit = new Camel(); amit.Speak(); var adley = new Dog(); var farm = new List <Pet>(); farm.Add(riddler); farm.Add(amit); farm.Add(adley); foreach (var vanana in farm) { vanana.Speak(); } }
public static int getPosition(string s) { GameObject g = GameObject.Find(s); Camel c = (Camel)g.GetComponent(typeof(Camel)); return(c.getPos()); }
public IActionResult UpdateCamel(int CamelId, Camel FromForm) { // Now we need to check the submitted model for errors if (ModelState.IsValid) { // And this is the fancy new update method! // Apply the camel id from the route to the object FromForm.CamelId = CamelId; // Then, run the update method dbContext.Update(FromForm); // Now, we need to remove the modified flag on the CreatedAt // property, so Entity doesn't try to overwrite the CreatedAt method dbContext.Entry(FromForm).Property("CreatedAt").IsModified = false; // And finally, save the changes in our actual database. dbContext.SaveChanges(); return(RedirectToAction("AllCamels")); } else { return(EditCamel(CamelId)); } }
public static int MovePiece(Camel camel, int spaces) { int finalPos = camel.position + spaces; bool gameOver = false; if (finalPos > MAX_SPACES - 1) { gameOver = true; finalPos = MAX_SPACES - 1; } bool trapBackward = false; var trap = mBoardPositions[finalPos].OfType <Trap>().ToList(); if (trap.Count > 0 && trap[0] != null) { if (trap[0].positionModifier < 0) { trapBackward = true; } finalPos += trap[0].positionModifier; trap[0].owner.ChangeCoins(trap[0].actionCoinValue); List <string> message = new List <string> { "Camel ", camel.name, $" got caught in {trap[0].owner.name} trap. His position now is {finalPos}." }; List <ConsoleColor> colors = new List <ConsoleColor> { ConsoleColor.Black, ColorUtils.GetConsoleColor(camel.color), ConsoleColor.Black }; ConsoleManager.PrintColored(message, colors); } var stack = GetCamelStack(camel); mBoardPositions[camel.position].Remove(camel); mBoardPositions[finalPos].Insert(trapBackward ? 0 : mBoardPositions[finalPos].Count, camel); for (int i = 0; i < stack.Count; i++) { mBoardPositions[camel.position].Remove(stack[i]); stack[i].position = finalPos; mBoardPositions[finalPos].Insert(mBoardPositions[finalPos].Count, stack[i]); } if (gameOver) { TurnManager.EndGame(camel); } return(finalPos); }
public async Task <ActionResult> DeleteConfirmed(int id) { Camel camel = await db.Camels.FindAsync(id); db.Camels.Remove(camel); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
private static void CreateCamels() { var camelColors = Enum.GetValues(typeof(CamelColors)); foreach (CamelColors c in camelColors) { Camel camel = new Camel(c); mCamels.Add(camel); } }
public void CamelMoveAreEqual() { string constResult = "Верблюд идёт по пескам пустыни"; IAnimal animal = new Camel(); string result; result = animal.Move(); Assert.AreEqual(constResult, result); }
public ViewResult EditCamel(int CamelId) { // Using our tag helpers makes Editing super easy! // All we need to do is pull the camel we want to edit // from our database, then send it to the cshtml page! Camel ToEdit = dbContext.Camels .FirstOrDefault(camel => camel.CamelId == CamelId); return(View("EditCamel", ToEdit)); }
public static void Start() { var auto = new Auto(); Driver.Travel(auto); IAnimal camel = new Camel(); ITransport camelTransport = new CamelToTransportAdapter(camel); Driver.Travel(camelTransport); }
public void DriverTravelCamelIsNotModified() { IAnimal animal = new Camel(); string constResult = animal.Move(); AnimalToTransportAdapter animalToTransportAdapter = new AnimalToTransportAdapter(animal); string result; result = A_Example.Instance.Main(animalToTransportAdapter); Assert.AreEqual(constResult, result); }
static void test_covariance() { Stack <Bear> bears = new Stack <Bear>(); ZooCleaner.Wash(bears); //Stack<Animal> animals = bears; // Compile-time error Bear[] bears2 = new Bear[3]; Animal[] animals = bears2; // OK animals[0] = new Camel(); // Runtime error }
public override void Run() { var driver = new Driver(); var car = new Car(); driver.Travel(car); var camel = new Camel(); var adapter = new AnimalTransportAdapter(camel); driver.Travel(adapter); }
public void AnimalToTransportAdapterIsNotModified() { IAnimal animal = new Camel(); string constResult = animal.Move(); string result; AnimalToTransportAdapter animalToTransportAdapter = new AnimalToTransportAdapter(animal); result = animalToTransportAdapter.Drive(); Assert.AreEqual(constResult, result); }
public static void addCamel(string toAdd, int pos) { GameObject g = GameObject.Find(toAdd); Camel c = (Camel)g.GetComponent(typeof(Camel)); int toRem = c.getPos(); if ((spaces[toRem].getCamelOnSpaces()).Contains(toAdd)) { spaces [toRem].removeCamel(toAdd); } spaces [pos].addCamel(toAdd); c.updatePos(pos); }
public RedirectToActionResult DeleteCamel(int CamelId) { // Deleting from the database is, logically, simple. // We need to pull the object from our database Camel ToDelete = dbContext.Camels .FirstOrDefault(camel => camel.CamelId == CamelId); // Then delete it from the local context of our database dbContext.Remove(ToDelete); // And save the changes, which will push the changes to // the actual database itself. dbContext.SaveChanges(); return(RedirectToAction("AllCamels")); }
public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Camel camel = await db.Camels.FindAsync(id); if (camel == null) { return(HttpNotFound()); } return(View(camel)); }
public Form1() { InitializeComponent(); driver = new Driver(); auto = new Auto(); camel = new Camel(); airplane = new Airplane(); transportTypeList = new List <string>(); transportTypeList.Add(auto.Name); transportTypeList.Add(camel.Name); transportTypeList.Add(airplane.Name); comboBox1.Text = transportTypeList[0]; comboBox1.Items.AddRange(transportTypeList.ToArray()); }
static void Main(string[] args) { // adventurer Driver driver = new Driver(); Auto auto = new Auto(); driver.Travel(auto); Camel camel = new Camel(); // use adapter ITransport camelTransport = new CamelToTransportAdapter(camel); driver.Travel(camelTransport); Console.Read(); }
private void AdapterReal() { Driver driver = new Driver(); Auto auto = new Auto(); Ship ship = new Ship(); driver.Travel(auto); driver.Travel(ship); Camel camel = new Camel(); ITransport camelTrasport = new CamelToTransportAdapter(camel); driver.Travel(camelTrasport); Console.ReadKey(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { // путешественник Driver driver = new Driver(); // машина Auto auto = new Auto(); // отправляемся в путешествие driver.Travel(auto); // встретились пески, надо использовать верблюда Camel camel = new Camel(); // используем адаптер ITransport camelTransport = new CamelToTransportAdapter(camel); // продолжаем путь по пескам пустыни driver.Travel(camelTransport); }
public static void Display() { // путешественник Driver driver = new Driver(); // машина Auto auto = new Auto(); // отправляемся в путешествие driver.Travel(auto); // встретились пески, надо использовать верблюда Camel camel = new Camel(); // используем адаптер ITransport camelTransport = new CamelToTransportAdapter(camel); // продолжаем путь по пескам пустыни driver.Travel(camelTransport); }
// Update is called once per frame void Update() { if (stopped == false) { if (stoppedMoving()) { stopped = true; int val = getSideUp(); GameObject g = GameObject.Find(color + "_camel"); Camel c = (Camel)g.GetComponent(typeof(Camel)); Debug.Log(c.getId() + " rolls " + val); c.moveSpaces(val); GameController.diceSettled = true; } } }
public async Task <ActionResult> Create([Bind(Include = "Id,Code,Breed,Weight,SlaughterYield,EwesYield,TotalGoals,MilkFatContent,Range,Description")] Camel camel, HttpPostedFileBase Photo) { if (ModelState.IsValid) { if (Photo != null) { MemoryStream target = new MemoryStream(); Photo.InputStream.CopyTo(target); camel.Photo = target.ToArray(); } db.Camels.Add(camel); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(camel)); }
public async Task <IActionResult> Create([Bind("Id,Code,BreedRU,BreedKK,BreedEN,WeightRU,WeightKK,WeightEN,SlaughterYield,EwesYieldRU,EwesYieldKK,EwesYieldEN,TotalGoals,MilkFatContent,RangeRU,RangeKK,RangeEN,FormFile,DescriptionRU,DescriptionKK,DescriptionEN")] Camel camel) { if (ModelState.IsValid) { using (var memoryStream = new MemoryStream()) { await camel.FormFile.CopyToAsync(memoryStream); camel.Photo = memoryStream.ToArray(); } _context.Add(camel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(camel)); }
private static List <Camel> GetCamelStack(Camel camel) { List <Camel> toReturn = new List <Camel>(); if (camel.position == 0) { return(toReturn); } int index = mBoardPositions[camel.position].IndexOf(camel) + 1; for (int i = index; i < mBoardPositions[camel.position].Count; i++) { toReturn.Add(mBoardPositions[camel.position][i] as Camel); } return(toReturn); }
public void moveBlock(int newPos) { Vector3 nextPosition = Board.spaces[this.currentPosition].getPosition(); List <string> startingSpace = Board.spaces[this.currentPosition].getCamelOnSpaces(); int camelStackPos = startingSpace.IndexOf(this.id + "_camel"); List <string> blockToMove = startingSpace.GetRange(camelStackPos, startingSpace.Count - camelStackPos); Board.spaces[this.currentPosition].removeRange(camelStackPos, startingSpace.Count - camelStackPos); foreach (string s in blockToMove) { Board.addCamel(s, newPos); } Camel.stackCamels(); }
private static void ShowAdapter() { Console.WriteLine("================================================"); Console.WriteLine("Pattern code (Adapter):"); Target target = new Adapter(); target.Request(); Console.WriteLine("\nReal code (Adapter):"); Driver driver = new Driver(); Auto auto = new Auto(); driver.Travel(auto); Camel camel = new Camel(); ITransport camelTransport = new CamelToTransportAdapter(camel); driver.Travel(camelTransport); }
public AllCamels() { blue = new Camel("Blue"); white = new Camel("White"); orange = new Camel("Orange"); yellow = new Camel("Yellow"); green = new Camel("Green"); camels = new List<Camel>(); camels.Add(blue); camels.Add(white); camels.Add(orange); camels.Add(yellow); camels.Add(green); allTraps = new List<Trap>(); }
public static void setUpBoard() { int count = 0; //set up count for (int i = 4; i <= 12; i += 4) { spaces [count] = new BoardSpace((new Vector3(i, 0.5f, 3)), count); count++; } for (int i = -1; i >= -13; i += -4) { spaces [count] = new BoardSpace((new Vector3(12, 0.5f, i)), count); count++; } for (int i = 8; i >= -4; i -= 4) { spaces [count] = new BoardSpace((new Vector3(i, 0.5f, -13)), count); count++; } for (int i = -9; i <= 3; i += 4) { spaces [count] = new BoardSpace(new Vector3(-4, 0.5f, i), count); count++; } spaces [15] = new BoardSpace(new Vector3(0, 0.5f, 3), count); List <string> camels = new List <string> { "green_camel", "yellow_camel", "orange_camel", "white_camel", "blue_camel" }; for (int i = 0; i < 5; i++) { int index = Random.Range(0, camels.Count); addCamel(camels [index], Random.Range(0, 2)); camels.Remove(camels [index]); } Camel.stackCamels(); }
public ActionResult GetBreedInfo( string Code) { int code = Convert.ToInt32(Code); if (code > 400) { SmallCattle smallcattle = _context.SmallCattle.FirstOrDefault(s => s.Code == code); smallcattle.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(smallcattle.Photo)); return(Json(new { smallcattle })); } else if (code > 300) { Horse horse = _context.Horse.FirstOrDefault(h => h.Code == code); horse.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(horse.Photo)); return(Json(new { horse })); } else if (code > 200) { Cattle cattle = _context.Cattle.FirstOrDefault(c => c.Code == code); cattle.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(cattle.Photo)); return(Json(new { cattle })); } else { Camel camel = _context.Camel.FirstOrDefault(c => c.Code == code); camel.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(camel.Photo)); return(Json(new { camel })); } }
public static LegBet GetLegBetCard(Camel camel) { var cList = mLegBet.Where(x => x.camel.name.Equals(camel.name)).ToList(); if (cList.Count == 0) { return(null); } LegBet bestCard = cList[0]; for (int i = 1; i < cList.Count; i++) { if (cList[i].rewards[0] > bestCard.rewards[0]) { bestCard = cList[i]; } } return(bestCard); }
public Pattern(string myName) { name = myName; camel1 = new Camel(); camel2 = new Camel(); camel3 = new Camel(); camel4 = new Camel(); camel5 = new Camel(); camel1.name = "1"; camel2.name = "2"; camel3.name = "3"; camel4.name = "4"; camel5.name = "5"; camels = new List<Camel>(); camels.Add(camel1); camels.Add(camel2); camels.Add(camel3); camels.Add(camel4); camels.Add(camel5); }
public List<Camel> SortCamelInOrderPos() { List<Camel> newList = new List<Camel>(); List<Camel> remainingCamels = new List<Camel>(GetCamels()); for (int j = 0; j < GetCamels().Count; j++) { string tempCamelName = "TempCamel"; Camel higherCamel = new Camel(tempCamelName); higherCamel.pos = 0; for (int i = 0; i < remainingCamels.Count; i++) { Camel currentCamel = remainingCamels[i]; if(newList.Count > 0 && currentCamel.camelOnTop == newList[newList.Count - 1]) { //prend le camelOnTop du dernier camel entrer higherCamel = currentCamel; break; } else { //Prend le plus grosse pos + sans camel on top if (currentCamel.camelOnTop == null && currentCamel.pos > higherCamel.pos) { higherCamel = currentCamel; } } } for(int k = 0; k < remainingCamels.Count; k++) { if (remainingCamels[k].name == higherCamel.name) remainingCamels.Remove(remainingCamels[k]); } if (higherCamel.name == tempCamelName) { UnityEngine.Debug.LogError("Didnt find higherCamel"); } newList.Add(higherCamel); } if(remainingCamels.Count != 0) { UnityEngine.Debug.LogError("We miss a Camel"); } return newList; }
private void DoTrap(Trap trap, Camel camel) { //Debug.Log(string.Format("Camel {0} land on trap {1}", camel.name, trap.isPlusTrap ? "+" : "-")); if(trap.isPlusTrap) { MoveCamel(camel.name, 1); } else { MoveCamelUnder(camel.name); } }
private bool IsLandingOnTrap(Camel camel) { foreach(var trap in allTraps) { if(trap.pos == camel.pos) { DoTrap(trap, camel); return true; } } return false; }
public Camel(string camelName, int pos, bool isDiceRoll, Camel camelOnTop) : this(camelName) { this.pos = pos; this.isDiceRoll = isDiceRoll; this.camelOnTop = camelOnTop; }
public Camel(Camel oldCamel) { name = oldCamel.name; pos = oldCamel.pos; isDiceRoll = oldCamel.isDiceRoll; }
public AllCamels(string board) { blue = new Camel("Blue"); white = new Camel("White"); orange = new Camel("Orange"); yellow = new Camel("Yellow"); green = new Camel("Green"); camels = new List<Camel>(); camels.Add(blue); camels.Add(white); camels.Add(orange); camels.Add(yellow); camels.Add(green); allTraps = new List<Trap>(); //Parse board string[] subBoard = board.Split(';'); for (int pos = 0; pos < subBoard.Length; pos++) { Camel lastCamel = null; string line = subBoard[pos]; for (int j = line.Length - 1; j >= 0; j--) { if (line[j] == '+' || line[j] == '-') { this.allTraps.Add(new Trap(line[j], pos)); } else { Camel camel = GetCamel(line[j]); camel.name = FindCamelName(line[j]); camel.pos = pos; camel.isDiceRoll = char.IsLower(line[j]); camel.camelOnTop = lastCamel; lastCamel = camel; } } } }
public Stream(Camel.Stream sub) { substream = sub; }
public void writeToStream(Camel.Stream stream) { int res; res = camel_data_wrapper_write_to_stream(cobject, stream.cobject); if (res == -1) throw new Exception(Exception.Type.SYSTEM, "IO Error"); }
public AllCamels(List<Camel> originalCamels, List<Trap> myTraps) { blue = new Camel("Blue"); white = new Camel("White"); orange = new Camel("Orange"); yellow = new Camel("Yellow"); green = new Camel("Green"); camels = new List<Camel>(); camels.Add(blue); camels.Add(white); camels.Add(orange); camels.Add(yellow); camels.Add(green); allTraps = new List<Trap>(myTraps); foreach (Camel originalCamel in originalCamels) { Camel camel = GetCamel(originalCamel.name); camel.pos = originalCamel.pos; camel.isDiceRoll = originalCamel.isDiceRoll; if (originalCamel.camelOnTop != null) { camel.camelOnTop = GetCamel(originalCamel.camelOnTop.name); } } }
public AllCamels(AllCamels originalCamels) { blue = new Camel(originalCamels.blue); white = new Camel(originalCamels.white); orange = new Camel(originalCamels.orange); yellow = new Camel(originalCamels.yellow); green = new Camel(originalCamels.green); camels = new List<Camel>(); camels.Add(blue); camels.Add(white); camels.Add(orange); camels.Add(yellow); camels.Add(green); allTraps = new List<Trap>(originalCamels.allTraps); orderedCamelsForDice = new List<Camel>(); if(originalCamels.orderedCamelsForDice != null) { foreach (var myCamel in originalCamels.orderedCamelsForDice) { orderedCamelsForDice.Add(GetCamel(myCamel.name)); } } for(int i = 0; i < originalCamels.GetCamels().Count; i++) { Camel originalCamel = originalCamels.GetCamel (i); if(originalCamel.camelOnTop != null) { Camel camel = GetCamel(originalCamel.name); camel.camelOnTop = GetCamel(originalCamel.camelOnTop.name); } } }
public void constructFromStream(Camel.Stream stream) { int res; res = camel_data_wrapper_construct_from_stream(cobject, stream.cobject); if (res == -1) throw new Exception(Exception.Type.SYSTEM, "IO Error"); }