Exemplo n.º 1
0
 public Partie()
 {
     Shots                  = new List <Shot>();
     CurrentClub            = GolfXMLReader.getClubFromName("Fer3");
     ScoreOfThisPartie      = new ScorePartie();
     this.holeFinishedCount = -1;
 }
Exemplo n.º 2
0
        /**
         * Saves the given game
         * scoreOfThisPartie : the game statistics
         */
        public async static Task saveGameForStats(ScorePartie scoreOfThisPartie)
        {
            SQLite.SQLiteAsyncConnection connection = DependencyService.Get <ISQLiteDb>().GetConnectionAsync();
            await connection.CreateTableAsync <ScoreHole>();

            await connection.CreateTableAsync <ScorePartie>();

            await SQLiteNetExtensionsAsync.Extensions.WriteOperations.InsertOrReplaceWithChildrenAsync(connection, scoreOfThisPartie, false);
        }
Exemplo n.º 3
0
 /**
  * Filters the given shot list keeping only the ones that was done during a game using the starting and ending date of the game
  * scorePartie : the game score
  * allShots : the list of shot to filter
  */
 public static List <Shot> getShotsFromPartie(ScorePartie scorePartie, List <Shot> allShots)
 {
     return(allShots.Where(sh => sh.Date >= scorePartie.DateDebut && sh.Date <= scorePartie.DateFin && !sh.isPutt()).ToList());
 }
Exemplo n.º 4
0
        /**
         * Creates a filled ScorePartie and insert it recursivly in the database.
         * Values used to create the statistics have not necessarily any sense
         */
        public static ScorePartie CreateScorePartie()
        {
            SQLite.SQLiteConnection connection = DependencyService.Get <ISQLiteDb>().GetConnection();
            connection.CreateTable <GolfCourse>();
            connection.CreateTable <ScorePartie>();
            connection.CreateTable <ScoreHole>();
            connection.CreateTable <Shot>();
            connection.CreateTable <MyPosition>();
            List <GolfCourse> golfCourses = SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren <GolfCourse>(connection);
            Random            r           = new Random();
            var holes = golfCourses[r.Next() % (golfCourses.Count)].Holes;
            //var holes = golfCourses[0].Holes;
            //DateTime date = new DateTime(2019, DateTime.Now.Month, (TestClassFactory.createdScorePartieCount % 28) + 1);
            DateTime    date  = DateTime.Now;
            ScorePartie sp    = new ScorePartie(date);
            List <Shot> shots = new List <Shot>();
            List <Club> clubs = SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren <Club>(connection);
            int         i     = 0;

            if (holes != null)
            {
                foreach (Hole hole in holes)
                {
                    int randPutt  = r.Next() % 3 + 1;
                    int randScore = r.Next() % 9 - 3;
                    if (TestClassFactory.createdScorePartieCount == 0)
                    {
                        randScore = 10;
                    }
                    //int randScore = 1;
                    System.Diagnostics.Debug.WriteLine("randPutt = " + randPutt + " randScore = " + randScore + "\n");
                    for (int j = 0; j < randScore; ++j)
                    {
                        shots.Add(new Shot(clubs[2], RandomEnumValue <Shot.ShotCategory>(), DateTime.Now));
                    }
                    if (i == 7 && r.Next() % 3 == 1)
                    {
                        randPutt = 0;
                    }
                    ScoreHole sh = new ScoreHole(hole, 0, randScore, randPutt == 2, randPutt, DateTime.Now);
                    sp.add(sh);
                    i++;
                }
            }
            System.Diagnostics.Debug.WriteLine("\n");
            sp.DateFin = DateTime.Now;
            try
            {
                SQLiteNetExtensions.Extensions.WriteOperations.InsertAllWithChildren(connection, shots, true);
                SQLiteNetExtensions.Extensions.WriteOperations.InsertAllWithChildren(connection, sp.scoreHoles, true);
                SQLiteNetExtensions.Extensions.WriteOperations.InsertWithChildren(connection, sp, true);
            } catch (SQLiteException sqlex)
            {
                System.Diagnostics.Debug.WriteLine(sqlex.StackTrace);
            }

            List <Shot> shotss = SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren <Shot>(connection);

            System.Diagnostics.Debug.WriteLine(shotss.Count);

            TestClassFactory.createdScorePartieCount++;
            return(sp);
        }