Commit d6093703 authored by julescournut's avatar julescournut
Browse files

Update game engine

parents 219c65ec b9451eb1
......@@ -292,7 +292,7 @@ namespace DataAccessLayer
War war = getWarById(id_war);
int id_territory = Convert.ToInt32(fightRow["id_territory"]);
Territory territory = getTerritoryById(id_territory);
res = new Fight(fightRow["name"].ToString(), house1, house2, (id_winner == house1.ID) ? house1 : house2, war, territory);
res = new Fight(id, fightRow["name"].ToString(), house1, house2, (id_winner == house1.ID) ? house1 : house2, war, territory);
}
catch (Exception e)
{
......
No preview for this file type
No preview for this file type
......@@ -21,13 +21,31 @@ namespace EntitiesLayer
Name = name;
Challenger1 = challenger1;
Challenger2 = challenger2;
if(challenger1.NbUnits > challenger2.NbUnits)
double prob;
Random rnd = new Random();
if (challenger1.NbUnits > challenger2.NbUnits)
{
Winner = challenger1;
prob = (double)challenger2.NbUnits / (double)challenger1.NbUnits;
if (rnd.NextDouble() <= prob)
{
Winner = challenger2;
}
else
{
Winner = challenger1;
}
}
else
{
Winner = challenger2;
prob = challenger1.NbUnits / challenger2.NbUnits;
if (rnd.NextDouble() <= prob)
{
Winner = challenger1;
}
else
{
Winner = challenger2;
}
}
War = war;
Territory = territory;
......
......@@ -36,9 +36,24 @@ namespace MVC.Controllers
}
// GET: Fght/Details/1
public ActionResult Details(int id)
public async Task<ActionResult> Details(int id)
{
return View();
FightModels fight = new FightModels();
IEnumerable<FightModels> relationships = new List<FightModels>();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/Fight/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
fight = JsonConvert.DeserializeObject<FightModels>(temp);
}
}
return View(fight);
}
// GET: Fght/Create
......@@ -163,6 +178,8 @@ namespace MVC.Controllers
}
}
FightModels Fight = new FightModels();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
......@@ -172,8 +189,14 @@ namespace MVC.Controllers
String jsonString = JsonConvert.SerializeObject(fight);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/fight", content);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
Fight = JsonConvert.DeserializeObject<FightModels>(temp);
}
}
return RedirectToAction("Index");
return RedirectToAction("Details/"+ Fight.ID);
}
// GET: Fight/Edit/1
......
......@@ -39,6 +39,7 @@ namespace MVC.Controllers
public async Task<ActionResult> Details(int id)
{
IEnumerable<FightModels> fights = new List<FightModels>();
IEnumerable<FightModels> Fi = new List<FightModels>();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
......@@ -52,8 +53,9 @@ namespace MVC.Controllers
fights = JsonConvert.DeserializeObject<List<FightModels>>(temp);
}
}
Fi = fights.Where(c => c.War.ID==id).ToList();
ViewBag.Title = (fights.Count() == 0) ? "No Fights for this War" : "All Fights for " + fights.First().War.Name;
return View(fights);
return View(Fi);
}
// GET: War/Create
......
......@@ -300,6 +300,7 @@
<Content Include="Views\Territory\Edit.cshtml" />
<Content Include="Views\Territory\Create.cshtml" />
<Content Include="Views\Territory\Delete.cshtml" />
<Content Include="Views\Fight\Details.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
......
......@@ -53,18 +53,6 @@
<dd>
@Html.DisplayFor(model => model.Characteristics.Type)
</dd>
<dt>
@Html.DisplayNameFor(model => model.RelationShips)
</dt>
@foreach (var rel in Model.RelationShips) {
<dd>
@Html.DisplayFor(model => rel.CharacterID)
</dd>
<dd>
@Html.DisplayFor(model => rel.Type)
</dd>
}
</dl>
</div>
<p>
......
@model MVC.Models.FightModels
@{
ViewBag.Title = "Create";
ViewBag.Title = "Create Fight";
}
<h2>Create</h2>
<h2>@ViewBag.Title</h2>
@using (Html.BeginForm())
......@@ -57,11 +57,12 @@
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Fight !" class="btn btn-primary" />
</div>
</div>
</div>
</div>
}
......
@model MVC.Models.FightModels
@{
ViewBag.Title = "Details";
}
<div>
<dl class="dl-horizontal">
<hr/>
<h2> <dt>@Html.DisplayNameFor(model => model.Winner) </dt><h2/>
<h2> <dd> @Html.DisplayFor(model => model.Winner.Name) </dd><h2/>
<hr/>
</dl>
</div>
<p>
@Html.ActionLink("Back to List", "Index")
</p>
......@@ -3,12 +3,12 @@
@{
ViewBag.Title = "All Fights";
}
<h2>@ViewBag.Title</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<br /><br />
<h1>
@Html.ActionLink("Jouer", "Create")
</h1>
<br /><br />
<h4>@ViewBag.Title</h4>
<table class="table">
<tr>
<th>
......
......@@ -3,29 +3,5 @@
}
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>
<div class="row">
<div class="col-md-4">
<h2>Getting started</h2>
<p>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
enables a clean separation of concerns and gives you full control over markup
for enjoyable, agile development.
</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Web Hosting</h2>
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
<p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
</div>
<h1><a href="http://localhost:5962/Fight" class="btn btn-primary btn-lg">Commencer</a></h1>
</div>
\ No newline at end of file
......@@ -22,10 +22,10 @@
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Character", "Index", "Character")</li>
<li>@Html.ActionLink("House", "Index", "House")</li>
<li>@Html.ActionLink("Fight", "Index", "Fight")</li>
<li>@Html.ActionLink("War", "Index", "War")</li>
<li>@Html.ActionLink("Character", "Index", "Character")</li>
<li>@Html.ActionLink("House", "Index", "House")</li>
<li>@Html.ActionLink("Territory", "Index", "Territory")</li>
</ul>
<!-- Html.Partial("_LoginPartial")-->
......
......@@ -17,7 +17,6 @@ namespace WebApiGOT.Controllers
{
List<FightDTO> list = new List<FightDTO>();
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
foreach (EntitiesLayer.Fight fight in busi.FightsList())
{
list.Add(new FightDTO(fight));
......@@ -29,7 +28,6 @@ namespace WebApiGOT.Controllers
public FightDTO Get(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
return new FightDTO(busi.getFightById(id));
}
......@@ -47,14 +45,16 @@ namespace WebApiGOT.Controllers
}
// POST: api/Fight
public void PostAddFight(FightDTO f)
public FightDTO PostAddFight(FightDTO f)
{
House challenger1 = new House(f.Challenger1.ID, f.Challenger1.Name, f.Challenger1.NbUnits);
House challenger2 = new House(f.Challenger2.ID, f.Challenger2.Name, f.Challenger2.NbUnits);
War war = new War(f.War.ID,f.War.Name);
Fight fight = new Fight(f.Name, challenger1, challenger2, war, new Territory(f.Territory.ID, f.Territory.Type, new House(f.Territory.Owner.ID, f.Territory.Owner.Name, f.Territory.Owner.NbUnits), f.Territory.Name));
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.addFight(fight);
int id = busi.addFight(fight);
FightDTO _fight = new FightDTO(busi.getFightById(id));
return _fight;
}
// PUT: api/Fight/2
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment