示例#1
0
        public void FindMoves_ReturnsExpectedNodesForMovementThree()
        {
            BoardGraph     boardGraph     = new BoardGraph();
            MoveCalculator moveCalculator = new MoveCalculator();

            List <Node> occupiedNodes = new List <Node>();

            occupiedNodes.Add(boardGraph.Nodes[13]);
            occupiedNodes.Add(boardGraph.Nodes[14]);
            occupiedNodes.Add(boardGraph.Nodes[17]);
            occupiedNodes.Add(boardGraph.Nodes[18]);
            occupiedNodes.Add(boardGraph.Nodes[19]);
            occupiedNodes.Add(boardGraph.Nodes[20]);
            occupiedNodes.Add(boardGraph.Nodes[23]);
            occupiedNodes.Add(boardGraph.Nodes[24]);

            IEnumerable <NodePath> actual;

            actual = moveCalculator.FindMoves(boardGraph.Nodes[13], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[14], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[17], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[18], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[19], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[20], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[23], 3, occupiedNodes);
            actual = moveCalculator.FindMoves(boardGraph.Nodes[24], 3, occupiedNodes);
        }
示例#2
0
 private void Start()
 {
     transform.position = currentTile.transform.position;
     moveCalculator     = GetComponent <MoveCalculator>();
     player             = GetComponent <Player>();
     isGameOver         = false;
 }
示例#3
0
        private void SubActionOne()
        {
            IEnumerable <int> availableNodeIds;

            if (ActionNumber == 1 || ActionNumber == 2)
            {
                var enemyNodes = GuestMonsters.Select(monster => monster.CurrentNode).ToList();
                availableNodeIds =
                    GameGraph.Nodes.Where(n => HostMonsters.Select(m => m.CurrentNode.Id).Contains(n.Id))
                    .OrderByDescending(t => MoveCalculator.FindAttackMoves(t, enemyNodes).Count())               // 1. one with the most attack moves
                    .ThenBy(m => m.Id > 12 ? 0 : 1)                                                              // 2. Monsters on the outer circle
                    .ThenByDescending(r => HostMonsters.First(w => w.CurrentNode.Id == r.Id).AttackRating)       // 3. the attack level of the monster
                    .Select(n => n.Id);
            }
            else
            {
                var enemyNodes = HostMonsters.Select(monster => monster.CurrentNode).ToList();
                availableNodeIds =
                    GameGraph.Nodes.Where(n => GuestMonsters.Select(m => m.CurrentNode.Id).Contains(n.Id))
                    .OrderByDescending(t => MoveCalculator.FindAttackMoves(t, enemyNodes).Count())                // 1. one with the most attack moves
                    .ThenBy(m => m.Id > 12 ? 0 : 1)                                                               // 2. Monsters on the outer circle
                    .ThenByDescending(r => GuestMonsters.First(w => w.CurrentNode.Id == r.Id).AttackRating)       // 3. the attack level of the monster
                    .Select(n => n.Id);
            }

            SubActionNumber = 2;

            _hostServer.SendToAll(CustomMessageTypes.AvailableMonstersResponse, new AvailableMonstersResponseMessage
            {
                ActionNumber            = ActionNumber,
                SubActionNumber         = SubActionNumber,
                AvailableMonsterNodeIds = availableNodeIds.ToArray(),
                Message = "Monsters available for selection"
            });
        }
