Esempio n. 1
0
        public Player(GameHooks.Emulator emulator, Scene scene)
        {
            this.emulator = emulator;
            activeScene   = scene;
            scorePerAct   = new double[scene.ActAmount];

            stateCallbacks[State.INITIALIZING] = delegate()
            {
                OnInitializing();
            };
            stateCallbacks[State.READY] = delegate()
            {
                OnReady();
            };
            stateCallbacks[State.RUNNING] = delegate()
            {
                OnRunning();
            };
            stateCallbacks[State.ERROR] = delegate()
            {
                OnError();
            };

            updateCoroutine = Task.Run(async() => {
                do
                {
                    Update();
                    await Task.Delay(17);
                } while (true);
            });
        }
Esempio n. 2
0
        private void OnRunning()
        {
            UpdateActScore();
            if (HasLost())
            {
                currentState = State.READY;
                LaunchGame();
                return;
                // @TODO: reduce life
            }

            if (HasWon())
            {
                // Try to finish this act...
                if (activeScene.FinishAct() == -1)
                {
                    // ... either there are no acts left
                    emulator = null;
                    Helper.WinAPI.SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
                    MessageBox.Show(string.Format("Current score: {0}", scorePerAct.Sum()), "Game completed!", MessageBoxButton.OK);
                    Environment.Exit(0);
                    // @TODO: Submit high-score
                }
                else
                {
                    // ... or we proceed to next game
                    nextGame     = activeScene.CurrentAct.Game;
                    currentState = State.READY;
                    LaunchGame();
                }

                return;
            }
        }
Esempio n. 3
0
        public bool IsFulfilled(GameHooks.Game game, GameHooks.Emulator emulator)
        {
            Debug.Assert(memoryStates.Length > 0, "No memory states available!", "IsFulfilled was called, but no memory states are defined! This is undefined behavior!");
            byte value = 0x00;

            foreach (MemoryState memoryState in memoryStates)
            {
                value = game.GetMemoryArea(memoryState.Area).GetByte(emulator);
                bool?statePassed = null;
                switch (memoryState.ComparisonOperator)
                {
                case "<":
                    statePassed = value < Convert.ToInt32(memoryState.Value);
                    break;

                case "<=":
                    statePassed = value <= Convert.ToInt32(memoryState.Value);
                    break;

                case ">":
                    statePassed = value > Convert.ToInt32(memoryState.Value);
                    break;

                case ">=":
                    statePassed = value >= Convert.ToInt32(memoryState.Value);
                    break;

                case "==":
                    statePassed = value == Convert.ToInt32(memoryState.Value);
                    break;
                }

                Debug.Assert(statePassed != null,
                             "Invalid comparision operator used; '{0}' is not supported (Comparing field {1} with value {2})",
                             memoryState.ComparisonOperator,
                             memoryState.Area,
                             memoryState.Value
                             );

                if (!statePassed.HasValue)
                {
                    break;
                }

                if (logicGate == "OR" && statePassed.Value)
                {
                    return(true);
                }

                if (logicGate == "AND" && !(statePassed.Value))
                {
                    return(false);
                }
            }

            return(true);
        }