Exemplo n.º 1
0
        public Dictionary<string, string> GetResult(Guid MatchId, int CurrentRound)
        {
            try
            {
                using (RockPaperScissorsContainer Entities = new RockPaperScissorsContainer())
                {
                    int HumanId = GetPlayerTypeId("Human", Entities);

                    int ComputerId = GetPlayerTypeId("Computer", Entities);

                    Dictionary<string, string> WinnerDict = new Dictionary<string, string>();
                    string HumanChoice = Entities.tblTurns
                        .Where(t => t.MatchId == MatchId && t.PlayerTypeId == HumanId && t.TurnNumber == CurrentRound)
                        .FirstOrDefault().Choice;

                    string ComputerChoice = Entities.tblTurns
                       .Where(t => t.MatchId == MatchId && t.PlayerTypeId == ComputerId && t.TurnNumber == CurrentRound)
                        .FirstOrDefault().Choice;

                    string Winner = this.GetWinner(Entities, HumanChoice, ComputerChoice);

                    WinnerDict.Add("HumanChoice", HumanChoice);
                    WinnerDict.Add("ComputerChoice", ComputerChoice);
                    WinnerDict.Add("Winner", Winner);

                    return WinnerDict;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
 public string GetWinner(RockPaperScissorsContainer Entities, string HumanChoice, string ComputerChoice)
 {
     if (Entities.vw_WinnersLosers.Where(v => v.Winner == HumanChoice && v.Loser == ComputerChoice).Count() == 1)
     {
         return "HumanWinner";
     }
     else if (Entities.vw_WinnersLosers.Where(v => v.Winner == ComputerChoice && v.Loser == HumanChoice).Count() == 1)
     {
         return "ComputerWinner";
     }
     else
     {
         return "Draw";
     }
 }
Exemplo n.º 3
0
 public List<tblPlayerType> GetOpponents()
 {
     try
     {
         using (RockPaperScissorsContainer entities = new RockPaperScissorsContainer())
         {
             return entities.tblPlayerTypes
                 .Where(p => p.PlayerTypeId != 1)
                 .ToList();
         }
     }
     catch(Exception ex)
     {
     // TODO: Handle SQL error
         throw ex;
     }
 }
Exemplo n.º 4
0
        public Dictionary<Guid, bool> CreateMatchId(string numOfRounds)
        {
            try
            {
                using (RockPaperScissorsContainer entities = new RockPaperScissorsContainer())
                {
                    tblMatch tblMatch = new tblMatch();
                    tblMatch.MatchId = Guid.NewGuid();
                    tblMatch.MatchType = numOfRounds;
                    entities.tblMatches.Add(tblMatch);
                    entities.SaveChanges();

                    Dictionary<Guid, bool> Outcome = new Dictionary<Guid, bool>();
                    Outcome.Add(tblMatch.MatchId, true);
                    return Outcome;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 5
0
 public int GetPlayerTypeId(string Type, RockPaperScissorsContainer Entities)
 {
     return Entities.tblPlayerTypes
                .Where(p => p.PlayerType == Type)
                .FirstOrDefault().PlayerTypeId;
 }
Exemplo n.º 6
0
        public string GetLastMoveHuman(Guid MatchId, int RoundNumber)
        {
            try
            {
                using (RockPaperScissorsContainer Entities = new RockPaperScissorsContainer())
                {
                   RoundNumber = RoundNumber-1;

                   return Entities.tblTurns
                       .Where(t => t.MatchId == MatchId && t.TurnNumber == RoundNumber && t.PlayerTypeId == 1)
                       .FirstOrDefault().Choice;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 7
0
        public void SaveMove(string Choice, Guid MatchId, string Player, int currentRound)
        {
            try
            {
                using (RockPaperScissorsContainer entities = new RockPaperScissorsContainer())
                {
                    int OpponentId = entities.tblPlayerTypes
                        .Where(p => p.PlayerType == Player)
                        .FirstOrDefault()
                        .PlayerTypeId;

                    tblTurn tblTurn = new tblTurn();
                    tblTurn.TurnId = Guid.NewGuid();
                    tblTurn.MatchId = MatchId;
                    tblTurn.Choice = Choice;
                    tblTurn.PlayerTypeId = OpponentId;
                    tblTurn.TurnNumber = currentRound;
                    entities.tblTurns.Add(tblTurn);
                    entities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
 // public list
 public List<tblLookupMoveType> GetStandardMoveSet()
 {
     try
     {
         using (RockPaperScissorsContainer entities = new RockPaperScissorsContainer())
         {
             return entities.tblLookupMoveTypes
                 .Where(m => m.MoveTypeName == "Rock" || m.MoveTypeName == "Paper" || m.MoveTypeName == "Scissors")
                 .ToList();
         }
     }
     catch (Exception ex)
     {
         // TODO: Handle SQL error
         throw ex;
     }
 }