示例#4
0
 private void Start()
 {
     PlayerCount++;
     pieceMover         = GetComponent <PieceMover>();
     moveCalculator     = GetComponent <MoveCalculator>();
     pieceMover.enabled = false;
 }
        private void btnMoves_Click(object sender, EventArgs e)
        {
            var moves = MoveParser.Parse(txtAlg.Text);

            txtCubeMoves.Text = string.Join("\r\n", moves.Select(x => x.ToString()).ToArray());

            var calculator = new MoveCalculator();

            foreach (Move mv in moves)
            {
                calculator.AddCubeMove(mv);
            }

            txtMachineMoves.Text = string.Join("\r\n", calculator.MachineMoves.Select(x => x.ToString()).ToArray());

            txtMotorMoves.Text = string.Join("\r\n", calculator.MachineMoves.MotorMoves.Select(x => x.ToString()).ToArray());

            txtNBMotorMoves.Text = "1/4: " + calculator.MachineMoves.MotorMoves.Sum(x => x.QuarterNumber).ToString() + "  moves: " + calculator.MachineMoves.MotorMoves.Count;

            textLongMove.Text = string.Join("  ", calculator.MachineMoves.MotorMoves.Select(x => x.EquivalentCubeMove()));


            var dir = GetUriViewer(/*txtAlg.Text+ "%0A%2F%2F" +*/ textLongMove.Text, txtMoves.Text);

            viewer.FrameLoadEnd += ResetCubeOnLoad; // reset du cube au chargement

            viewer.Load(dir);
        }
示例#6
0
 public GpsBase(IGeolocator geolocator)
 {
     Name           = "GPS";
     _geolocator    = geolocator;
     Id             = "GPS";
     MoveCalculator = new MoveCalculator();
 }
示例#7
0
    public Board()
    {
        pieces  = new List <Piece>();
        squares = new Square[8, 8];
        mc      = new MoveCalculator();

        initializeSquares();
    }
示例#8
0
 public MemoryLap()
 {
     _timeFrames        = new List <ActivityTimeFrame>();
     _moveCalculator    = new MoveCalculator();
     _hrCalculator      = new Statistics();
     _powerCalculator   = new Statistics();
     _cadenceCalculator = new Statistics();
     _speedCalculator   = new Statistics();
     _avgSpeed.Unit     = _maxSpeed.Unit = SpeedUnit.MeterPerSecond;
     _ascentCalculator  = new AscentCalculator(0.0f);
 }
        void Start()
        {
            Client = GameManager.Instance.Client;

            if (Client.IsPlayer)
            {
                Destroy(gameObject);
                return;
            }

            Instance = this;

            GameGraph        = new BoardGraph();
            BoardSpaces      = new Dictionary <int, BoardSpace>();
            FriendlyMonsters = new List <Monster>();
            EnemyMonsters    = new List <Monster>();
            AttackCalculator = new AttackCalculator();
            MoveCalculator   = new MoveCalculator();

            AvailablePushDestinations = new List <Node>();

            BattleSmoke.gameObject.SetActive(false);

            Client.GameState = this;

            float attackResultTextRotationOffset = Client.IsHost ? 180 : 0;

            AttackResultTextPrefab.YRotationOffset = attackResultTextRotationOffset;

            _actionNumber = 1;

            if (!Client.IsHost)
            {
                _actionNumber = 3;

                var table = GameObject.Find("Table");
                table.transform.localRotation = Quaternion.Euler(table.transform.localRotation.eulerAngles.x,
                                                                 table.transform.localRotation.eulerAngles.y + 180, table.transform.localRotation.eulerAngles.z);
            }

            _subActionNumber = 1;

            for (int i = 0; i < SpacePrefabs.Count; i++)
            {
                BoardSpace spacePrefab = SpacePrefabs[i];
                if (!BoardSpaces.ContainsKey(i))
                {
                    spacePrefab.Node = GameGraph.Nodes[i];
                    BoardSpaces.Add(i, spacePrefab);
                }
            }
        }
示例#10
0
        private static bool CheckTeamHasNoMoves(Teams team)
        {
            int totalMoves = 0;
            var pawns      = team == Teams.TeamA ? GameManager.Pawns.TeamA : GameManager.Pawns.TeamB;

            foreach (var pawn in pawns)
            {
                if (!pawn.State.IsAlive)
                {
                    continue;
                }
                var tiles = MoveCalculator.GetValidTiles(pawn);
                totalMoves += tiles.Count;
            }
            return(totalMoves == 0);
        }
