//Update game stats public string EditGameStats(Game game) { using (SPORT_LINK_DBDataContext db = new SPORT_LINK_DBDataContext()) { try { var query = (from gm in db.GAME_STATs where gm.Game_Id.Equals(game.ID) && gm.stats_Id.Equals(game.stats_ID) select gm); if (query.Count() != 0) { GAME_STAT toinsert = query.Single(); // toinsert.Type = _team.Type; toinsert.BestPlayer = game.BestPlayer; toinsert.Team2_Position = game.TeamTwoPos; toinsert.Team2_Fouls = game.TeamTwoFouls; toinsert.Team2_GoalScored = game.TeamTwoGoalScored; toinsert.Team2_NumCornerKick = game.TeamTwoCornerKick; toinsert.Team2_RedCard = game.TeamTwoRedCard; toinsert.Team2_YellowCard = game.TeamTwoYellowCard; toinsert.Team2_OveralAverage = game.TeamTwo_OveralAverage; toinsert.Team1_Fouls = game.TeamOneFouls; toinsert.Team1_Position = game.TeamOnePos; toinsert.Team1_GoalScored = game.TeamOneGoalScored; toinsert.Team1_NumCornerKick = game.TeamOneCornerKick; toinsert.Team1_RedCard = game.TeamOneRedCard; toinsert.Team1_YellowCard = game.TeamOneYellowCard; toinsert.Team1_OveralAverage = game.TeamOne_OveralAverage; //db.SPORTs.InsertOnSubmit(toinsert); db.SubmitChanges(); return("success"); } else { return("failed: No Such team exist"); } } catch (Exception) { return("failed"); } }; }
private static void UpdateState(GAME_SIG game_sig) { switch (now_state) { case GAME_STAT.Menu: if (game_sig == GAME_SIG.Game) { now_state = GAME_STAT.Game; } else if (game_sig == GAME_SIG.Tutorial) { now_state = GAME_STAT.Tutorial; } break; case GAME_STAT.Game: if (game_sig == GAME_SIG.Menu) { now_state = GAME_STAT.Menu; } else if (game_sig == GAME_SIG.Pause) { now_state = GAME_STAT.Pause; } else if (game_sig == GAME_SIG.GameOver) { now_state = GAME_STAT.GameOver; } break; case GAME_STAT.Tutorial: if (game_sig == GAME_SIG.Game) { now_state = GAME_STAT.Game; } else if (game_sig == GAME_SIG.Menu) { now_state = GAME_STAT.Menu; } break; case GAME_STAT.Pause: if (game_sig == GAME_SIG.Game) { now_state = GAME_STAT.Game; } break; case GAME_STAT.GameOver: if (game_sig == GAME_SIG.Game) { now_state = GAME_STAT.Game; } else if (game_sig == GAME_SIG.Menu) { now_state = GAME_STAT.Menu; } break; default: Debug.Log("Error!! Invalid game state: " + now_state); break; } }
//AddBestPlayer public string GameStats(Game game) { try { using (SPORT_LINK_DBDataContext db = new SPORT_LINK_DBDataContext()) { //Update Team Average string updateTeamAverage = calcAverage(game); var query = (from res in db.GAME_STATs where res.Game_Id.Equals(game.ID) select res); if (query.Count() == 0) //add stats { GAME_STAT toinsert = new GAME_STAT(); toinsert.Game_Id = game.ID; toinsert.BestPlayer = game.BestPlayer; toinsert.Team2_Position = game.TeamTwoPos; toinsert.Team2_Fouls = game.TeamTwoFouls; toinsert.Team2_GoalScored = game.TeamTwoGoalScored; toinsert.Team2_NumCornerKick = game.TeamTwoCornerKick; toinsert.Team2_RedCard = game.TeamTwoRedCard; toinsert.Team2_YellowCard = game.TeamTwoYellowCard; toinsert.Team2_OveralAverage = game.TeamTwo_OveralAverage; toinsert.Team1_Fouls = game.TeamOneFouls; toinsert.Team1_Position = game.TeamOnePos; toinsert.Team1_GoalScored = game.TeamOneGoalScored; toinsert.Team1_NumCornerKick = game.TeamOneCornerKick; toinsert.Team1_RedCard = game.TeamOneRedCard; toinsert.Team1_YellowCard = game.TeamOneYellowCard; toinsert.Team1_OveralAverage = game.TeamOne_OveralAverage; db.GAME_STATs.InsertOnSubmit(toinsert); db.SubmitChanges(); return("success"); } else { GAME_STAT toinsert = query.First(); // toinsert.Game_Id = game.ID; toinsert.BestPlayer = game.BestPlayer; toinsert.Team2_Position = game.TeamTwoPos; toinsert.Team2_Fouls = game.TeamTwoFouls; toinsert.Team2_GoalScored = game.TeamTwoGoalScored; toinsert.Team2_NumCornerKick = game.TeamTwoCornerKick; toinsert.Team2_RedCard = game.TeamTwoRedCard; toinsert.Team2_YellowCard = game.TeamTwoYellowCard; toinsert.Team2_OveralAverage = game.TeamTwo_OveralAverage; toinsert.Team1_Fouls = game.TeamOneFouls; toinsert.Team1_Position = game.TeamOnePos; toinsert.Team1_GoalScored = game.TeamOneGoalScored; toinsert.Team1_NumCornerKick = game.TeamOneCornerKick; toinsert.Team1_RedCard = game.TeamOneRedCard; toinsert.Team1_YellowCard = game.TeamOneYellowCard; toinsert.Team1_OveralAverage = game.TeamOne_OveralAverage; // db.GAME_STATs.InsertOnSubmit(toinsert); db.SubmitChanges(); return("success"); } }; } catch (Exception) { return("failed"); } }