Beispiel #1
0
        /// <summary>
        /// List pawns for current node
        /// </summary>
        /// <returns>List of pawn types</returns>
        public List <String> ListPawns()
        {
            List <String> retList = new List <String>();

            Pawns.ForEach(pawn => retList.Add(pawn.ToString()));
            return(retList);
        }
Beispiel #2
0
        public override void Draw(SpriteBatch spriteBatch, Matrix parentTransform)
        {
            Matrix globalTransform = LocalTransform * parentTransform;

            Tiles.ForEach(t => t.Draw(spriteBatch, globalTransform));
            Pawns.ForEach(p => p.Draw(spriteBatch, globalTransform));

            IsManeuvering           = false;
            IsMainThrustFiring      = false;
            IsPortThrustFiring      = false;
            IsStarboardThrustFiring = false;
        }
Beispiel #3
0
        public override void Update(GameTime gameTime, Matrix parentTransform)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            HandleInput(deltaTime);
            DetectCollisions();

            // Continue rotation until turn rate reaches zero to simulate slowing
            if (_currentTurnRate > 0)
            {
                RotateClockwise(deltaTime);
            }
            else if (_currentTurnRate < 0)
            {
                RotateCounterClockwise(deltaTime);
            }

            Velocity += _acceleration * deltaTime;

            // Cap velocity to max velocity
            if (Velocity.LengthSquared() > MaxVelocity * MaxVelocity)
            {
                Velocity.Normalize();
                Velocity *= MaxVelocity;
            }
            _acceleration.X = 0;
            _acceleration.Y = 0;
            Position       += Velocity * deltaTime;
            WorldPosition   = Position;

            if (!IsManeuvering)
            {
                if (_currentTurnRate != 0)
                {
                    SlowDownManueveringThrust();
                }
            }

            Tiles.ForEach(t => t.Update(gameTime, LocalTransform));
            Pawns.ForEach(p => p.Update(gameTime, LocalTransform));

            if (MainGame.IsDebugging && MainGame.Ship == this)
            {
                MainGame.Instance.ShipDebugEntries["Position"]          = $"{Math.Round(Position.X)}, {Math.Round(Position.Y)}";
                MainGame.Instance.ShipDebugEntries["Velocity"]          = $"{Math.Round(Velocity.X)}, {Math.Round(Velocity.Y)}";
                MainGame.Instance.ShipDebugEntries["Heading"]           = $"{Math.Round(Heading, 2)}";
                MainGame.Instance.ShipDebugEntries["Velocity Heading"]  = $"{Math.Round(Velocity.ToAngle(), 2)}";
                MainGame.Instance.ShipDebugEntries["World Tile"]        = $"{Math.Floor(Position.X / MainGame.WorldTileSize)}, {Math.Floor(Position.Y / MainGame.WorldTileSize)}";
                MainGame.Instance.ShipDebugEntries["Current Turn Rate"] = $"{Math.Round(_currentTurnRate, 2)}";
            }
        }
        public string CreateOutput()
        {
            var    fields = size;
            double ratio  = 9.0 / 16.0;

            var fieldCount_x = Math.Min((int)Math.Sqrt(ratio * fields), MaxWidth);
            var fieldCount_y = fields / fieldCount_x; //ratio * fieldCount_y;

            if (fields % fieldCount_x != 0)
            {
                fieldCount_y++;
            }

            string[,] array2D = new string[fieldCount_y, fieldCount_x];
            string result = "";

            var counter = size;



            for (var y = 0; y < fieldCount_y; ++y)
            {
                for (var x = 0; x < fieldCount_x; ++x)
                {
                    string bottomSpace     = "";
                    string topSpace        = "";
                    string firstPawnSpace  = "";
                    string secondPawnSpace = "";

                    var xOffs       = y % 2 == 0 ? x : fieldCount_x - x - 1;
                    var stringDigit = $"      {counter} ";
                    stringDigit = stringDigit.Substring(stringDigit.Length - 4);

                    if (counter > 0 & counter <= fields)
                    {
                        array2D[y, xOffs] = $"{stringDigit}[ | , | ] ";
                    }
                    else
                    {
                        array2D[y, xOffs] = "".PadLeft(14, ' ');
                    }

                    Entities.ForEach(entity =>
                    {
                        if (entity.type == EntityType.Eel & entity.bottom_location == counter)
                        {
                            bottomSpace = "s";
                        }
                        else if (entity.type == EntityType.Escalator & entity.bottom_location == counter)
                        {
                            bottomSpace = "e";
                        }
                    });

                    if (bottomSpace.Length == 0)
                    {
                        bottomSpace = " ";
                    }
                    if (bottomSpace.Length == 0)
                    {
                        bottomSpace = " ";
                    }

                    Entities.ForEach(entity =>
                    {
                        if (entity.type == EntityType.Eel & entity.top_location == counter)
                        {
                            topSpace = "S";
                        }
                        else if (entity.type == EntityType.Escalator & entity.top_location == counter)
                        {
                            topSpace = "E";
                        }
                    });

                    if (topSpace.Length == 0)
                    {
                        topSpace = " ";
                    }
                    if (topSpace.Length == 0)
                    {
                        topSpace = " ";
                    }

                    Pawns.ForEach(pawn =>
                    {
                        if (pawn.location == counter & (firstPawnSpace.Length == 0 || firstPawnSpace == " "))
                        {
                            firstPawnSpace = pawn.playerID.ToString();
                        }
                        else if (pawn.location == counter & (secondPawnSpace.Length == 0 || secondPawnSpace == " "))
                        {
                            secondPawnSpace = pawn.playerID.ToString();
                        }
                    });

                    if (firstPawnSpace.Length == 0)
                    {
                        firstPawnSpace = " ";
                    }
                    if (secondPawnSpace.Length == 0 || secondPawnSpace == " ")
                    {
                        secondPawnSpace = " ";
                    }

                    if (counter > 0 & counter <= fields)
                    {
                        array2D[y, xOffs] = $"{stringDigit}[{topSpace}|{firstPawnSpace},{secondPawnSpace}|{bottomSpace}] ";
                    }

                    counter--;
                }
            }

            for (var y = 0; y < fieldCount_y; ++y)
            {
                for (var x = 0; x < fieldCount_x; ++x)
                {
                    result += array2D[y, x];
                }

                result += "\n";
            }


            return(result);
        }
