public async Task <IHttpActionResult> Postpokemon(pokemon pokemon) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.pokemon.Add(pokemon); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (pokemonExists(pokemon.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = pokemon.Id }, pokemon)); }
/* Gets, populates, and returns a pokemon entity based on the name parameter * Throws exception "Pokemon not found." If pokemon does not exist. */ public pokemon GetPokemon(string name, Boolean useCache = true) { try { //let's get it from cache to avoid slamming the servers pokemon pokeObj = this.pokeCache[name]; return(pokeObj); } catch (KeyNotFoundException) { const string apiUrl = "http://pokeapi.co/api/v2/pokemon/"; string jsonResponse = Get(apiUrl + name); pokemon pokeObj = new pokemon(name); dynamic responseObj = JObject.Parse(jsonResponse); //assuming there will only ever be two types for each pokemon max foreach (var t in responseObj.types) { pokeObj.SetType((int)t.slot - 1, (string)t.type.name); } //get damage relation from type object PopulateDamageRelationships(pokeObj); pokeCache.Add(name, pokeObj); return(pokeObj); } }
public async Task <IHttpActionResult> Putpokemon(int id, pokemon pokemon) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pokemon.Id) { return(BadRequest()); } db.Entry(pokemon).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!pokemonExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private static void Main(string[] args) { pokemon pokemon = new pokemon(); Console.Write("請輸入姓名:"); pokemon.name = Console.ReadLine(); Console.Write("請輸入血量:"); pokemon.hp = Console.ReadLine(); Console.Write("請輸入性別:"); pokemon.gender = Console.ReadLine(); Console.Write("請輸入體重:"); pokemon.weight = Console.ReadLine(); Console.Write("請輸入屬性:"); pokemon.attribute = Console.ReadLine(); Console.Write("請輸入身高:"); pokemon.height = Console.ReadLine(); Console.Write("請輸入技能1:"); pokemon.skill1 = Console.ReadLine(); Console.Write("請輸入技能2:"); pokemon.skill2 = Console.ReadLine(); Console.WriteLine( "姓名:{0}, 血量:{1}, 性別:{2}, 體重:{3}, 屬性:{4}, 身高:{5}, " + "技能1:{6}, 技能2:{7}" , pokemon.name , pokemon.hp , pokemon.gender , pokemon.weight , pokemon.attribute , pokemon.height , pokemon.skill1 , pokemon.skill2 ); }
static void Main(string[] args) { pokemon poke1 = new pokemon(); pokemon poke2 = new pokemon(); poke1.Naam = "Bulbasaur"; poke1.HP_Base = 45; poke1.Attack_Base = 49; poke1.Defense_Base = 49; poke1.SpecialAttack_Base = 65; poke1.SpecialDefense_Base = 65; poke1.Speed_Base = 45; poke2.Naam = "Charmander"; poke2.HP_Base = 39; poke2.Attack_Base = 52; poke2.Defense_Base = 43; poke2.SpecialAttack_Base = 60; poke2.SpecialDefense_Base = 50; poke2.Speed_Base = 65; for (int i = 0; i < 5; i++) { poke2.Verhooglevel(); } /*Console.WriteLine($"Bulbasaur heeft een average:{poke1.Average} en een total van {poke1.Total}"); * Console.WriteLine($"Charmander is nu level {poke2.Level} en heeft een average:{poke2.Average} en een total van {poke2.Total} en full stat HP{poke2.HP_Full}");*/ poke2.ShowInfo(); }
public async Task <IHttpActionResult> Getpokemon(int id) { pokemon pokemon = await db.pokemon.FindAsync(id); if (pokemon == null) { return(NotFound()); } return(Ok(pokemon)); }
public async Task <IHttpActionResult> Deletepokemon(int id) { pokemon pokemon = await db.pokemon.FindAsync(id); if (pokemon == null) { return(NotFound()); } db.pokemon.Remove(pokemon); await db.SaveChangesAsync(); return(Ok(pokemon)); }
static void NiceOutput(pokemon pokeObj) { List <string> quad_damage_from = new List <string>(); List <string> doub_damage_from = new List <string>(); List <string> half_damage_from = new List <string>(); List <string> quar_damage_from = new List <string>(); List <string> no_damage_from = new List <string>(); foreach (var dr in pokeObj.GetDamageRelationships()) { switch (dr.Value) { case 0: no_damage_from.Add(dr.Key); break; case 0.25: quar_damage_from.Add(dr.Key); break; case 0.50: half_damage_from.Add(dr.Key); break; case 2: doub_damage_from.Add(dr.Key); break; case 4: quad_damage_from.Add(dr.Key); break; } } Console.Write("Pokemon " + pokeObj.GetName() + ". "); string[] types = pokeObj.GetTypes(); Console.Write("Type: " + types[0]); if (types[1] != null) { Console.Write("/" + types[1]); } Console.Write(Environment.NewLine); OutputDamageRatio(no_damage_from, "NO"); OutputDamageRatio(quar_damage_from, "0.25x"); OutputDamageRatio(half_damage_from, "0.5x"); OutputDamageRatio(doub_damage_from, "2x"); OutputDamageRatio(quad_damage_from, "4x"); Console.WriteLine(" Recieves normal damage from all other types."); }
public IActionResult Put([FromBody] pokemon updatepokemon) { pokemon orgpokemon = context.pokemons.Find(updatepokemon.ID); if (orgpokemon == null) { return(NotFound()); } orgpokemon.Name = updatepokemon.Name; orgpokemon.Type = updatepokemon.Type; context.SaveChanges(); return(Ok(orgpokemon)); }
/* Poplates the pokemon object's damage relationships based on the object's types * If types have not been set this will not add any relationships. */ private void PopulateDamageRelationships(pokemon pokeObj) { foreach (var t in pokeObj.GetTypes()) { if (t != null) { string typeJson = GetTypeJson(t); Dictionary <string, double> typeDict = ParseTypeJsonIntoDamageDict(typeJson); foreach (var td in typeDict) { pokeObj.AddDamageRelationship(td.Key, td.Value); } } } return; }
private static void Main(string[] args) { pokemon pokemon = new pokemon() { name = "妙蛙種子", hp = "60", gender = "男", weight = "5.94kg", attribute = "草/毒", height = "0.67m", star = "271484", candy = "27", powerup = "3000星星+3糖果", evolve = "25糖果", skill1 = "藤鞭", skill1dmg = "7", skill2 = "汙泥炸彈", skill2dmg = "80", location = "台灣,新北市三重區", date = "9/14/2016", }; Console.WriteLine("名稱:{0}, 血量:{1}, 性別:{2}, 體重:{3}, 屬性:{4}, 身高:{5}," + "星星沙子:{6}, 妙蛙種子的糖果:{7}, 強化:{8}, 進化:{9}, 技能1:{10}, " + "技能1攻擊力:{11}, 技能2:{12}, 技能2攻擊力:{13}, 捕捉地點:{14}, 捕捉日期:{15}" , pokemon.name , pokemon.hp , pokemon.gender , pokemon.weight , pokemon.attribute , pokemon.height , pokemon.star , pokemon.candy , pokemon.powerup , pokemon.evolve , pokemon.skill1 , pokemon.skill1dmg , pokemon.skill2 , pokemon.skill2dmg , pokemon.location , pokemon.date ); }
static void Main(string[] args) { RestClient client = new RestClient("https://pokeapi.co/api/v2/"); RestRequest request = new RestRequest("pokemon/totodile"); request.AddParameter("uid", "ANMA0000032338"); IRestResponse response = client.Get(request); //string content = response.Content; //System.Console.WriteLine(content); pokemon totodile = JsonConvert.DeserializeObject <pokemon>(response.Content); Console.WriteLine(totodile.weight); Console.ReadLine(); }
static void Main(string[] args) { PokeService pokeService = new PokeService(); bool quit = false; while (quit != true) { string pokeName = ""; Console.WriteLine("Type a pokemon name or type quit to quit."); pokeName = Console.ReadLine(); pokeName = pokeName.Trim().ToLower().Replace(".", "").Replace(" ", "-"); if (pokeName != "quit") { if (pokeName == "") { continue; } try { pokemon pokeObj = pokeService.GetPokemon(pokeName, true); NiceOutput(pokeObj); } catch (Exception e) when(e.Message == "Pokemon not found.") { Console.WriteLine(e.Message); continue; } } else { quit = true; } } }
public void Post([FromBody] pokemon newpokemon) { context.pokemons.Add(newpokemon); context.SaveChanges(); }
public static void Main() { string[] input = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Dictionary <string, Person> persons = new Dictionary <string, Person>(); while (input[0] != "End") { if (!persons.ContainsKey(input[0])) { Person current = new Person(); current.name = input[0]; persons.Add(input[0], current); } switch (input[1]) { case "company": company comp = new company(); comp.name = input[2]; comp.department = input[3]; comp.salary = double.Parse(input[4]); persons[input[0]].Company = comp; break; case "pokemon": pokemon poke = new pokemon(); poke.name = input[2]; poke.type = input[3]; persons[input[0]].Pokemons.Add(poke); break; case "parents": parents parent = new parents(); parent.name = input[2]; parent.birthday = input[3]; persons[input[0]].Parents.Add(parent); break; case "children": children child = new children(); child.name = input[2]; child.birthday = input[3]; persons[input[0]].Children.Add(child); break; case "car": car car = new car(); car.model = input[2]; car.speed = input[3]; persons[input[0]].Car = car; break; } input = Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); } string person = Console.ReadLine(); var pers = persons.Where(x => x.Key == person).ToList(); foreach (var one in pers) { Console.WriteLine(one.Value.name); Console.WriteLine("Company:"); if (one.Value.Company != null) { Console.WriteLine($"{one.Value.Company.name} {one.Value.Company.department} {one.Value.Company.salary:f2}"); } Console.WriteLine("Car:"); if (one.Value.Car != null) { Console.WriteLine($"{one.Value.Car.model} {one.Value.Car.speed}"); } Console.WriteLine("Pokemon:"); if (one.Value.Pokemons != null) { foreach (var pokemon in one.Value.Pokemons) { Console.WriteLine($"{pokemon.name} {pokemon.type}"); } } Console.WriteLine("Parents:"); if (one.Value.Parents != null) { foreach (var parent in one.Value.Parents) { Console.WriteLine($"{parent.name} {parent.birthday}"); } } Console.WriteLine("Children:"); if (one.Value.Children != null) { foreach (var child in one.Value.Children) { Console.WriteLine($"{child.name} {child.birthday}"); } } } }
//Generate the Pokemon based on ID (pokedex) number and suffix public pokemon generatePokemon(string id) { bool isShiny = false; bool isFemale = false; if (rng.Next(0, shinyChance) + 1 == 1) { isShiny = true; } if (rng.Next(0, 110) + 1 < femaleChance) { isFemale = true; } else { isFemale = false; } //Default base stats = 50, 50, 50, 50, 50, 50 newPokemon = new pokemon(); switch (id) { case "1": newPokemon.setStats("Bulbasaur", 10, tackle, leer, NONE, NONE, isShiny, int.Parse(id), "", tackle.PP, growl.PP, NONE.PP, NONE.PP, isFemale, false); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "grass", "blank"); break; case "4": newPokemon.setStats("Charmander", 10, scratch, growl, NONE, NONE, isShiny, int.Parse(id), "", scratch.PP, growl.PP, NONE.PP, NONE.PP, isFemale, false); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "fire", "blank"); break; case "7": newPokemon.setStats("Squirtle", 10, tackle, tailWhip, poisonPowder, stunPowder, isShiny, int.Parse(id), "", tackle.PP, tailWhip.PP, NONE.PP, NONE.PP, isFemale, false); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "water", "blank"); break; case "16": newPokemon.setStats("Pidgey", 10, gust, sandAttack, NONE, NONE, isShiny, int.Parse(id), "", gust.PP, sandAttack.PP, NONE.PP, NONE.PP, isFemale, false); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "flying", "blank"); break; case "19": newPokemon.setStats("Rattata", 10, tackle, tailWhip, NONE, NONE, isShiny, int.Parse(id), "", tackle.PP, tailWhip.PP, NONE.PP, NONE.PP, isFemale, true); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "normal", "blank"); break; case "25": newPokemon.setStats("Pikachu", 10, tackle, tailWhip, NONE, NONE, isShiny, int.Parse(id), "", tackle.PP, tailWhip.PP, NONE.PP, NONE.PP, isFemale, true); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "electric", "blank"); break; case "69": newPokemon.setStats("Bellsprout", 10, vineWhip, NONE, NONE, NONE, isShiny, int.Parse(id), "", tackle.PP, tailWhip.PP, NONE.PP, NONE.PP, isFemale, false); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "grass", "blank"); break; default: newPokemon.setStats("MissingNo", 10, NONE, NONE, NONE, NONE, false, 0, "", tackle.PP, growl.PP, NONE.PP, NONE.PP, isFemale, false); newPokemon.setAttrib(50, 50, 50, 50, 50, 50, "normal", "blank", "blank"); break; } //Default affinities to 5000 for (int x = 0; x < 18; x++) { newPokemon.attackAffinity[x] = 5000; newPokemon.defenseAffinity[x] = 5000; } //Function to adjust affinity based on location adjustAffinityByType(); //Function to adjust the affinities based on pokemon type adjustDifficulty(); //Function to adjust base states based on difficulty return(newPokemon); }