示例#11
0
        void Start()
        {
            DontDestroyOnLoad(gameObject);

            ActionNumber    = 1;
            SubActionNumber = 1;

            GameGraph        = new BoardGraph();
            HostMonsters     = new List <Monster>();
            GuestMonsters    = new List <Monster>();
            AttackCalculator = new AttackCalculator();
            MoveCalculator   = new MoveCalculator();

            AvailablePushDestinations = new List <Node>();

            GameManager gameManager = GameManager.Instance;

            if (gameManager == null || gameManager.Server == null)
            {
                throw new InvalidOperationException("Server must exist to begin game");
            }

            _hostServer = gameManager.Server;

            if (_hostServer == null || !_hostServer.IsServerStarted)
            {
                throw new InvalidOperationException("Server must be running to begin game");
            }

            if (SceneManager.GetSceneByName("startup").isLoaded)
            {
                SceneManager.UnloadSceneAsync("startup");
            }

            AssignMonstersToPlayers();

            GameStartMessage gameStartMessage = new GameStartMessage
            {
                HostMonsters    = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                GuestMonsters   = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                ActionNumber    = 1,
                SubActionNumber = 1
            };

            _hostServer.SendToAll(gameStartMessage.MessageTypeId, gameStartMessage);
        }
示例#12
0
        private bool GetMoves()
        {
            moves.Clear();
            foreach (var pawn in GameManager.Pawns.TeamB)
            {
                if (!pawn.State.IsAlive)
                {
                    continue;
                }

                var tiles = MoveCalculator.GetValidTiles(pawn);
                foreach (var tile in tiles)
                {
                    moves.Add(new Move(pawn, tile));
                }
            }
            return(moves.Count > 0);
        }
示例#13
0
 public BasicMoveValidator()
 {
     MoveCalculator = new MoveCalculator();
 }
