-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.aspx.cs
More file actions
56 lines (47 loc) · 1.53 KB
/
Server.aspx.cs
File metadata and controls
56 lines (47 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Server : System.Web.UI.Page
{
static string datafile;
protected void Page_Load(object sender, EventArgs e)
{
Response.AppendHeader("Content-Type", "application/json");
datafile = Server.MapPath(@"~/App_Data/db.json");
}
// send a model to the client
[WebMethod]
public static dynamic GetModel(string type)
{
switch (type)
{
// base types
case "Troop": return new Troop();
case "Resource": return new Resource();
// troops
case "Archer": return new Archer();
case "Spearman": return new Spearman();
// resources
case "Grass": return new Grass();
case "Swamp": return new Swamp();
case "Water": return new Water();
case "Forest": return new Forest();
case "Mountain": return new Mountain();
}
return "";
}
// resolve a combat
[WebMethod]
public static Troop CombatResolution(Combat fight)
{
double attackVal = (fight.attacker._attack + fight.attacker._loyalty + fight.attackHex._attackModifier);
double defenseVal = (fight.defender._defense + fight.defender._loyalty + fight.defenceHex._defenseModifier);
if (attackVal > defenseVal)
return fight.attacker;
return fight.defender;
}
}