public void fight(user_battle_info pA, user_battle_info pB) { int favorA = 0; for (int i = 0; i < 5; i++) { log += pA.username + " vs " + pB.username + "\r\n"; favorA += action_eval(pA.actions[i], pB.actions[i]); log += " " + pA.actions[i].ToString() + " vs " + pB.actions[i] + "\r\n"; } if (favorA > 0) { pA.battle_score++; log += pA.username + " wins the round! \r\n"; } if (favorA < 0) { pB.battle_score++; log += pB.username + " wins the round! \r\n"; } if (favorA == 0) { log += "A draw?!? A conspiracy?\r\n"; blocked_users.Add(pA); blocked_users.Add(pB); } log += "\r\n"; }
public string joinBattle(user_battle_info user) { if (!battleActive) { battleActive = true; timer = Task.Run(startTimerAsync); } active_users.Add(user); //add active user timer.Wait(); return(log); }
//GET public static Response setActions(Request req, Battle battle) { int userid = tokenToUserId(req.token); if (userid != -1) { if (req.ctype == "json") { user_battle_info thisUser = null; foreach (user_battle_info user in battle.user_infos) { if (user.username == DB_Tools.userIdToName(userid)) { thisUser = user; } } if (thisUser == null) { thisUser = new user_battle_info(DB_Tools.userIdToName(userid)); battle.user_infos.Add(thisUser); } int status = thisUser.setActions(JObject.Parse(req.payload).GetValue("actions").ToString()); if (status == -2) { return(new Response(req, Status_Code.NOK, AdditionalPayload: "Please use Rock Paper Scissor Lizard Spock initials. ")); } if (status == -1) { return(new Response(req, Status_Code.NOK, AdditionalPayload: "Please use 5 Characters. ")); } if (status == 0) { return(new Response(req, Status_Code.OK, AdditionalPayload: "Actions Set. ")); } } return(new Response(req, Status_Code.NOK, AdditionalPayload: "Invalid type. ")); } return(new Response(req, Status_Code.NOK, AdditionalPayload: "Coulnd't verify connection. ")); }