示例#14
0
        public void ProcessAttackAction(int attackingMonsterTypeId, int defendingMonsterTypeId)
        {
            Monster attacker;
            Monster defender;
            bool    isHostAttacker = ActionNumber == 1 || ActionNumber == 2;

            if (isHostAttacker)
            {
                attacker = HostMonsters.Single(m => m.MonsterTypeId == attackingMonsterTypeId);
                defender = GuestMonsters.Single(m => m.MonsterTypeId == defendingMonsterTypeId);
            }
            else
            {
                attacker = GuestMonsters.Single(m => m.MonsterTypeId == attackingMonsterTypeId);
                defender = HostMonsters.Single(m => m.MonsterTypeId == defendingMonsterTypeId);
            }

            AttackResult       attackResult          = AttackCalculator.Calculate(attacker.AttackRating, defender.DefenseRating);
            IEnumerable <Node> friendlyOccupiedNodes = HostMonsters.Select(monster => monster.CurrentNode).ToList();
            IEnumerable <Node> enemyOccupiedNodes    = GuestMonsters.Select(monster => monster.CurrentNode).ToList();

            switch (attackResult)
            {
            case AttackResult.Kill:
                if (isHostAttacker)
                {
                    GuestMonsters.Remove(defender);
                }
                else
                {
                    HostMonsters.Remove(defender);
                }
                SubActionNumber = 0;

                _hostServer.SendToAll(CustomMessageTypes.AttackKillResponse, new AttackKillResponseMessage
                {
                    ActionNumber           = ActionNumber,
                    SubActionNumber        = SubActionNumber,
                    AttackingMonsterTypeId = attackingMonsterTypeId,
                    DefendingMonsterTypeId = defendingMonsterTypeId,
                    AttackResultId         = (int)AttackResult.Kill,
                    Message = "Kill"
                });
                break;

            case AttackResult.CounterKill:
                if (isHostAttacker)
                {
                    HostMonsters.Remove(attacker);
                }
                else
                {
                    GuestMonsters.Remove(attacker);
                }
                SelectedMonster = null;
                SubActionNumber = 0;

                _hostServer.SendToAll(CustomMessageTypes.AttackKillResponse, new AttackKillResponseMessage
                {
                    ActionNumber           = ActionNumber,
                    SubActionNumber        = SubActionNumber,
                    AttackingMonsterTypeId = attackingMonsterTypeId,
                    DefendingMonsterTypeId = defendingMonsterTypeId,
                    AttackResultId         = (int)AttackResult.CounterKill,
                    Message = "Counter Kill"
                });
                break;

            case AttackResult.Push:

                AvailablePushDestinations = MoveCalculator.FindMoves(defender.CurrentNode, 1,
                                                                     friendlyOccupiedNodes.Union(enemyOccupiedNodes)).Select(m => m.DestinationNode);

                if (!AvailablePushDestinations.Any())
                {
                    SubActionNumber = 0;
                    _hostServer.SendToAll(CustomMessageTypes.GameState, new GameStateMessage
                    {
                        ActionNumber      = ActionNumber,
                        SubActionNumber   = SubActionNumber,
                        Message           = "No available push destinations.",
                        HostMonsterState  = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                        GuestMonsterState = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id))
                    });
                }
                else
                {
                    SubActionNumber = 6;
                    _hostServer.SendToAll(CustomMessageTypes.AttackPushResponse, new AttackPushResponseMessage
                    {
                        ActionNumber                = ActionNumber,
                        SubActionNumber             = SubActionNumber,
                        AttackingMonsterTypeId      = attackingMonsterTypeId,
                        DefendingMonsterTypeId      = defendingMonsterTypeId,
                        AvailablePushDestinationIds = AvailablePushDestinations.Select(d => d.Id).ToArray(),
                        AttackResultId              = (int)AttackResult.Push,
                        Message = "Push"
                    });
                }

                break;

            case AttackResult.CounterPush:

                AvailablePushDestinations = MoveCalculator.FindMoves(attacker.CurrentNode, 1,
                                                                     friendlyOccupiedNodes.Union(enemyOccupiedNodes)).Select(m => m.DestinationNode);

                if (!AvailablePushDestinations.Any())
                {
                    SubActionNumber = 0;
                    _hostServer.SendToAll(CustomMessageTypes.GameState, new GameStateMessage
                    {
                        ActionNumber      = ActionNumber,
                        SubActionNumber   = SubActionNumber,
                        Message           = "No available push destinations.",
                        HostMonsterState  = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                        GuestMonsterState = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id))
                    });
                }
                else
                {
                    SubActionNumber = 7;
                    _hostServer.SendToAll(CustomMessageTypes.AttackPushResponse, new AttackPushResponseMessage
                    {
                        ActionNumber                = ActionNumber,
                        SubActionNumber             = SubActionNumber,
                        AttackingMonsterTypeId      = attackingMonsterTypeId,
                        DefendingMonsterTypeId      = defendingMonsterTypeId,
                        AvailablePushDestinationIds = AvailablePushDestinations.Select(d => d.Id).ToArray(),
                        AttackResultId              = (int)AttackResult.CounterPush,
                        Message = "Counter Push"
                    });
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#15
0
文件: Enemy.cs 项目: odedw/ponglike
 protected override void Start()
 {
     base.Start();
     moveCalculator = GetComponent <MoveCalculator>();
     boardPlacer    = GetComponent <BoardPlacer>();
 }
示例#16
0
 public JumpMoveValidator()
 {
     AverageCalculator = new AverageCalculator();
     MoveCalculator    = new MoveCalculator();
 }
示例#17
0
        private void SubActionThree()
        {
            if (SelectedMonster != null)
            {
                IEnumerable <Node> friendlyOccupiedNodes;
                IEnumerable <Node> enemyOccupiedNodes;

                if (ActionNumber == 1 || ActionNumber == 2)
                {
                    friendlyOccupiedNodes = HostMonsters.Select(monster => monster.CurrentNode).ToList();
                    enemyOccupiedNodes    = GuestMonsters.OrderBy(t => t.DefenseRating).Select(monster => monster.CurrentNode).ToList(); // order enemies defense rating
                }
                else
                {
                    friendlyOccupiedNodes = GuestMonsters.Select(monster => monster.CurrentNode).ToList();
                    enemyOccupiedNodes    = HostMonsters.OrderBy(t => t.DefenseRating).Select(monster => monster.CurrentNode).ToList(); // order enemies defense rating
                }


                IEnumerable <int> availableMoveActionNodeIds = MoveCalculator.FindMoves(SelectedMonster.CurrentNode,
                                                                                        SelectedMonster.MovementRating, friendlyOccupiedNodes.Union(enemyOccupiedNodes))
                                                               .Select(a => a.DestinationNode.Id)
                                                               .OrderBy(a => a); // order nodes by id so center nodes are prioritized

                IEnumerable <int> availableAttackActionNodeIds = MoveCalculator.FindAttackMoves(SelectedMonster.CurrentNode,
                                                                                                enemyOccupiedNodes).Select(a => a.Id);

                SubActionNumber = 4;

                if (friendlyOccupiedNodes.Count() <= 1 && !availableAttackActionNodeIds.Any() &&
                    !availableMoveActionNodeIds.Any())
                {
                    SubActionNumber = 0;
                    _hostServer.SendToAll(CustomMessageTypes.GameState, new PassActionMessage
                    {
                        ActionNumber      = ActionNumber,
                        SubActionNumber   = SubActionNumber,
                        Message           = "No available moves.",
                        HostMonsterState  = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                        GuestMonsterState = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id))
                    });
                }
                else
                {
                    if (friendlyOccupiedNodes.Count() == 1 && availableAttackActionNodeIds.Any())
                    {
                        availableMoveActionNodeIds = new List <int>();
                    }

                    _hostServer.SendToAll(CustomMessageTypes.AvailableMovesResponse, new AvailableMovesResponseMessage
                    {
                        ActionNumber           = ActionNumber,
                        SubActionNumber        = SubActionNumber,
                        AvailableAttackNodeIds = availableAttackActionNodeIds.ToArray(),
                        AvailableMoveNodeIds   = availableMoveActionNodeIds.ToArray(),
                        Message = "Available actions",
                        SelectedMonsterTypeId = SelectedMonster.MonsterTypeId
                    });
                }
            }
        }
