Esempio n. 1
0
    public int CalculateScore(BodyPartItem realItem, BodyPartItem selectedItem)
    {
        int category = realItem.Category == selectedItem.Category ? 2 : 0;
        int colour   = realItem.Colour == selectedItem.Colour ? 1 : 0;
        int type     = realItem.Type == selectedItem.Type ? 1 : 0;

        return(category + colour + type);
    }
Esempio n. 2
0
    public void InitImage(BodyPartItem item)
    {
        Item = item;
        var im = GetComponent <Image> ();

        im.sprite = item.Sprite;
        im.color  = item.Colour == BodyPartColour.Yellow ? yellow : brown;
    }
Esempio n. 3
0
    public void InitSprite(BodyPartItem item)
    {
        Item = item;
        var sr = GetComponent <SpriteRenderer> ();

        sr.sprite = item.Sprite;
        sr.color  = item.Colour == BodyPartColour.Yellow ? yellow : brown;
        transform.localPosition = item.Offset;
        Debug.LogFormat("Position: {0}, offset: {1}", transform.localPosition, item.Offset);
    }
Esempio n. 4
0
    public void FillTray(BodyPartType type)
    {
        TrayPartList.Clear();
        Solution sol = GenerateSolution(type);

        if (!sol.FakeItem)
        {
            Debug.LogError("Could not find fake part: " + sol.ToString());
            return;
        }

        BodyPartItem solutionFakeItem = sol.FakeItem;

        TrayPartList.Add(solutionFakeItem);

        var tempFakePartList = new List <BodyPartItem> (FakeBodyPartList);

        // Remove solution fake part
        tempFakePartList.Remove(solutionFakeItem);

        // Equal Type + Category
        var equalTypeCategory = tempFakePartList.FindAll((item) => item.Type == solutionFakeItem.Type && item.Category == solutionFakeItem.Category && item.Colour != solutionFakeItem.Colour);

        BodyPartItem newItem = equalTypeCategory[Random.Range(0, equalTypeCategory.Count)];

        tempFakePartList.Remove(newItem);
        TrayPartList.Add(newItem);
        Debug.Log("Equal Type + Category: " + newItem.ToString());

        // Equal Type + Colour
        var equalTypeColour = tempFakePartList.FindAll((item) => item.Type == solutionFakeItem.Type && item.Colour == solutionFakeItem.Colour && item.Category != solutionFakeItem.Category);

        newItem = equalTypeColour[Random.Range(0, equalTypeColour.Count)];
        tempFakePartList.Remove(newItem);
        TrayPartList.Add(newItem);
        Debug.Log("Equal Type + Colour: " + newItem.ToString());

        // Equal Type (Not equal color + category)
        var equalType = tempFakePartList.FindAll((item) => item.Type == solutionFakeItem.Type && item.Category != solutionFakeItem.Category && item.Colour != solutionFakeItem.Colour);

        newItem = equalType[Random.Range(0, equalType.Count)];
        tempFakePartList.Remove(newItem);
        TrayPartList.Add(newItem);
        Debug.Log("Equal Type: " + newItem.ToString());

        TrayPartList.Shuffle();
        foreach (BodyPartItem item in TrayPartList)
        {
            Debug.Log(item.name == solutionFakeItem.name ? "(solution) " + item.ToString() : item.ToString());
        }
    }
Esempio n. 5
0
    public Solution GenerateSolution(BodyPartType type)
    {
        // Pick a random real body part
        BodyPartItem realPart = GetRandomBodyPart(RealBodyPartList, type, CurrentSolution != null ? CurrentSolution.RealItem : null);

        // Match a fake body part with it
        BodyPartItem fakePart = FakeBodyPartList.Find((item) => item.Colour == realPart.Colour && item.Type == realPart.Type && item.Category == realPart.Category);

        RegisterSolution(realPart.name);
        CurrentSolution = new Solution(realPart, fakePart);

        Debug.LogFormat("New Solution: " + CurrentSolution.ToString());
        return(CurrentSolution);
    }
Esempio n. 6
0
    private BodyPartItem GetRandomBodyPart(List <BodyPartItem> list, BodyPartType type, BodyPartItem toExclude = null)
    {
        List <BodyPartItem> tempList = new List <BodyPartItem> (list);

        // Remove if item exists and is not the only item in the list
        if (tempList.IndexOf(toExclude) != -1 && tempList.Count > 1)
        {
            tempList.Remove(toExclude);
        }

        tempList = tempList.FindAll((item) => item.Type == type);

        BodyPartItem newItem = tempList[Random.Range(0, tempList.Count)];

        Debug.LogFormat("New random body part: {0}", newItem.name);
        return(newItem);
    }
Esempio n. 7
0
        public void RemoveMeasurement(object sender)
        {
            var workoutMeasurement = (sender as Button).DataContext as WorkoutMeasurement;

            using var db = new AppDbContext();
            db.WorkoutMeasurements.Remove(workoutMeasurement);
            db.SaveChanges();

            var bodyPartItem = new BodyPartItem
            {
                BodyPart     = workoutMeasurement.BodyPart,
                BodyPartName = workoutMeasurement.BodyPart.ToString()
            };

            BodyPartItems.Insert(0, bodyPartItem);
            SelectedBodyPartItem = bodyPartItem;

            WorkoutResultItem.WorkoutMeasurements.Remove(workoutMeasurement);
        }
Esempio n. 8
0
 public Solution(BodyPartItem realItem, BodyPartItem fakeItem)
 {
     RealItem = realItem;
     FakeItem = fakeItem;
 }
Esempio n. 9
0
 public void InitialiseBodyPartImage(int index, BodyPartItemObject obj, BodyPartItem item)
 {
     obj.InitImage(item);
     obj.name = string.Format("image-body-part-{0}-{1}", index, item.name);
 }