public CompetitionParticipationTaskRes(ParticipationObject PO, Task currTask, int score)
        {
            PO.Score += score;

            Label taskName = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"Task: {currTask.TaskName}"
            };

            Label gained = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"Score gained: +{score} pts"
            };

            Label total = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"Total score: {PO.Score}"
            };

            Button SubmitButt = new Button()
            {
                Text              = "Next",
                BackgroundColor   = Color.White,
                BorderColor       = Color.Black,
                BorderWidth       = 3,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
            };

            SubmitButt.Clicked += async(sender, args) => await NextButtonClick(sender, args, PO);

            StackLayout C = new StackLayout();

            C.Children.Add(taskName);
            C.Children.Add(gained);
            C.Children.Add(total);
            C.Children.Add(SubmitButt);


            ScrollView scrollView = new ScrollView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content         = C
            };

            Content = scrollView;
        }
Exemple #2
0
        public CompetitionParticipationResult(ParticipationObject PO)
        {
            Label Congratz = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"You have completed the competition {PO.Competition.Name}"
            };

            Label gained = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"Your score is: {PO.Score}"
            };

            Button SubmitButt = new Button()
            {
                Text              = "Back",
                BackgroundColor   = Color.White,
                BorderColor       = Color.Black,
                BorderWidth       = 3,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
            };

            SubmitButt.Clicked += async(sender, args) => await NextButtonClick(sender, args, PO);

            StackLayout C = new StackLayout();

            C.Children.Add(Congratz);
            C.Children.Add(gained);
            C.Children.Add(SubmitButt);


            ScrollView scrollView = new ScrollView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content         = C
            };

            Content = scrollView;
        }
 private async System.Threading.Tasks.Task EnterButtonOnClick(object sender, EventArgs e, Competition selectedCom)
 {
     //To enter page
     ParticipationObject po = new ParticipationObject(selectedCom);
     await Navigation.PushAsync(new CompetitionParticipation(po));
 }
 private async System.Threading.Tasks.Task NextButtonClick(object sender, EventArgs e, ParticipationObject PO)
 {
     await Navigation.PushAsync(new CompetitionParticipation(PO));
 }
Exemple #5
0
        public CompetitionParticipation(ParticipationObject PO)
        {
            DateTime taskStart = DateTime.Now;

            Xamarin.Forms.Maps.Map map = new Xamarin.Forms.Maps.Map();

            Random rnd      = new Random();
            int    rndindex = rnd.Next(0, PO.Tasks.Count);
            Task   currTask = PO.Tasks[rndindex];

            PO.Tasks.RemoveAt(rndindex);

            Label taskName = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"Task: {currTask.TaskName}"
            };

            Label desc = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"{currTask.Description}"
            };

            Label quest = new Label()
            {
                IsVisible         = false,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = $"{currTask.Question}"
            };


            Button SubmitButt = new Button()
            {
                Text              = "Submit",
                BackgroundColor   = Color.White,
                BorderColor       = Color.Black,
                BorderWidth       = 3,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
            };

            Entry answerEntry = new Entry()
            {
                IsVisible         = false,
                Placeholder       = "Your answer here",
                BackgroundColor   = Color.White,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
            };

            map.HeightRequest = 300;

            var     pos     = new Position(lat, lon);
            MapSpan mapspan = new MapSpan(pos, 0.01, 0.01);

            map = new Xamarin.Forms.Maps.Map(mapspan);

            SubmitButt.Clicked += async(sender, args) => await SubmitButtonOnClick(sender, args, PO, currTask, taskStart, answerEntry);


            StackLayout C = new StackLayout();

            C.Children.Add(taskName);
            C.Children.Add(desc);
            C.Children.Add(map);
            C.Children.Add(answerEntry);
            C.Children.Add(quest);
            C.Children.Add(SubmitButt);

            WaitUntillInLocation(answerEntry, quest);

            ScrollView scrollView = new ScrollView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content         = C
            };

            Content = scrollView;
        }
Exemple #6
0
        private async System.Threading.Tasks.Task SubmitButtonOnClick(object sender, EventArgs e, ParticipationObject PO, Task task, DateTime startDate, Entry answerEntry)
        {
            DateTime endDate = DateTime.Now;
            TimeSpan ts      = endDate - startDate;

            int score = 0;

            if (answerEntry.Text == task.Answer)
            {
                score += 150;
            }

            if (ts.TotalSeconds < 600)
            {
                double t = (600 - ts.TotalSeconds) / 600;
                score += (int)((double)score * (0.3 * t));
            }

            if (PO.Tasks.Count > 0)
            {
                await Navigation.PushAsync(new CompetitionParticipationTaskRes(PO, task, score));
            }
            else
            {
                await Navigation.PushAsync(new CompetitionParticipationResult(PO));
            }
        }