示例#18
0
        void Start()
        {
            Client = GameManager.Instance.Client;

            if (!Client.IsPlayer)
            {
                Destroy(gameObject);
                return;
            }


            Instance = this;

            GameGraph        = new BoardGraph();
            BoardSpaces      = new Dictionary <int, BoardSpace>();
            FriendlyMonsters = new List <Monster>();
            EnemyMonsters    = new List <Monster>();
            AttackCalculator = new AttackCalculator();
            MoveCalculator   = new MoveCalculator();

            AvailablePushDestinations = new List <Node>();

            BattleSmoke.gameObject.SetActive(false);

            Client.GameState = this;

            float attackResultTextRotationOffset = Client.IsHost ? 180 : 0;

            AttackResultTextPrefab.YRotationOffset = attackResultTextRotationOffset;

            _actionNumber = 1;

            if (!Client.IsHost)
            {
                _actionNumber = 3;

                var table = GameObject.Find("Table");
                table.transform.localRotation = Quaternion.Euler(table.transform.localRotation.eulerAngles.x,
                                                                 table.transform.localRotation.eulerAngles.y + 180, table.transform.localRotation.eulerAngles.z);
            }

            _subActionNumber = 1;

            for (int i = 0; i < SpacePrefabs.Count; i++)
            {
                BoardSpace spacePrefab = SpacePrefabs[i];
                if (!BoardSpaces.ContainsKey(i))
                {
                    spacePrefab.Node = GameGraph.Nodes[i];
                    BoardSpaces.Add(i, spacePrefab);
                }
            }

            List <Monster> friendlyMonsters = new List <Monster>();
            List <Monster> enemyMonsters    = new List <Monster>();

            foreach (Monster monster in MonsterPrefabs)
            {
                if (GameManager.Instance.FriendlyMonsterInitialNodeIds.ContainsKey(monster.MonsterTypeId))
                {
                    monster.CurrentNode = GameGraph.Nodes[GameManager.Instance.FriendlyMonsterInitialNodeIds[monster.MonsterTypeId]];
                    friendlyMonsters.Add(monster);
                }
                else
                {
                    monster.CurrentNode = GameGraph.Nodes[GameManager.Instance.EnemyMonsterInitialNodeIds[monster.MonsterTypeId]];
                    enemyMonsters.Add(monster);
                }
            }

            DisplayMonsters(friendlyMonsters, enemyMonsters);

            Client.SendStateAck(GetAdjustedActionNumber(), _subActionNumber);

            if (GameManager.Instance.Difficulty == 1)
            {
                GameObject.Find("selectionPreview").SetActive(false);
            }
        }