Beispiel #5
0
    // return true if is atack is avaiable for the pawn
    public bool isAtackAvailable(GameObject pawn)
    {
        bool    avaiable     = false;
        int     player       = pawn.GetComponent <PawnController>().player == 1 ? 0 : 1; //player which is attacked
        Vector3 pawnPosition = pawn.transform.position;
        bool    queen        = pawn.GetComponent <PawnController>().queen;

        if (queen)
        {
            int directions = 0;
            for (int i = 1; directions < 4; i++)
            {
                bool    skip = false;
                Vector3 markposition;
                if (directions < 2)
                {
                    markposition = new Vector3(pawnPosition.x + 2 * i, pawnPosition.y + (2 * i) * (-1 * directions % 2 == 0 ? 1 : -1), pawnPosition.z);
                }
                else
                {
                    markposition = new Vector3(pawnPosition.x - 2 * i, pawnPosition.y - (2 * i) * (-1 * directions % 2 == 0 ? 1 : -1), pawnPosition.z);
                }
                PlayerPawns [player].ForEach(obj => {
                    if (obj.transform.position == markposition)
                    {
                        Vector3 objPos  = obj.transform.position;
                        Vector3 markpos = new Vector3(pawnPosition.x < markposition.x?markposition.x + 2:markposition.x - 2, pawnPosition.y < markposition.y?markposition.y + 2:markposition.y - 2, 0);
                        PlayerPawns.ForEach(Pawns => {
                            Pawns.ForEach(objj => {
                                if (objj.transform.position == markpos)
                                {
                                    skip = true;
                                }
                            });
                        });

                        if (!skip && (markpos.x > -8 && markpos.x < 8 && markpos.y < 8 && markpos.y > -8))
                        {
                            avaiable = true;
                            return;
                        }
                        else
                        {
                            i = 0;
                            directions++;
                        }
                    }
                });
                if (markposition.x < -8 || markposition.x > 8 || markposition.y > 8 || markposition.y < -8)
                {
                    i = 0;
                    directions++;
                }

                if (avaiable)
                {
                    return(avaiable);
                }
            }
        }
        else
        {
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Vector3 markposition = new Vector3(2 - (4 * (i % 2)) + pawnPosition.x, 2 - (j % 2 * 4) + pawnPosition.y, 0);
                    PlayerPawns [player].ForEach(obj => {
                        bool skip = false;
                        if (obj.transform.position == markposition)
                        {
                            Vector3 objPosition = obj.transform.position;
                            Vector3 markpos     = new Vector3(markposition.x + (objPosition.x - pawnPosition.x), markposition.y + (objPosition.y - pawnPosition.y), 0);
                            PlayerPawns.ForEach(Pawns => {
                                Pawns.ForEach(objj => {
                                    if (objj.transform.position == markpos)
                                    {
                                        skip = true;
                                    }
                                });
                            });
                            if (!skip && (markpos.x > -8 && markpos.x < 8 && markpos.y < 8 && markpos.y > -8))
                            {
                                avaiable = true;
                                return;
                            }
                        }
                    });
                    if (avaiable)
                    {
                        return(avaiable);
                    }
                }
            }
        }

        return(false);
    }
