Exemplo n.º 1
0
        void OnRemoveStepDone()
        {
            m_GameManager.OnRemoveStepDone -= OnRemoveStepDone;

            GameStep = GameStep.Move;
            DoStepJob();
        }
Exemplo n.º 2
0
        void OnMoveStepDone()
        {
            m_GameManager.OnMoveStepDone -= OnMoveStepDone;

            GameStep = GameStep.GameOver;
            DoStepJob();
        }
Exemplo n.º 3
0
        public void ToGame()
        {
            CurPlayer = 1;

            Hammer = GameObject.Instantiate(PrefabPool.GetPrefab("model/hammer"), Vector3.one * 100, Quaternion.identity)
                     .GetComponent <Hammer>();
            Hammer.gameObject.SetActive(true);

            UIGame uiGame = UIManager.CreateUI <UIGame>();

            uiGame.SetRoomConfig();
            uiGame.SetCurPlayer(CurPlayer);

            // camera
            if (GameConf.MapType == MapType.Small)
            {
                Camera.main.transform.position = new Vector3(1.57f, 9.07f, -5.82f);
            }
            else if (GameConf.MapType == MapType.Middle)
            {
                Camera.main.transform.position = new Vector3(2.18f, 9.07f, -7.01f);
            }
            else if (GameConf.MapType == MapType.Big)
            {
                Camera.main.transform.position = new Vector3(2.58f, 9.07f, -8.2f);
            }

            HexManager = AddChild(new HexManager()) as HexManager;



            GameStep = GameStep.SelectingMain;
        }
Exemplo n.º 4
0
 private void Step(GameStep step)
 {
     foreach (var achievement in _achievementList.Achievements)
     {
         achievement.Calculate(step);
     }
 }
Exemplo n.º 5
0
        public void OnStartHitting()
        {
            UIGame uiGame = UIManager.GetUIByType <UIGame>();

            if (OpType == OpType.Pass)
            {
                uiGame.ShowWheel(false);
                uiGame.ShowWheelLater(true, 0.5f);

                NextPlayer();
                return;
            }

            // 检查是否有选定的颜色,如果已经没有相应的颜色,则再次随机
            if (OpType != OpType.Both && !HexManager.HasColor(OpType))
            {
                uiGame.ShowWheel(false);
                uiGame.ShowWheelLater(true, 0.5f);
                UIManager.SendMessage(MsgType.OnShowTips, "颜色无效,再转一回吧");

                return;
            }

            GameStep = GameStep.Hitting;
            uiGame.ShowWheel(false);
        }
