Beispiel #1
0
        public void Bake(TickActions actionList)
        {
            tickCount++;
            // Update players
            foreach (KeyValuePair <Player, Action> playerAction in actionList.ActionDict)
            {
                Player player = playerAction.Key;
                Action action = playerAction.Value;

                switch (action)
                {
                case Action.UP:
                    if (IsEmptyForMove(player.X - 1, player.Y))
                    {
                        player.MoveUp();
                    }
                    break;

                case Action.DOWN:
                    if (IsEmptyForMove(player.X + 1, player.Y))
                    {
                        player.MoveDown();
                    }
                    break;

                case Action.LEFT:
                    if (IsEmptyForMove(player.X, player.Y - 1))
                    {
                        player.MoveLeft();
                    }
                    break;

                case Action.RIGHT:
                    if (IsEmptyForMove(player.X, player.Y + 1))
                    {
                        player.MoveRight();
                    }
                    break;

                case Action.BOMB:
                    bombs.Add(new Bomb(player.X, player.Y));
                    break;

                default:
                    throw new ProtocolError();
                }
            }
            // Also update the bombs, and destroy players/walls
            bombs.Tick(map, players);
            DrawState();
        }
Beispiel #2
0
        public void Bake(TickActions actionList)
        {
            tickCount++;
            // Update players
            foreach (KeyValuePair<Player, Action> playerAction in actionList.ActionDict)
            {
                Player player = playerAction.Key;
                Action action = playerAction.Value;

                switch (action)
                {
                    case Action.UP:
                        if (IsEmptyForMove(player.X - 1, player.Y))
                        {
                            player.MoveUp();
                        }
                        break;
                    case Action.DOWN:
                        if (IsEmptyForMove(player.X + 1, player.Y))
                        {
                            player.MoveDown();
                        }
                        break;
                    case Action.LEFT:
                        if (IsEmptyForMove(player.X, player.Y - 1))
                        {
                            player.MoveLeft();
                        }
                        break;
                    case Action.RIGHT:
                        if (IsEmptyForMove(player.X, player.Y + 1))
                        {
                            player.MoveRight();
                        }
                        break;
                    case Action.BOMB:
                        bombs.Add(new Bomb(player.X, player.Y));
                        break;
                    default:
                        throw new ProtocolError();
                }
            }
            // Also update the bombs, and destroy players/walls
            bombs.Tick(map, players);
            DrawState();
        }
Beispiel #3
0
        private void ProcessActions(int actionCount)
        {
            // Process the lines into a TickActions, then bake into the gamestate
            TickActions actions = new TickActions();

            for (int rowCount = 0; rowCount < actionCount; rowCount++)
            {
                string line = reader.ReadLine();
                Logger.WriteLineServer(line);
                string[] lineParts = line.Split(' ');
                Player   player    = currentGameState.GetPlayer(lineParts[0]);
                switch (lineParts[1])
                {
                case "UP":
                    actions.AddAction(player, Action.UP);
                    break;

                case "DOWN":
                    actions.AddAction(player, Action.DOWN);
                    break;

                case "LEFT":
                    actions.AddAction(player, Action.LEFT);
                    break;

                case "RIGHT":
                    actions.AddAction(player, Action.RIGHT);
                    break;

                case "BOMB":
                    actions.AddAction(player, Action.BOMB);
                    break;

                default:
                    throw new ProtocolError();
                }
            }
            currentGameState.Bake(actions);
        }
Beispiel #4
0
 private void ProcessActions(int actionCount)
 {
     // Process the lines into a TickActions, then bake into the gamestate
     TickActions actions = new TickActions();
     for (int rowCount = 0; rowCount < actionCount; rowCount++)
     {
         string line = reader.ReadLine();
         Logger.WriteLineServer(line);
         string[] lineParts = line.Split(' ');
         Player player = currentGameState.GetPlayer(lineParts[0]);
         switch (lineParts[1])
         {
             case "UP":
                 actions.AddAction(player, Action.UP);
                 break;
             case "DOWN":
                 actions.AddAction(player, Action.DOWN);
                 break;
             case "LEFT":
                 actions.AddAction(player, Action.LEFT);
                 break;
             case "RIGHT":
                 actions.AddAction(player, Action.RIGHT);
                 break;
             case "BOMB":
                 actions.AddAction(player, Action.BOMB);
                 break;
             default:
                 throw new ProtocolError();
         }
     }
     currentGameState.Bake(actions);
 }