示例#19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="batch"></param>
        public void Draw(SpriteBatch batch)
        {
            if (selectionUpdated)
            {
                // Reset the update flag
                selectionUpdated = false;

                // Update the selected entity
                selectedEntity = GetEntityFor(selectedPosition);
            }

            possibleMoves = MoveCalculator.GetMoves(selectedEntity, this);
            //var attackMoves = (moveCalculator == null) ? new MoveList() : moveCalculator.GetAvailableAttackLocations();
            List <Move> attackMoves = new List <Move>();

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    Point point = GetPointForTile(new Vector2(x, y));
                    var   left  = point.X;
                    var   top   = point.Y;
                    var   top2  = y * (TILEHEIGHT - TILEOFFSET) - (int)cameraPosition.Y;

                    // DRAW TILES
                    var tile = map[y, x];
                    if (tile.HasTexture)
                    {
                        var texture = tileTextures[tile.TextureIndex];
                        batch.Draw(texture, new Rectangle(left, top2, TILEWIDTH, TILEHEIGHT), Color.White);
                    }


                    // DRAW DECALS
                    if (tile.HasDecal)
                    {
                        var decal = decalTextures[tile.DecalIndex];
                        batch.Draw(decal, new Rectangle(left, top2, TILEWIDTH, TILEHEIGHT), Color.White);
                    }

                    if (possibleMoves.Any <Move>(move => move.Contains(new Vector2(x, y))))
                    {
                        batch.Draw(MoveIndicator, new Rectangle(left, top2, TILEWIDTH, TILEHEIGHT), Color.White);
                    }
                    else if (attackMoves.Any <Move>(move => move.Contains(new Vector2(x, y))) && GetEntityFor(new Vector2(x, y)) != null)
                    {
                        batch.Draw(AttackIndicator, new Rectangle(left, top2, TILEWIDTH, TILEHEIGHT), Color.IndianRed);
                    }
                }
            }

            // Sort objects in order they need to be drawn
            PlacedObjects.Sort();

            // Draw objects
            foreach (var renderObject in PlacedObjects)
            {
                Vector2 position = renderObject.Location;
                Point   point    = GetPointForTile(position);
                batch.Draw(renderObject.Entity.EntityTexture, new Rectangle(point.X, point.Y, TILEWIDTH, TILEHEIGHT), TurnManager.Instance.TeamDictionary[renderObject.Entity].Color);
            }

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    var left = x * TILEWIDTH - (int)cameraPosition.X;
                    var top  = y * TILEHEIGHT - (int)cameraPosition.Y;
                    var top2 = y * (TILEHEIGHT - TILEOFFSET) - (int)cameraPosition.Y;

                    // ADD HIGHLIGHT
                    if (x == currentPosition.X && y == currentPosition.Y)
                    {
                        batch.Draw(HighlightTexture, new Rectangle(left, top2 - (int)(0.5 * TILEOFFSET), TILEWIDTH, TILEHEIGHT), Color.White);
                    }
                }
            }
        }
