Пример #1
0
        /// <summary>
        /// Processes given event
        /// </summary>
        /// <param name="ev">Event to process</param>
        public void ProcessEvent(Event e)
        {
            // for events that are not handled by plugins

            if (e.what == EventType.gameWon)
            {
                if (GameChanged != null)
                {
                    GameChanged(gameDisplayType, GameChange.Won);
                }
            }
            else if (e.what == EventType.stopCountingTime)
            {
                if (GameChanged != null)
                {
                    GameChanged(gameDisplayType, GameChange.StopCountingTime);
                }
            }
            else if (e.what == EventType.gameLost)
            {
                if (GameChanged != null)
                {
                    GameChanged(gameDisplayType, GameChange.Lost);
                }
            }
            else if (e.what == EventType.restartGame)
            {
                if (GameChanged != null)
                {
                    GameChanged(gameDisplayType, GameChange.Restart);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="time"></param>
        /// <param name="ev"></param>
        /// <returns>What GamePlugin was moved; if none then null</returns>
        public IGamePlugin ProcessGoEvent(Int64 time, Event ev)
        {
            if (!host.IsSimulationActive) return null;

            IGamePlugin result = null;
            // TODO: It's not possible to move object if there's something behind it

            MovementDirection md = EventType2MovementDirection(ev.what);

            // posX and posY are one-based!!!
            int nextFieldX = CoordinationOfMovementDirectionX(posX, md);
            int nextFieldY = CoordinationOfMovementDirectionY(posY, md);

            bool isThereWall = this.isThereWall(nextFieldX, nextFieldY);
            IGamePlugin obstructionGp = null;

            if (isThereWall == false)
            {
                IGamePlugin gp = host.GetObstructionOnPosition(nextFieldX, nextFieldY);

                if (gp as IFixedElement != null)
                {
                    isThereWall = true;
                }
                else
                {
                    obstructionGp = gp;
                }
            }

            // No wall and no other game object; just move my object
            if (isThereWall == false && obstructionGp == null)
            {
                PrepareMovement(ev.when, 0, (IGamePlugin)ev.who, ev.what);
            }
            else if (isThereWall == false && ((IMovableElement)obstructionGp).ObstructionLevel(thisGamePlugin) == -1)
            {
                PrepareMovement(ev.when, 0, (IGamePlugin)ev.who, ev.what);
                result = obstructionGp;
            }
            // No wall and object can be moved
            else if (isThereWall == false && 
                this.ObstructionLevel(obstructionGp) > ((IMovableElement)obstructionGp).ObstructionLevel(thisGamePlugin))
            {
                int nextNextX = CoordinationOfMovementDirectionX(nextFieldX, md);
                int nextNextY = CoordinationOfMovementDirectionY(nextFieldY, md);

                // Cannot move the object because behind the object is border of maze
                if (this.isThereWall(nextNextX, nextNextY))
                {
                    planHittingWall("PGE-WallBehindObj", ev.when, ev.who); // ev.who = this plugin
                }
                else
                {
                    IGamePlugin gp2 = host.GetObstructionOnPosition(nextNextX, nextNextY);

                    // there's no obstruction behind object obstructionGp
                    if (gp2 == null)
                    {
                        PrepareMovement(ev.when, 0, ev.who, ev.what);

                        int speed = ((IMovableElement)obstructionGp).Speed;
                        // Lend obstructionGp speed of ev.who
                        if (speed <= 0)
                        {
                            speed = ((IMovableElement)ev.who).Speed;
                            ((IMovableElement)obstructionGp).Speed = -speed;
                        }
                        PrepareMovement(ev.when, 0, obstructionGp, ev.what, speed);
                        result = obstructionGp;
                    }
                    else
                    {
                        planHittingWall("PGE-ObstrBehindObj", ev.when, ev.who); // ev.who = this plugin
                    }
                }
            }
            // Is there wall or object cannot be moved
            else
            {
                planHittingWall("PGE-Wall", ev.when, ev.who);
            }

            return result;
        }
Пример #3
0
        public bool ProcessEvent(Int64 time, Event ev)
        {
            bool returnValue = false;

            switch (ev.what)
            {
                case EventType.goRight:
                case EventType.goLeft:
                case EventType.goUp:
                case EventType.goDown:

                    ProcessGoEvent(time, ev);

                    returnValue = true;
                    break;

                case EventType.wentRight:
                case EventType.wentLeft:
                case EventType.wentUp:
                case EventType.wentDown:

                    #region wentXXX

                    movementEventsInBuffer--;
                    if (immediatelyOccupyNewField == false)
                    {
                        ((IMovableElement)ev.who).FinishMove((MovementDirection)(ev.what - 10));
                    }

                    returnValue = true;
                    break;

                    #endregion wentXXX


                case EventType.hitToTheWall:

                    return false;
       
                default:
                    returnValue = false;
                    break;
            }

            return returnValue;
        }
Пример #4
0
        public new bool ProcessEvent(Int64 time, Event ev)
        {
            bool returnValue = false;

            switch (ev.what)
            {
                case EventType.goRight:
                case EventType.goLeft:
                case EventType.goUp:
                case EventType.goDown:

                    if (!host.IsSimulationActive) return true;

                    base.SetOrientation(ev.what);

                    DebuggerIX.WriteLine(DebuggerTag.SimulationNotableEvents, "[Sokoban] ProcessEvent", ev.what.ToString() + "; Raised from EventID: " + ev.EventID.ToString());
                    DebuggerIX.WriteLine(DebuggerTag.SimulationNotableEvents, "", "[Sokoban]" + ev.ToString());

                    IGamePlugin obstruction = base.ProcessGoEvent(time, ev);

                    if (obstruction != null && obstruction.Name == "Box")
                    {
                        this.host.GameVariant.CheckRound(time, "BoxMoved", null);
                    }

                    this.host.GameVariant.CheckRound(time, "SokobanMoved", null);

                    returnValue = true;

                    break;

                case EventType.wentRight:
                case EventType.wentLeft:
                case EventType.wentUp:
                case EventType.wentDown:

                    #region wentXXX

                    base.ProcessEvent(time, ev);

                    DebuggerIX.WriteLine(DebuggerTag.SimulationNotableEvents, "[Sokoban]", "Key buffer: " + movementEventsInBuffer.ToString() +
                        " / " + MAX_EVENTS_IN_KB.ToString());

                    if (heldKeyEvent != EventType.none && movementEventsInBuffer == 0 && timeWholeMovementEnds <= time)
                    {
                        EventType newEvent = heldKeyEvent;
                        DebuggerIX.WriteLine(DebuggerTag.SimulationNotableEvents, "[Sokoban]", "Raised from EventID = " + ev.EventID.ToString());
                        base.MakePlan("SokRepMvmt", ev.when, ev.who, newEvent);
                    }

                    returnValue = true;
                    break;

                    #endregion wentXXX

                case EventType.hitToTheWall:

                    return processHitToWall();

                default:
                    returnValue = base.ProcessEvent(time, ev);
                    break;
            }

            return returnValue;
        }
Пример #5
0
 public new bool ProcessEvent(Int64 time, Event ev)
 {
     return true; // TODO
 }
Пример #6
0
 public bool ProcessEvent(long time, Event e)
 {
     return true;
 }
Пример #7
0
 public new bool ProcessEvent(Int64 time, Event ev)
 {
     return base.ProcessEvent(time, ev);
 }
Пример #8
0
        private void ProcessPursuitEvent(long time, Event ev)
        {
            if (this.wave == null) wave = new int[fieldsX, fieldsY];
            if (this.waveQueue == null) waveQueue = new ArrayList(50);

            for (int j = 0; j < fieldsY; j++)
            {
                for (int i = 0; i < fieldsX; i++)
                {
                    wave[i, j] = -1;
                }
            }

            wave[this.posX - 1, this.posY - 1] = 0; // start
            waveQueue.Clear();
            waveQueue.Add(new Coordinate(this.posX, this.posY));

            int g = 0;
            int akt = 0;
            // One-based values
            int pSx = sokoban.PosX;
            int pSy = sokoban.PosY;

            while (g < waveQueue.Count)
            {
                Coordinate tmp = (Coordinate)waveQueue[g];
                akt = wave[tmp.x - 1, tmp.y - 1];

                if (tmp.x == pSx && tmp.y == pSy)
                {
                    break;
                }

                for (int t = 0; t < 4; t++)
                {
                    int newX = tmp.x + moves[2 * t];
                    int newY = tmp.y + moves[2 * t + 1];
                    IGamePlugin obstruction = host.GetObstructionOnPosition(newX, newY);

                    if (obstruction == null || obstruction.Name == "Sokoban")
                    {
                        if (wave[newX - 1, newY - 1] == -1)
                        {
                            wave[newX - 1, newY - 1] = akt + 1; // start
                            waveQueue.Add(new Coordinate(newX, newY));
                        }
                    }
                }
                g++;
            }

            waveQueue.Clear();

            // REKONSTRUKCE CESTY
            // ================================================================================
            akt = wave[pSx - 1, pSy - 1];

            if (akt > -1) // akt == -1 znaci, ze neexistuje cesta k sokobanovi
            {
                Random rndNum = new Random();

                while (wave[pSx - 1, pSy - 1] != 1)
                {

                    if (wave[pSx - 1, pSy - 1] < 1)
                    {
                        break;
                    }

                    int[] tmpSmery = new int[] { 0, 1, 2, 3 };
                    int xTmpSmery = 3;

                    for (int u = 0; u < 4; u++)
                    {
                        int nahodne = rndNum.Next(0, xTmpSmery);
                        int t = tmpSmery[nahodne];
                        tmpSmery[nahodne] = tmpSmery[xTmpSmery];
                        xTmpSmery--;

                        int newX = pSx + moves[2 * t];
                        int newY = pSy + moves[2 * t + 1];

                        if (newX - 1 >= 0 && newY - 1 >= 0 &&
                            newX - 1 < fieldsX && newY - 1 < fieldsY &&
                            wave[newX - 1, newY - 1] < akt && wave[newX - 1, newY - 1] != -1)
                        {
                            pSx = newX;
                            pSy = newY;
                            akt = wave[newX - 1, newY - 1];
                            break;
                        }
                    }
                }
            }

            if (akt == 1)
            {
                if (pSx - this.posX < 0)
                {
                    MakePlan("MonsterGoXXX", time, this, EventType.goLeft);
                }
                else if (pSx - this.posX > 0)
                {
                    MakePlan("MonsterGoXXX", time, this, EventType.goRight);
                }
                else if (pSy - this.posY < 0)
                {
                    MakePlan("MonsterGoXXX", time, this, EventType.goUp);
                }
                else if (pSy - this.posY > 0)
                {
                    MakePlan("MonsterGoXXX", time, this, EventType.goDown);
                }
                else
                {
                    MakePlan("MonsterPursuit", time, this, EventType.pursuit);
                }
            }
            else
            {
                MakePlan("MonsterPursuit", time + this.Speed, this, EventType.pursuit);
            }
        }
Пример #9
0
        public new bool ProcessEvent(Int64 time, Event ev)
        {
            bool returnValue = false;

            switch (ev.what)
            {
                case EventType.goRight:
                case EventType.goLeft:
                case EventType.goUp:
                case EventType.goDown:

                    if (!host.IsSimulationActive) return true;

                    base.SetOrientation(ev.what);

                    DebuggerIX.WriteLine(DebuggerTag.SimulationNotableEvents, "[Sokoban] ProcessEvent", ev.what.ToString() + "; Raised from EventID: " + ev.EventID.ToString());
                    DebuggerIX.WriteLine(DebuggerTag.SimulationNotableEvents, "", "[Sokoban]" + ev.ToString());

                    IGamePlugin obstruction = base.ProcessGoEvent(time, ev);

                    returnValue = true;

                    break;

                case EventType.pursuit:

                    if (!host.IsSimulationActive) return true;

                    ProcessPursuitEvent(time, ev);

                    return true;

                case EventType.wentRight:
                case EventType.wentLeft:
                case EventType.wentUp:
                case EventType.wentDown:

                    base.ProcessEvent(time, ev);
                    MakePlan("MonsterPursuit", time, this, EventType.pursuit);

                    return true;

                default:
                    returnValue = base.ProcessEvent(time, ev);
                    break;
            }

            return returnValue;
        }