Exemple #1
0
        // To initiate the adventure
        private async void Start_Clicked(object sender, EventArgs e)
        {
            Start.IsEnabled = false; // disable the button to avoid multiple clicks.

            actIndicator.IsRunning = true;
            await App.isNetworkAccess();

            if (adventure.waypointID == null) // handle error when no starting waypoint found
            {
                actIndicator.IsRunning = false;
                await DisplayAlert("Error", "Could not find the stating waypoint! This adventure is current unavailable or under development.", "Cancel");

                Start.IsEnabled = true; // enable the button.
                return;
            }

            session = await SessionLogic.GetSession(App.myTeam.teamID, adventure.adventureID);

            if (session == null)                           //this is the first time the team is playing this adventure
            {
                await SessionLogic.PostSession(adventure); //create a new session for this adventure and team

                session = await SessionLogic.GetSession(App.myTeam.teamID, adventure.adventureID);
            }
            else
            {
                actIndicator.IsRunning = false;
                bool sng = await DisplayAlert("Warning", "Starting new game will cause your past save of this adventure be removed!", "Start new game", "Cancel");

                if (sng == true)
                {
                    actIndicator.IsRunning = true;
                    //Reset game state
                    await SessionLogic.PutSession(App.myTeam.teamID, adventure.adventureID, adventure.waypointID.Value);

                    session = await SessionLogic.GetSession(App.myTeam.teamID, adventure.adventureID);
                }
                else
                {
                    Start.IsEnabled = true; // enable the button.
                    return;
                }
            }

            Waypoint wp = await WaypointLogic.GetWaypoint(session.WaypointID);

            App.atWaypointID  = session.WaypointID;
            App.atAdventureID = session.AdventureID;

            App.reachableWaypoints = await AdventureMapLogic.GetAdventureMap(App.atWaypointID);

            App.getLocation();
            actIndicator.IsRunning = false;
            Start.IsEnabled        = true; // enable the button.
            await Navigation.PushAsync(new StoryPage(adventure.title, wp));
        }
Exemple #2
0
        // To support movement between waypoint, it will check whether the players are allowed to move to the next waypoint or not
        async void OnWaypointAlertClick(object sender, EventArgs e)
        {
            continue_btn.IsEnabled = false; // disable the button to avoid multiple clicks.

            actIndicator.IsRunning = true;
            await App.isNetworkAccess();

            if (isCompleted == false) // requests to finished challenge before move to the next waypoint
            {
                actIndicator.IsRunning = false;
                await DisplayAlert("Failed", "You have not completed the challenge yet. Try again!", "Ok");

                continue_btn.IsEnabled = true; // enable the button.
                return;
            }

            if (isEndpoint == true) // handles the last waypoint completed.
            {
                actIndicator.IsRunning = false;
                await DisplayAlert("Congratulation", "You have completed '" + adventureTitle + "'!", "Ok");

                continue_btn.Text      = "Completed";
                continue_btn.IsEnabled = false;
                return;
            }

            await App.getLocation(); // the main method to compare location

            Waypoint wp = await WaypointLogic.GetWaypoint(App.atWaypointID);

            bool reached = false;

            foreach (Waypoint w in App.reachableWaypoints)
            {
                if (w.WaypointId == wp.WaypointId)
                {
                    reached = true;
                }
            }


            if (reached == false) // alerts if not reached a new waypoint yet
            {
                actIndicator.IsRunning = false;
                await DisplayAlert("Failed", "You have not reached a new story point yet. Keep searching!", "Ok");

                continue_btn.IsEnabled = true; // enable the button.
                return;
            }

            //Save new state
            await SessionLogic.PutSession(App.myTeam.teamID, App.atAdventureID, App.atWaypointID);

            // opens new Story page with the content of the next waypoint
            App.reachableWaypoints = await AdventureMapLogic.GetAdventureMap(App.atWaypointID);

            actIndicator.IsRunning = false;
            continue_btn.IsEnabled = true; // enable the button.

            await Navigation.PushAsync(new StoryPage(adventureTitle, wp));
        }