Exemplo n.º 6
0
 void PublishSteps()
 {
     try
     {
         while (true)
         {
             var alivePlayerHandlers = this.playerHandlers.FindAll(p => p.alive);
             if (alivePlayerHandlers.Count == 0)
             {
                 break;
             }
             GameStep nextStep = this.game.Step();
             alivePlayerHandlers.ForEach(playerHandler =>
                                         PublishToPlayer(playerHandler, nextStep)
                                         );
             Thread.Sleep(Server.STEP_TIME);
         }
         Console.WriteLine("Closing game");
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         Console.WriteLine("Closing game");
         if (Server.DidThreadAbort(e))
         {
             return;
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        ///     Returns opponent
        /// </summary>
        /// <param name="rowIndex"></param>
        /// <param name="columnIndex"></param>
        /// <param name="gameId"></param>
        /// <param name="userName">Name of a use who made a step</param>
        /// <returns></returns>
        //todo: refactor
        // figure name in not necessary in GameStep entity
        private async Task <Member> AddStepToGame(int rowIndex, int columnIndex, int gameId, string userName)
        {
            Member opponent;
            var    context = Context.Request.GetHttpContext().GetOwinContext().Get <GameContext>();
            var    game    = context.Games.Find(gameId);

            // this method is not necessary
            var figure = await GetFigure(userName, context, game);

            var step = new GameStep
            {
                PlayerName  = userName,
                XCoordinate = rowIndex,
                YCoordinate = columnIndex,
                IdFigure    = figure.FigureId
            };

            game.GameSteps.Add(step);
            await context.SaveChangesAsync();

            if (game.PlayerInitiator.UserName.Equals(userName))
            {
                opponent = await GetUserByName(game.OpponentUserName, Context);
            }
            else if (game.OpponentUserName.Equals(userName))
            {
                opponent = game.PlayerInitiator;
            }
            else
            {
                throw new ArgumentException("Invalid user name");
            }
            return(opponent);
        }
Exemplo n.º 8
0
        public void OnStartHitting()
        {
            if (OpType == OpType.Pass)
            {
                // 此轮跳过,延迟1秒到下一位

                CmdResponse.RandomOperation(null, OpType);

                // todo: 延迟
                NextPlayer();
                return;
            }

            // 检查是否有选定的颜色,如果已经没有相应的颜色,则再次随机
            if (OpType != OpType.Both && !HexManager.HasColor(OpType))
            {
                // 重新随机

                return;
            }

            GameStep = GameStep.Hitting;

            foreach (Player p in m_players.Values)
            {
                CmdResponse.StartHitting(p, OpType);
            }
        }
Exemplo n.º 9
0
 void PublishToPlayer(PlayerHandler playerHandler, GameStep nextStep)
 {
     try
     {
         if (playerHandler.isNew)
         {
             this.game.steps.ForEach(step =>
                                     playerHandler.socket.Send(step.ToByteArray())
                                     );
             playerHandler.isNew = false;
         }
         else
         {
             playerHandler.socket.Send(nextStep.ToByteArray());
         }
     }
     catch (Exception e)
     {
         playerHandler.alive = false;
         Console.WriteLine("player disconnected: " + playerHandler.id);
         if (Server.DidPlayerDisconnect(playerHandler, e))
         {
             return;
         }
         Console.WriteLine(e.GetType());
         playerHandler.socket.Close();
     }
 }
Exemplo n.º 10
0
 protected override void DoStep(GameStep step)
 {
     if (GameStep.GameWon == step)
     {
         PercentageCompleted = 100;
     }
 }
Exemplo n.º 11
0
    /// <summary>Receives input from client and handles it</summary>
    public void TakeInput(int firstElementIndexAtParent, int secondElementIndexAtParent)
    {
        // find first element based on gamePanel's child index
        firstElement = BoardFunctions.GetElementBasedOnParentIndex(elementsPositions, firstElementIndexAtParent);
        // find second element based on gamePanel's child index
        secondElement = BoardFunctions.GetElementBasedOnParentIndex(elementsPositions, secondElementIndexAtParent);
        currentStep   = GameStep.CheckingInput;

        #region  Debug
        //  To use for cheats
        // if (BoardFunctions.GetIfNeighbours(firstElement, secondElement, elementsPositions)) {
        //     AlexDebugger.GetInstance().AddMessage("Correct input: " + BoardFunctions.GetTransformByIndex(firstElement.GetTransformIndex()) + ", with " + BoardFunctions.GetTransformByIndex(secondElement.GetTransformIndex()), AlexDebugger.tags.Input);
        //     // Remove tokens
        //     MoneyManager.ChangeBalanceBy(-MoneyManager.GetSwapCost());
        //     // Swap the elements on the board
        //     BoardFunctions.SwapElements(firstElement, secondElement, this, rewire : false, FixedElementData.swappingSpeed / 2);
        //     // Allow Update() to check if matches are created

        // }
        // else {
        //     // Swap elements, on rewire mode
        //     BoardFunctions.SwapElements(firstElement, secondElement, this, rewire : true);
        //     AddWaitMessage();
        //     SendMessagesToClient();
        //     currentMessageID += 1;
        //     Server.GetServerInstance().SendMessageToClient(new Messages.ServerStatusMessage(currentMessageID, -1, true));

        // }
        #endregion
    }
 protected override void DoStep(GameStep step)
 {
     if (GameStep.GameFinished == step)
     {
         PercentageCompleted += 10;
     }
 }
Exemplo n.º 13
0
    void UpdateStep(GameStep oldStep)
    {
        switch (CurrentStep)
        {
        case GameStep.RoleSelection:
            RoleSelectionManager.BuildRoleList();
            LoadScriptButton.SetActive(true);
            break;

        case GameStep.BluffSelection:
            RoleSelectionManager.gameObject.SetActive(true);
            NightManager.gameObject.SetActive(false);
            LoadScriptButton.SetActive(false);
            RoleSelectionManager.BuildBluffList();
            break;

        case GameStep.FirstNight:
            RoleSelectionManager.gameObject.SetActive(false);
            NightManager.gameObject.SetActive(true);
            NightManager.BuildFirstNightList();
            break;

        case GameStep.OtherNights:
            NightManager.BuildOtherNightsList();
            break;

        default:
            break;
        }
    }
Exemplo n.º 14
0
    // Met le jeu en place pour un lancer
    void Init()
    {
        step = GameStep.Start;

        ResetQuilles();
        ResetBoule();
        ResetCameras();
    }
Exemplo n.º 15
0
        void Start()
        {
            Notify.RefreshScaler();

            GameStep = GameStep.GameBegin;

            DoStepJob();
        }
Exemplo n.º 16
0
 /// <summary>
 /// Stop the run step (stop jump and speed detection until next run)
 /// </summary>
 /// <param name="message">Message emitted by the backend</param>
 private void FinishRun(string message)
 {
     if (logMode)
     {
         log.Info(Step.ToString() + " : Message = \"" + message + "\"");
     }
     Step = GameStep.FINISHED;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Pass to the next gameplay step which is the run
 /// </summary>
 /// <param name="message">Message emitted by the backend</param>
 private void StartRun(string message)
 {
     if (logMode)
     {
         log.Info(Step.ToString() + " : Message received = \"" + message + "\"");
     }
     Step = GameStep.STARTED;
 }
Exemplo n.º 18
0
        public override void Start()
        {
            base.Start();

            m_players  = new Dictionary <int, Player>();
            HexManager = AddChild(new HexManager()) as HexManager;

            GameStep = GameStep.NotStart;
        }
Exemplo n.º 19
0
        public void OnGameOver()
        {
            GameStep = GameStep.GameOver;

            foreach (Player p in m_players.Values)
            {
                CmdResponse.EndGame(p);
            }
        }
Exemplo n.º 20
0
        public override void Start()
        {
            PrefabPool       = new PrefabPool();
            UIManager        = AddChild(new UIManager()) as UIManager;
            CoroutineManager = new GameObject("Coroutine Manager").AddComponent <CoroutineManager>(); // temp
            AsyncInvokeMng   = AddChild(new AsyncInvokeMng()) as AsyncInvokeMng;

            GameStep = GameStep.NotStart;
            UIManager.CreateUI <UIMain>();
        }
Exemplo n.º 21
0
        public void Calculate(GameStep step)
        {
            if (100 == PercentageCompleted)
            {
                return;
            }

            DoStep(step);
            CheckForCompletion();
        }
Exemplo n.º 22
0
        public void ToGame()
        {
            CurPlayer = 1;

            GameStep = GameStep.SelectingMain;
            foreach (Player p in m_players.Values)
            {
                CmdResponse.StartGame(p);
            }
        }
Exemplo n.º 23
0
 public void OnGrimoireReset()
 {
     CurrentStep = GameStep.RoleSelection;
     RoleSelectionManager.gameObject.SetActive(true);
     NightManager.gameObject.SetActive(false);
     RoleSelectionManager.BuildRoleList();
     NextButton.SetActive(true);
     PrevButton.SetActive(false);
     StepText.text = StepNames[(int)CurrentStep];
 }
Exemplo n.º 24
0
        // Do step: POST api/Game/<token> | BODY {"X": 0, "Y": 0}
        public bool PostDoStep(string token, [FromBody] GameStep step)
        {
            var currentGame = FindGame(token);

            if (currentGame == null)
            {
                return(false);
            }

            return(currentGame.Step(step));
        }
Exemplo n.º 25
0
        public void Restart()
        {
            m_curTargetHex    = null;
            m_singleTargetHex = null;
            m_mainHex         = null;
            HexManager.Restart();
            CurPlayer = 1;


            GameStep = GameStep.SelectingMain;
        }
Exemplo n.º 26
0
    public GameStep Step(GameStep step = null)
    {
        if (step != null && step.id != this.turn)
        {
            throw new Exception("Step count off\nawaiting:" + this.turn + ", incoming: " + step.id);
        }
        if (step == null)
        {
            step = new GameStep(this.turn, this.actions);
            this.steps.Add(step);
            this.actions = new List <GameAction>();
        }
        foreach (GameAction action in step.actions)
        {
            switch (action.type)
            {
            case GameActionType.BuyWorker:
                BuyWorker(action.player);
                break;

            case GameActionType.BuyUnit:
                BuyUnit(action);
                break;

            case GameActionType.Upgrade:
                Upgrade(action.player);
                break;

            case GameActionType.Nuke:
                Nuke(action.player);
                break;
            }
        }
        if (step.id % Game.SPAWN_RATE == 0)
        {
            Spawn();
        }
        if (step.id % Game.GOLD_RATE == 0)
        {
            GiveGold();
        }
        foreach (var projectile in this.projectiles)
        {
            projectile.Act();
        }
        foreach (var unit in this.units)
        {
            unit.Act();
        }
        this.CleanupUnits();
        this.CleanupProjectiles();
        this.turn++;
        return(step);
    }
Exemplo n.º 27
0
 private void InitLoop()
 {
     if (
         _player1.GetPlayerState() == PlayerState.READY &&
         _player2.GetPlayerState() == PlayerState.READY
         )
     {
         Debug.Log("Both Players Ready !");
         UIManager.GetInstance().HidePlayersButton();
         _currentGameStep = GameStep.LOOP;
     }
 }
Exemplo n.º 28
0
    // Lance la boule vers l'avant : dans le cas où un angle a été donné à la
    // boule, on veut également ajouter une force sur l'axe Z
    void Lancer()
    {
        var fw = mainCam.transform.forward;

        // on réactive la gravité sur la boule une fois qu'elle est lancée
        GetComponent <Rigidbody>().useGravity = true;
        GetComponent <Rigidbody>().AddForce(new Vector3(
                                                fw.x * 20000f,
                                                800f,
                                                fw.z * 20000f
                                                ));
        step = GameStep.мячкатится它很漂亮不是吗;
    }
Exemplo n.º 29
0
    public void OnStateEnter()
    {
        Debug.Log("IGameState Enter");
        GameObject go = new GameObject("Players");

        _player1 = go.AddComponent <Player>();
        _player2 = go.AddComponent <Player>();

        _player1.InitPlayer(1);
        _player2.InitPlayer(2);

        _currentGameStep = GameStep.INIT;
    }
Exemplo n.º 30
0
        protected override void DoStep(GameStep step)
        {
            if (GameStep.GameLost == step)
            {
                PercentageCompleted += 20;
                return;
            }

            if (GameStep.GameWon == step)
            {
                PercentageCompleted = 0;
            }
        }
Exemplo n.º 31
0
    void GameGraphGUI()
    {
        int newlySelectedBar = Graph.DrawAxisLabels(bars);
        if(newlySelectedBar >= 0){
            selectedBar = newlySelectedBar;
            uiScrollPosition = Vector2.zero;
        }

        StartLayout();

        GUILayout.BeginHorizontal();
        ShowScores();
        GUILayout.Space(30f);
        if(Event.current.type == EventType.Repaint){
            Graph.OffsetX = GUILayoutUtility.GetLastRect().xMax / Screen.width;
        }
        GUILayout.EndHorizontal();

        if (showingFullGraph) {
            GUILayout.Label("Showing all " + answers.Count);
            if (answers.Count > 100) {
                if (GUILayout.Button("Restrict to last 100")) {
                    bars = Bar.GetBars(answers, 100);
                    selectedBar = -1;
                    showingFullGraph = false;
                }
            }
        }
        else {
            GUILayout.Label("Showing last 100");
            if (GUILayout.Button("Show all " + answers.Count)) {
                bars = Bar.GetBars(answers, -1);
                selectedBar = -1;
                showingFullGraph = true;
            }
        }

        GUILayout.FlexibleSpace();
        GUILayout.Space(10f);
        if(Event.current.type == EventType.Repaint){
            Graph.Height = GUILayoutUtility.GetLastRect().yMax / Screen.height;
        }

        if((selectedBar >= 0) && (selectedBar < bars.Count)){
            Bar bar = bars[selectedBar];
            uiScrollPosition = GUILayout.BeginScrollView(uiScrollPosition);
            if(tutorialFinished){
                GUILayout.Label("Answers: " + bar.GetListOfConfidenceValues());
                GUILayout.Label("Average credence: " + bar.x.ToString("G3") + "%");
                GUILayout.Label("Actual success rate: " + bar.y.ToString("G3") + "%");
                GUILayout.Label("Average score: " + bar.scoreAverage);
                GUILayout.Label("Total points: " + bar.scoreSum);
            } else {
                GUILayout.Label("This bar represents your average credence and success rate on the " + bar.Count + " question" + (bar.Count > 1 ? "s" : "") + " where you answered " + bar.GetAnswerRange() + " " + bar.GetListOfConfidenceValues() + ". On those questions:");
                GUILayout.Label(bar.x.ToString("G3") + "% was your average credence, ");
                GUILayout.Label(bar.y.ToString("G3") + "% was your actual success rate, and ");
                GUILayout.Label(bar.scoreAverage + " was your average score. (Those answers are responsible for " + bar.scoreSum + " points.)");
                if(System.Math.Abs(bar.x - bar.y) <= Answer.CLOSE_ENOUGH){
                    GUILayout.Label("You seem to have been pretty well calibrated on those questions.  Well done!  Your average feeling of credence and actual success rate were fairly close.");
                } else if(bar.x < bar.y){
                    GUI.color = Color.cyan;
                    GUILayout.Label("You can probably improve this score, because you seem to have been under-confident on those questions. The arrow means that when you feel like answering " + bar.GetAnswerRange() + ", on average you can score more points if you adjust your credence upward by around " + bar.Adjustment.ToString("G3") + "%.");
                } else {
                    GUI.color = Color.magenta;
                    GUILayout.Label("You can probably improve this score, because you seem to have been over-confident on those questions. The arrow means that when you feel like answering " + bar.GetAnswerRange() + ", on average you can score more points if you adjust your credence downward by around " + bar.Adjustment.ToString("G3") + "%.");
                }
                GUILayout.Label("The yellow line shows the optimal bar height, i.e. the optimal success rate, for each credence level. Ideally, all your bars would be no higher or lower than this yellow line.");
            }
            GUILayout.EndScrollView();
            GUI.color = Color.white;
        } else {
            if(!tutorialFinished){
                GUILayout.Label("This graph will help you adjust your credence feeling toward your actual success rate, which will help you get more points.");
                GUILayout.Label(Click + " on the blue graph bar to see more information.");
            } else {
                GUILayout.Label(Click + " on a graph bar to see more information.");
            }
        }

        if(GUILayout.Button(tutorialFinished ? "CONTINUE" : "END TUTORIAL", GUILayout.ExpandWidth(true)) || HitValidateKey ()){
            GoToNextQuestion();
            if(!tutorialFinished){
                gameStep = GameStep.EndTutorial;
            }
        }
        EndLayout();
    }
Exemplo n.º 32
0
    void GameAnswerGUI()
    {
        StartLayout();

        bool viewGraphButton = answers.Count >= minAnswersForGraph && answers.Count % answersBetweenGraph == 0;

        GUILayout.BeginHorizontal();
        if(tutorialShowScore){
            ShowScores();
        }

        GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
        GUILayout.Box("QUESTION " + (questionCount + 1) + ": " + CurrentQuestion.m_questionText, GUILayout.ExpandWidth(true));
        GUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true));
        if(probOfCorrectAnswer == 50.0){
            GUI.contentColor = Color.black;
            GUI.backgroundColor = gaveCorrectAnswer ? Color.blue : Color.red;
            ScoreLabel("", "0", true);
            GUI.contentColor = Color.white;
            GUI.backgroundColor = Color.white;
            GUILayout.Label("You were " + (gaveCorrectAnswer ? "correct" : "incorrect") + ", but since you answered 50%, you don't " + (gaveCorrectAnswer ? "receive" : "lose") + " any points.\n" + (gaveCorrectAnswer ? CurrentQuestion.m_correctResponse : CurrentQuestion.m_wrongResponse));
        } else if(!gaveCorrectAnswer){
            GUI.contentColor = Color.black;
            GUI.backgroundColor = Color.red;
            ScoreLabel("", "" + PointsReceived, true);
            GUI.contentColor = Color.white;
            GUI.backgroundColor = Color.white;
            GUILayout.Label("Incorrect. " + CurrentQuestion.m_wrongResponse);

        } else {
            GUI.contentColor = Color.black;
            GUI.backgroundColor = Color.blue;
            ScoreLabel("", "+" + PointsReceived, true);
            GUI.contentColor = Color.white;
            GUI.backgroundColor = Color.white;
            GUILayout.Label("Correct! " + CurrentQuestion.m_correctResponse);
        }

        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        if(!tutorialShowScore){
            GUILayout.Label("Points are awarded based on the following table. Note that you lose a lot of points if you are very confident in the wrong answer.");
            GuiScoringTable(true);
            GUILayout.Label("Remember, your goal is to get as many points as you can.");
        }

        GUILayout.FlexibleSpace();

        if(tutorialFinished && !viewGraphButton){
            GUIEx.RightAligned(() => {
                GUILayout.BeginHorizontal("box");
                ViewGraphButton(false, false);
                if(GUILayout.Button("OPTIONS")){
                    gameStep = GameStep.Options;
                }
                if(GUILayout.Button("QUIT")) {
                    Application.Quit();
                }
                GUILayout.EndHorizontal();
            });
        }

        if(viewGraphButton){
            // Display a full-width "view graph" button
            ViewGraphButton(true, HitValidateKey());
        } else if (tutorialFinished || !SecondTutorialQuestion) {
            if(GUILayout.Button("NEXT QUESTION", GUILayout.ExpandWidth(true)) || HitValidateKey()){
                GoToNextQuestion();
            }
        } else {
            if(GUILayout.Button("OKAY, GET MORE POINTS. GOT IT.", GUILayout.ExpandWidth(true)) || HitValidateKey()){
                gameStep = GameStep.ExplainScores;
            }
        }

        EndLayout();
    }
Exemplo n.º 33
0
    void GameEndTutorialGUI()
    {
        StartLayout();

        GUILayout.Label("This is it! Remember, here is how you are scored on your answers:");
        GuiScoringTable(true);
        GUILayout.Label("The best strategy is to sincerely indicate how confident you are in your answer, and then adjust based on the graph the game will show you!");
        GUILayout.Label("\nGood luck and have fun!");

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        if(GUILayout.Button("NEXT QUESTION", GUILayout.ExpandWidth(true)) || HitValidateKey()){
            SetTutorialStatus(true);
            SaveGame();
            gameStep = GameStep.Question;
        }
        GUI.color = new Color(1f, 0.5f, 0.5f);
        if(GUILayout.Button("MORE DETAILS")){
            SetTutorialStatus(true);
            SaveGame();
            gameStep = GameStep.Question;
            uiIntructionsPage = 0;
            uiShowAllInstructions = true;
            uiScrollPosition = Vector2.zero;
        }
        GUI.color = Color.white;
        GUILayout.EndHorizontal();
        EndLayout();
    }
Exemplo n.º 34
0
    void AddingNewDatabaseGUI()
    {
        StartLayout();

        GUILayout.Label("NEW DATABASE", WelcomeStyle);
        GUILayout.Space(15f);
        GUILayout.Label("URL:");
        QuestionDatabase.newDatabaseUrl = GUILayout.TextField(QuestionDatabase.newDatabaseUrl, GUILayout.ExpandWidth(true));
        if(QuestionDatabase.loadingDatabases){
            GUILayout.Label("Progress: " + (int)(QuestionDatabase.AddingProgress * 100f) + "%");
        } else if(GUILayout.Button("ADD")){
            StartCoroutine(QuestionDatabase.TryToAddNewDatabase());
        }

        GUILayout.FlexibleSpace();

        GUILayout.Label(QuestionDatabase.resultLog, NoteStyle);
        GUI.enabled = !QuestionDatabase.loadingDatabases;
        if(GUILayout.Button("BACK")){
            gameStep = GameStep.QuestionDatabases;
        }
        GUI.enabled = true;

        EndLayout();
    }
Exemplo n.º 35
0
    void Awake()
    {
        singleton = this;
        reverseOptions = Random.value >= 0.5f;

        if(!Application.isWebPlayer){
            if(File.Exists(SaveGameFilename)){
                LoadGame();
            } else {
                SaveGame();
            }
        }
        //SetTutorialStatus(false);

        if(tutorialFinished) gameStep = GameStep.Question;
        Application.targetFrameRate = 60;
    }
Exemplo n.º 36
0
 void Update()
 {
     if(gameStep == GameStep.DownloadingDatabases && QuestionDatabase.justLoadedDatabases){
         QuestionDatabase.justLoadedDatabases = false;
         gameStep = GameStep.QuestionDatabases;
     }
     if(gameStep == GameStep.AddingNewDatabase && QuestionDatabase.justLoadedDatabases){
         QuestionDatabase.justLoadedDatabases = false;
         gameStep = GameStep.QuestionDatabases;
     }
     if (updatedStep != gameStep)
     {
         updatedStep = gameStep;
         nextHighlightedKey = "";
     }
     highlightedKey = nextHighlightedKey;
 }
Exemplo n.º 37
0
 void ViewGraphButton(bool expandButton, bool isKeyPressed)
 {
     if(GUILayout.Button("VIEW GRAPH", GUILayout.ExpandWidth(expandButton)) || isKeyPressed){
         selectedBar = -1;
         bars = Bar.GetBars(answers, -1);
         gameStep = GameStep.Graph;
         showingFullGraph = true;
     }
 }
Exemplo n.º 38
0
 void Update()
 {
     if(gameStep == GameStep.DownloadingDatabases && QuestionDatabase.Progress >= 1f){
         gameStep = GameStep.QuestionDatabases;
     }
 }
Exemplo n.º 39
0
    void QuestionDatabasesGUI()
    {
        StartLayout();

        GUILayout.Label("QUESTION DATABASES", WelcomeStyle);

        if(gameStep == GameStep.DownloadingDatabases){
            GUILayout.Label("Download progress: " + (int)(QuestionDatabase.Progress * 100f) + "%");
        } else {
            uiScrollPosition = GUILayout.BeginScrollView(uiScrollPosition);
            if(GUILayout.Button("ADD NEW DATABASE")){

            }
            foreach(QuestionDatabase database in QuestionDatabase.databases){
                GUILayout.BeginHorizontal();
                GUI.enabled = database.downloaded;
                database.used = GUILayout.Toggle(database.used, database.name);
                GUI.enabled = true;
                GUILayout.Label("(" + database.url + ")", NoteStyle);
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            GUILayout.Space(15f);

            GUILayout.BeginHorizontal();
            if(GUILayout.Button("UPDATE ALL")){
                StartCoroutine_Auto(QuestionDatabase.LoadDatabasesFromUrls());
                gameStep = GameStep.DownloadingDatabases;
            }
            if(QuestionDatabase.resultLog != null){
                GUILayout.Label(QuestionDatabase.resultLog, NoteStyle);
            }
            GUILayout.EndHorizontal();

            GUI.enabled = QuestionDatabase.databases.Exists(db => db.used);
            if(GUILayout.Button("BACK")){
                QuestionDatabase.SaveDatabases();
                QuestionDatabase.resultLog = null;
                QuestionsScript.singleton.RegenerateQuestions();
                gameStep = GameStep.Options;
            }
            GUI.enabled = true;
        }

        EndLayout();
    }
Exemplo n.º 40
0
Arquivo: Game.cs Projeto: ZuTa/Othello
        private void VerifyStep()
        {
            Message = string.Empty;

            if (!CanDoNextStep(step))
            {
                GameStep tmp = (GameStep)(((int)step + 1) % countStep);
                if (!CanDoNextStep(tmp))
                {
                    string winner = nameOfPlayer1;
                    if (CountBlueBalls > CountRedBalls)
                        winner = nameOfPlayer2;
                    Message = string.Format("Game is over! {0} wins", winner);
                    Stop();
                }
                else
                {
                    Message = string.Format("{0} loses turn.", step.ToString());
                    Step = tmp;
                }
            }

            if (step == GameStep.Blue && style == GameStyle.Single)
                DoComputerStep();
        }
Exemplo n.º 41
0
 void ViewGraphButton(bool expandButton)
 {
     if(GUILayout.Button("VIEW GRAPH", GUILayout.ExpandWidth(expandButton))){
         selectedBar = -1;
         bars = Bar.GetBars(answers);
         gameStep = GameStep.Graph;
     }
 }
Exemplo n.º 42
0
Arquivo: Game.cs Projeto: ZuTa/Othello
        private void Stop()
        {
            Step = GameStep.None;
            IsFinished = true;

            if (OnGameFinished != null)
                OnGameFinished(this);
        }
Exemplo n.º 43
0
 void GoToNextQuestion()
 {
     questionCount++;
     currentQuestion++;
     reverseOptions = Random.value >= 0.5f;
     tutorialAnsweredOneQuestion = true;
     gameStep = GameStep.Question;
 }
Exemplo n.º 44
0
    void QuestionTypesGUI()
    {
        StartLayout();

        GUILayout.Label("QUESTION TYPES", WelcomeStyle);

        uiScrollPosition = GUILayout.BeginScrollView(uiScrollPosition);
        bool tagsChanged = false;

        GUILayout.BeginHorizontal();
        GUILayout.Label("Set everything to:");
        if(GUILayout.Button("None", TagButtonStyle)){
            foreach(string tag in QuestionsScript.tags.Keys) QuestionsScript.tags[tag] = TagUsage.None;
            tagsChanged = true;
        }
        if(GUILayout.Button("Some", TagButtonStyle)){
            foreach(string tag in QuestionsScript.tags.Keys) QuestionsScript.tags[tag] = TagUsage.Some;
            tagsChanged = true;
        }
        if(GUILayout.Button("All", TagButtonStyle)){
            foreach(string tag in QuestionsScript.tags.Keys) QuestionsScript.tags[tag] = TagUsage.All;
            tagsChanged = true;
        }
        GUILayout.EndHorizontal();
        GUILayout.Label("(A question will be asked iff all its tags are set to Some or at least one of its tags is set to All.)", NoteStyle);

        foreach(string tag in QuestionsScript.tags.Keys){
            GUILayout.BeginHorizontal();
            bool hasSubTag = QuestionsScript.HasSubTag(tag);
            bool parentSetToAll = false;
            string tagName = tag;
            if(hasSubTag){
                GUILayout.Space(30f);
                tagName = QuestionsScript.GetChildTag(tag);
                parentSetToAll = QuestionsScript.tags[QuestionsScript.GetParentTag(tag)] == TagUsage.All;
            }
            if(parentSetToAll){
                GUILayout.Label("All");
            } else {
                TagUsage oldValue = QuestionsScript.tags[tag];
                if(GUILayout.Button(oldValue.ToString(), TagButtonStyle)){
                    QuestionsScript.tags[tag] = (TagUsage)(((int)oldValue + 1) % (int)TagUsage.COUNT);
                }
                tagsChanged |= oldValue != QuestionsScript.tags[tag];
            }

            GUILayout.Label(tagName);
            GUILayout.EndHorizontal();
        }
        if(tagsChanged){
            QuestionsScript.singleton.UpdateQuestionGenerators();
        }
        GUILayout.EndScrollView();

        GUILayout.Space(15f);

        GUILayout.BeginHorizontal();
        if(GUILayout.Button("BACK")){
            SaveGame();
            currentQuestion = -1;
            QuestionsScript.singleton.RegenerateQuestions();
            gameStep = GameStep.Options;
        }
        GUILayout.Label("Data tables available: " + QuestionsScript.generators.FindAll(generator => generator.m_active).Count + "/" + QuestionsScript.generators.Count, GUILayout.ExpandHeight(true));
        GUILayout.EndHorizontal();

        EndLayout();
    }
Exemplo n.º 45
0
    void OptionsGUI()
    {
        StartLayout();

        GUILayout.Label("OPTIONS", WelcomeStyle);
        if(GUILayout.Button("QUESTION DATABASES")){
            deleteUnselectedConfirmation = false;
            uiScrollPosition = Vector2.zero;
            QuestionsScript.singleton.StopGeneratingQuestions();
            gameStep = GameStep.QuestionDatabases;
        }
        if(GUILayout.Button("QUESTION TYPES")){
            uiScrollPosition = Vector2.zero;
            gameStep = GameStep.QuestionTypes;
        }
        if(GUILayout.Button("REDO TUTORIAL")){
            GoToNextQuestion();
            SetTutorialStatus(false);
            uiIntructionsPage = -1;
            gameStep = GameStep.Start;
        }
        if(GUILayout.Button("GAME INFO")){
            uiScrollPosition = Vector2.zero;
            uiShowAllInstructions = true;
            uiIntructionsPage = 0;
        }
        GUI.color = new Color(1f, 0.5f, 0.5f);
        if(GUILayout.Button("RESTART GAME")){
            restartingGame = true;
        }
        GUI.color = Color.white;

        GUILayout.FlexibleSpace();

        if(GUILayout.Button("BACK")){
            GoToNextQuestion();
        }

        EndLayout();
    }
Exemplo n.º 46
0
 /// <summary>
 /// The player picked an answer.
 /// </summary>
 /// <param name='probability'>Probability given by the player to answer A.</param>
 void GiveAnswer(double probability, bool correct)
 {
     gaveCorrectAnswer = correct;
     probOfCorrectAnswer = gaveCorrectAnswer ? probability : 100.0 - probability;
     totalScore += PointsReceived;
     averageScore = (PointsReceived + averageScore * answers.Count) / (double)(answers.Count + 1);
     answers.Add(new Answer(probability, gaveCorrectAnswer, PointsReceived));
     SaveGame();
     gameStep = GameStep.Answer;
 }
Exemplo n.º 47
0
 void GoToNextQuestion()
 {
     questionCount++;
     currentQuestion++;
     reverseOptions = Random.value >= 0.5f;
     tutorialAnsweredOneQuestion = true;
     gameStep = GameStep.Question;
     // Reinit keyboard shortcuts
     highlightedKey = "";
 }
Exemplo n.º 48
0
Arquivo: Game.cs Projeto: ZuTa/Othello
 /*
 private void cellControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     CellControl c = (CellControl)sender;
     DoStepStuff(c);
 }
  */
 public void DoStepStuff(CellControl c)
 {
     if (c.Ball == ImageBalls.None && !IsFinished)
     {
         bool result = false;
         switch (step)
         {
             case GameStep.Red:
                 result = DoStepStuff(c, ImageBalls.RedBall);
                 break;
             case GameStep.Blue:
                 result = DoStepStuff(c, ImageBalls.BlueBall);
                 break;
             default:
                 break;
         }
         if (result)
         {
             Step = (GameStep)(((int)step + 1) % countStep);
             VerifyStep();
         }
     }
 }
Exemplo n.º 49
0
    void QuestionDatabasesGUI()
    {
        StartLayout();

        GUILayout.Label("QUESTION DATABASES", WelcomeStyle);

        uiScrollPosition = GUILayout.BeginScrollView(uiScrollPosition);
        if(GUILayout.Button("ADD NEW DATABASE")){
            QuestionDatabase.resultLog = "";
            deleteUnselectedConfirmation = false;
            gameStep = GameStep.AddingNewDatabase;
        }
        foreach(QuestionDatabase database in QuestionDatabase.databases){
            GUILayout.BeginHorizontal();
            GUI.enabled = database.downloaded;
            database.used = GUILayout.Toggle(database.used, database.name);
            GUI.enabled = true;
            GUILayout.Label("(" + database.url + ")", NoteStyle);
            GUILayout.EndHorizontal();
        }
        GUILayout.EndScrollView();

        GUILayout.Space(15f);

        if(deleteUnselectedConfirmation){
            GUILayout.Label("Are you sure you want to delete ALL unselected databases? You can't undo this.");
        } else if(QuestionDatabase.resultLog != null){
            GUILayout.Label(QuestionDatabase.resultLog, NoteStyle);
        }

        GUILayout.BeginHorizontal();

        if(GUILayout.Button("BACK")){
            deleteUnselectedConfirmation = false;
            currentQuestion = -1;
            QuestionDatabase.resultLog = null;
            QuestionDatabase.SaveDatabases();
            QuestionsScript.singleton.LoadAllQuestions();
            QuestionDatabase.SaveDatabases();//save again, in case some databases failed to load
            gameStep = GameStep.Options;
        }

        GUILayout.FlexibleSpace();

        if(GUILayout.Button("UPDATE ALL")){
            deleteUnselectedConfirmation = false;
            StartCoroutine_Auto(QuestionDatabase.LoadDatabasesFromUrls());
            gameStep = GameStep.DownloadingDatabases;
        }

        GUILayout.FlexibleSpace();

        if(GUILayout.Button("DELETE UNSELECTED")){
            if(deleteUnselectedConfirmation){
                QuestionDatabase.RemoveUnselectedDatabases();
            }
            deleteUnselectedConfirmation = !deleteUnselectedConfirmation;
        }

        GUILayout.EndHorizontal();

        EndLayout();
    }
Exemplo n.º 50
0
Arquivo: Game.cs Projeto: ZuTa/Othello
        private bool CanDoNextStep(GameStep step)
        {
            ImageBalls ball = ImageBalls.None;
            switch (step)
            {
                case GameStep.Red:
                    ball = ImageBalls.RedBall;
                    break;
                case GameStep.Blue:
                    ball = ImageBalls.BlueBall;
                    break;
                default:
                    break;
            }
            bool result= false;

            foreach (CellControl cell in cellCollection)
            {
                if (cell.Ball == ImageBalls.None && GetValidCells(cell, ball).Count > 0)
                {
                    result = true;
                    break;
                }
            }

            return result;
        }
Exemplo n.º 51
0
    void StartGameGUI()
    {
        StartLayout();

        if(!tutorialFinished && uiIntructionsPage < 0){
            if(uiIntructionsPage == -2){
                GUILayout.FlexibleSpace();
                GUIEx.Centered(() => GUILayout.Label(cfarTexture, WelcomeStyle));
                GUILayout.Space(20f);
                GUIEx.Centered(() => GUILayout.Label("Welcome to the Credence Game!", WelcomeStyle));
                GUIEx.Centered(() => GUILayout.Label("Send bugs and comments to [email protected]", NoteStyle));
                GUILayout.FlexibleSpace();
                GUIEx.Centered(() => {
                    if(GUILayout.Button("LET'S START WITH A TUTORIAL!")){
                        uiIntructionsPage++;
                    }
                });
                GUIEx.Centered(() => {
                    GUI.color = new Color(1f, 0.5f, 0.5f);
                    if(GUILayout.Button("SKIP TUTORIAL")){
                        SetTutorialStatus(true);
                        SaveGame();
                        gameStep = GameStep.Question;
                    }
                    GUI.color = Color.white;
                });
                GUILayout.FlexibleSpace();
            } else if(uiIntructionsPage == -1){
                GUILayout.Label("In this game you will be asked a series of questions. For example:");
                GuiQuestionBox(CurrentQuestion.m_questionText);
                GUILayout.Label("Each answer will have two options:");
                GuiAnswersBox(CurrentQuestion.m_correctAnswerText, CurrentQuestion.m_wrongAnswerText);
                GUILayout.Label("You'll have to pick what answer you think is correct. Moreover, you'll have to specify how confident you are in your answer.");
                GUILayout.Label("If you answer the question correctly, you will gain points. If you answer the question incorrectly, you will lose points.");
                GUILayout.Space(20f);
                GUILayout.Label("Your goal is to get as many points as you can.");

                GUILayout.FlexibleSpace();

                if(GUILayout.Button("LET'S DO THIS!", GUILayout.ExpandWidth(true)) || HitValidateKey ()){
                    gameStep = GameStep.Question;
                }
            }
        } else if(uiIntructionsPage >= 0){
            uiScrollPosition = GUILayout.BeginScrollView(uiScrollPosition);
            if(uiIntructionsPage == 0){
                GUILayout.Label("Welcome to the Credence Game, where information is the goal and credence calibration is how you improve!");
                GUILayout.Label("What happens: You answer a series of two-choice questions, and indicate a credence level between 50% and 99% for each answer.");
                GUILayout.Label("Your objective: To earn something called an 'information score', measured in 'centibits', which are simply points awarded by the following rule:");

                GuiScoringTable(false);

                GUILayout.Label("The optimal strategy: on each question, sincerely indicate how confident you are in your answer!");
                GUILayout.Label("How to improve: By calibrating your credence level!  We will regularly give you feedback about whether you are overconfident or underconfident in your answers, and adjusting your credence levels accordingly will improve your average score.");

                GUILayout.Label("Don't forget, the goal of the game is to earn points.  The calibration statistics are just feedback to help you do better.  If calibration were your only goal, you could just click 50% all the time and be perfectly calibrated!  But then you wouldn't be any more informative than a coin flip.  That's why the goal is to earn points, and we carefuly chose our scoring rule so that calibration would be your best way of doing that (trust us!).");
            } else if(uiIntructionsPage == 1) {
                GUILayout.Label("Score = round(100 * (log2(percent_probability_of_correct_answer / 100) + 1))");
                GuiScoringTable(false);
                //Note: you can think of it in terms of surprise or adjustment you'll have to make
                GUILayout.Label("Why these numbers?  Your score is the amount of information you've provided, in centibits, or hundreths of a bit.  Giving a correct, 100% confident answer to a two-choice question is providing 1 bit of information, or 100 centibits.  Giving an 80% confident right answer is giving 68 centibits of information because 80% = 2^(0.68)*50%, i.e. you are doing 2^(0.68) times better than a coin flip.  Giving an 80% confident wrong answer is giving -132 centibits of information because 20% = 2^(-1.32)*50%, i.e. you are doing 2^(1.32) times worse than a coin flip.");
                GUILayout.Label("\nIt's a theorem that giving points in this way makes giving your sincere credence levels the best strategy to maximize your expected score, and that calibrating your credence levels to your actual success rates will improve your performance!");
                //GUILayout.Label("If you would like to understand why the numbers above are really the exact, information-theoretic amounts of information each credence level provides, check out our web tutorial on [information scoring](link).");
            } else {
                GUILayout.Label("CREDITS");
                GUILayout.Label("\nProgramming:");
                GUILayout.Label("(Send bugs and comments to this guy.)");
                GUILayout.Label("Alexei Andreev ([email protected])");
                GUILayout.Label("See: appliedrationality.org");
                GUILayout.Label("\nDesign:");
                GUILayout.Label("Andrew Critch ([email protected])");
                GUILayout.Label("See: math.berkeley.edu/~critch/");
                GUILayout.Label("\nQuestions database (created from Wikipedia pages):");
                GUILayout.Label("Andrew Critch and Zachary Aletheia");
            }
            GUILayout.EndScrollView();

            GUILayout.FlexibleSpace();

            bool backToGame = !uiShowAllInstructions || uiIntructionsPage == 2;
            if(GUILayout.Button(backToGame ? "BACK TO THE GAME" : (uiIntructionsPage == 0 ? "EXPLAIN SCORING SYSTEM" : "CREDITS"), GUILayout.ExpandWidth(true))){
                if(backToGame){
                    uiShowAllInstructions = false;
                    uiIntructionsPage = -2;
                } else {
                    uiScrollPosition = Vector2.zero;
                    uiIntructionsPage++;
                }
            }
        }

        EndLayout();
    }
Exemplo n.º 52
0
Arquivo: Game.cs Projeto: ZuTa/Othello
        private void SetDefault()
        {
            this.IsFinished = false;
            Step = GameStep.Red;

            int x = ((int)level / 2) - 1;
            cellCollection[x * (int)level + x + 1].Ball = cellCollection[(x + 1) * (int)level + x].Ball = ImageBalls.RedBall;
            cellCollection[x * (int)level + x].Ball = cellCollection[(x + 1) * (int)level + x + 1].Ball = ImageBalls.BlueBall;

            CountRedBalls = 2;
            CountBlueBalls = 2;
        }