示例#20
0
        public void SelectAction(int selectedNodeId)
        {
            if (selectedNodeId < 0)
            {
                SubActionNumber = 0;
                _hostServer.SendToAll(CustomMessageTypes.GameState, new PassActionMessage
                {
                    ActionNumber      = ActionNumber,
                    SubActionNumber   = SubActionNumber,
                    Message           = "No available moves.",
                    HostMonsterState  = JsonConvert.SerializeObject(HostMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id)),
                    GuestMonsterState = JsonConvert.SerializeObject(GuestMonsters.Select(m => new { m.MonsterTypeId, m.CurrentNode.Id }).ToDictionary(k => k.MonsterTypeId, v => v.Id))
                });
            }

            IEnumerable <Node> friendlyOccupiedNodes;
            IEnumerable <Node> enemyOccupiedNodes;

            List <Monster> friendlyMonsters = ActionNumber == 1 || ActionNumber == 2 ? HostMonsters : GuestMonsters;
            List <Monster> enemyMonsters    = ActionNumber == 1 || ActionNumber == 2 ? GuestMonsters : HostMonsters;

            friendlyOccupiedNodes = friendlyMonsters.Select(monster => monster.CurrentNode).ToList();
            enemyOccupiedNodes    = enemyMonsters.Select(monster => monster.CurrentNode).ToList();

            IEnumerable <NodePath> movementPaths = MoveCalculator.FindMoves(SelectedMonster.CurrentNode,
                                                                            SelectedMonster.MovementRating, friendlyOccupiedNodes.Union(enemyOccupiedNodes));

            IEnumerable <Node> availableMoveActions = movementPaths.Select(p => p.DestinationNode);

            IEnumerable <Node> availableAttackActions = MoveCalculator.FindAttackMoves(SelectedMonster.CurrentNode,
                                                                                       enemyOccupiedNodes);

            if (friendlyOccupiedNodes.Select(n => n.Id).Contains(selectedNodeId))
            {
                SelectedMonster    = friendlyMonsters.Single(m => m.CurrentNode.Id == selectedNodeId);
                SelectedAttackNode = null;

                SubActionNumber = 3;

                _hostServer.SendToAll(CustomMessageTypes.SelectMonsterResponse, new SelectMonsterResponseMessage
                {
                    ActionNumber          = ActionNumber,
                    SubActionNumber       = SubActionNumber,
                    SelectedMonsterTypeId = SelectedMonster.MonsterTypeId,
                    Message = SelectedMonster.Name,
                });
            }
            else if (availableAttackActions.Select(a => a.Id).Contains(selectedNodeId))
            {
                SelectedAttackNode   = availableAttackActions.Single(a => a.Id == selectedNodeId);
                SelectedMovementPath = null;
                SubActionNumber      = 5;

                _hostServer.SendToAll(CustomMessageTypes.SelectAttackActionResponse, new SelectAttackResponseMessage
                {
                    ActionNumber    = ActionNumber,
                    SubActionNumber = SubActionNumber,

                    Message      = "Attack selected",
                    AttackNodeId = SelectedAttackNode.Id
                });
            }
            else if (availableMoveActions.Select(m => m.Id).Contains(selectedNodeId))
            {
                SelectedMovementPath = movementPaths.Single(m => m.DestinationNode.Id == selectedNodeId);
                SelectedAttackNode   = null;
                SubActionNumber      = 5;

                _hostServer.SendToAll(CustomMessageTypes.SelectMoveActionResponse, new SelectMoveResponseMessage
                {
                    ActionNumber    = ActionNumber,
                    SubActionNumber = SubActionNumber,

                    Message           = SelectedMovementPath.ToString(),
                    MovementPathIds   = SelectedMovementPath.PathToDestination.Select(n => n.Id).ToArray(),
                    DestinationNodeId = SelectedMovementPath.DestinationNode.Id
                });
            }
        }
 public BeatPawnService()
 {
     MoveCalculator = new MoveCalculator();
 }