Beispiel #6
0
    public void markMoves(GameObject pawn)
    {
        int     player       = pawn.GetComponent <PawnController>().player;
        bool    queen        = pawn.GetComponent <PawnController>().queen;
        Vector3 pawnPosition = pawn.transform.position;

        if (queen)
        {
            int directions = 0;
            for (int i = 1; directions < 4; i++)
            {
                bool    skip = false;
                Vector3 markposition;
                if (directions < 2)
                {
                    markposition = new Vector3(pawnPosition.x + 2 * i, pawnPosition.y + (2 * i) * (-1 * directions % 2 == 0 ? 1 : -1), pawnPosition.z);
                }
                else
                {
                    markposition = new Vector3(pawnPosition.x - 2 * i, pawnPosition.y - (2 * i) * (-1 * directions % 2 == 0 ? 1 : -1), pawnPosition.z);
                }
                PlayerPawns.ForEach(Pawns => {
                    Pawns.ForEach(Pawn => {
                        if (Pawn.transform.position == markposition)
                        {
                            skip = true;
                        }
                    });
                });

                if (skip || markposition.x < -8 || markposition.x > 8 || markposition.y > 8 || markposition.y < -8)
                {
                    directions++;
                    i = 0;
                    continue;
                }
                var mark = Instantiate(MoveMark, pawn.transform);
                mark.transform.position = markposition;
                marks.Add(mark, null);
            }
        }
        else
        {
            for (int i = 0; i < 2; i++)
            {
                bool    skip         = false;
                Vector3 markposition = new Vector3(pawnPosition.x + 2 - (4 * i), pawnPosition.y + 2 - (4 * player), 0);
                PlayerPawns.ForEach(Pawns => {
                    Pawns.ForEach(Pawn => {
                        if (Pawn.transform.position == markposition)
                        {
                            skip = true;
                        }
                    });
                });
                if (skip || !(markposition.x > -8 && markposition.x < 8 && markposition.y < 8 && markposition.y > -8))
                {
                    continue;
                }
                var mark = Instantiate(MoveMark, pawn.transform);
                mark.transform.position = markposition;
                marks.Add(mark, null);
            }
        }
    }
Beispiel #7
0
    public void markAtacks(GameObject pawn)
    {
        int     player       = pawn.GetComponent <PawnController>().player == 1 ? 0 : 1;
        Vector3 pawnPosition = pawn.transform.position;

        if (pawn.GetComponent <PawnController>().queen)
        {
            int directions = 0;
            for (int i = 0; directions < 4; i++)
            {
                Vector3    markposition;
                bool       skip   = false;
                GameObject beaten = null;
                if (directions < 2)
                {
                    markposition = new Vector3(pawnPosition.x + 2 * i, pawnPosition.y + (2 * i) * (-1 * directions % 2 == 0 ? 1 : -1), pawnPosition.z);
                }
                else
                {
                    markposition = new Vector3(pawnPosition.x - 2 * i, pawnPosition.y - (2 * i) * (-1 * directions % 2 == 0 ? 1 : -1), pawnPosition.z);
                }
                PlayerPawns [player].ForEach(obj => {
                    if (obj.transform.position == markposition)
                    {
                        beaten          = obj;
                        Vector3 objPos  = obj.transform.position;
                        Vector3 markpos = new Vector3(pawnPosition.x < markposition.x ? markposition.x + 2 : markposition.x - 2, pawnPosition.y < markposition.y ? markposition.y + 2 : markposition.y - 2, 0);
                        PlayerPawns.ForEach(Pawns => {
                            Pawns.ForEach(objj => {
                                if (objj.transform.position == markpos)
                                {
                                    skip = true;
                                }
                            });
                        });
                        if (!skip && (markpos.x > -8 && markpos.x < 8 && markpos.y < 8 && markpos.y > -8))
                        {
                            var mark = Instantiate(MoveMark, pawn.transform);
                            mark.transform.position = markpos;
                            marks.Add(mark, beaten);
                        }
                    }
                });
                if (markposition.x < -8 || markposition.x > 8 || markposition.y > 8 || markposition.y < -8)
                {
                    directions++;
                    i = 0;
                }
            }
        }
        else
        {
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Vector3 markposition = new Vector3(2 - (4 * (i % 2)) + pawnPosition.x, 2 - (j % 2 * 4) + pawnPosition.y, 0);
                    PlayerPawns [player].ForEach(obj => {
                        bool skip         = false;
                        GameObject beaten = null;
                        if (obj.transform.position == markposition)
                        {
                            beaten = obj;
                            Vector3 objPosition = obj.transform.position;
                            Vector3 markpos     = new Vector3(markposition.x + (objPosition.x - pawnPosition.x), markposition.y + (objPosition.y - pawnPosition.y), 0);
                            PlayerPawns.ForEach(Pawns => {
                                Pawns.ForEach(objj => {
                                    if (objj.transform.position == markpos)
                                    {
                                        skip = true;
                                    }
                                });
                            });
                            if (skip || !(markpos.x > -8 && markpos.x < 8 && markpos.y < 8 && markpos.y > -8))
                            {
                                return;
                            }
                            else
                            {
                                var mark = Instantiate(MoveMark, pawn.transform);
                                mark.transform.position = markpos;
                                marks.Add(mark, beaten);
                            }
                        }
                    });
                }
            }
        }
    }