Exemple #1
0
        public void Shoot(Lod Input)
        {
            if (Rotate != RotationState.Unset)
            {
                Input.ShipRotate(Rotate);
            }
            List <int> MapShipShoot = new List <int>();

            TextToPlayer = "Používáš ostrou munici";
            Kurzor       = Input.pivot;
            int      ShipMaxIndex = Input.ShipTiles.Count;
            int      BadCount     = 0;
            Position ShipTile     = new Position();
            int      ShipInt;
            int      KurzorInt = (Kurzor.PosX) + ((Kurzor.PosY) * MapSize);

            AbleToPlace = true;

            for (int i = 0; i < ShipMaxIndex; i++)
            {
                ShipTile = Input.ShipTiles[i];
                ShipInt  = (ShipTile.PosX + Kurzor.PosX) + ((ShipTile.PosY + Kurzor.PosY) * MapSize);



                if (ShipTile.PosX + Kurzor.PosX >= 0 && ShipTile.PosX + Kurzor.PosX <= MapSize - 1)
                {
                }
                else
                {
                    TextToPlayer = "Zde nemůžeš střílet";
                    BadCount++;
                }


                if (ShipInt < MapMaxIndex && ShipInt >= 0)/*&& MapSize * (b - 1) <= ShipInt && MapSize * b >= ShipInt*/
                {
                    if (MapState[ShipInt] == 2 || MapState[ShipInt] == 0)
                    {
                        MapShipShoot.Add(ShipInt);
                    }

                    MapStatePlayer[ShipInt] = 3;
                }
                else
                {
                    //not able place!!!
                    TextToPlayer = "Zde nemůžeš střílet";
                    BadCount++;
                }
            }

            if (BadCount == 0 && Place == true)
            {
                MapStatePlayer = MapStatePlayerReal.ToList();
                MapState       = MapStateReal.ToList();
                for (int i = 0; i < MapShipShoot.Count(); i++)
                {
                    ShipInt = MapShipShoot[i];

                    if (MapStateReal[ShipInt] == 2)
                    {
                        MapState[ShipInt]       = 4;
                        MapStatePlayer[ShipInt] = 4;
                        for (int d = 0; d < HitShips.Count; d++)
                        {
                            for (int g = 1; g < HitShips[d].Count; g++)
                            {
                                if (HitShips[d][g] == ShipInt)
                                {
                                    HitShips[d][0]++;
                                    if (HitShips[d][0] == HitShips[d].Count - 1)
                                    {
                                        for (int f = 1; f < HitShips[d].Count; f++)
                                        {
                                            MapState[HitShips[d][f]]       = 1;
                                            MapStatePlayer[HitShips[d][f]] = 1;
                                        }
                                        DestroyedShipsCount++;
                                        HitShips[d][0] = 9999999;
                                    }
                                }
                            }
                        }
                    }
                    else if (MapStateReal[ShipInt] == 0)
                    {
                        MapStatePlayer[ShipInt] = 3;
                    }
                }

                MapStatePlayerReal = MapStatePlayer.ToList();
                MapStateReal       = MapState.ToList();
                HitShipsReal       = HitShips.ToList();
            }
        }
Exemple #2
0
        public void Discover(Lod Input)
        {
            if (Rotate != RotationState.Unset)
            {
                Input.ShipRotate(Rotate);
            }
            List <int> MapShipShoot = new List <int>();

            TextToPlayer = "Používáš slepou munici";
            Kurzor       = Input.pivot;
            int      ShipMaxIndex = Input.ShipTiles.Count;
            int      BadCount     = 0;
            Position ShipTile     = new Position();
            int      ShipInt;
            int      KurzorInt = (Kurzor.PosX) + ((Kurzor.PosY) * MapSize);

            AbleToPlace = true;

            for (int i = 0; i < ShipMaxIndex; i++)
            {
                ShipTile = Input.ShipTiles[i];
                ShipInt  = (ShipTile.PosX + Kurzor.PosX) + ((ShipTile.PosY + Kurzor.PosY) * MapSize);



                if (ShipTile.PosX + Kurzor.PosX >= 0 && ShipTile.PosX + Kurzor.PosX <= MapSize - 1)
                {
                }
                else
                {
                    TextToPlayer = "Zde nemůžeš střílet";
                    BadCount++;
                }


                if (ShipInt < MapMaxIndex && ShipInt >= 0)/*&& MapSize * (b - 1) <= ShipInt && MapSize * b >= ShipInt*/
                {
                    if (MapState[ShipInt] == 2 || MapState[ShipInt] == 0)
                    {
                        MapShipShoot.Add(ShipInt);
                    }


                    MapStatePlayer[ShipInt] = 3;
                }
                else
                {
                    //not able place!!!
                    TextToPlayer = "Zde nemůžeš střílet";
                    BadCount++;
                }
            }

            if (BadCount == 0 && Place == true)
            {
                MapStatePlayer = MapStatePlayerReal.ToList();

                for (int i = 0; i < MapShipShoot.Count(); i++)
                {
                    ShipInt = MapShipShoot[i];

                    if (MapStateReal[ShipInt] == 2)
                    {
                        MapStatePlayer[ShipInt] = 2;
                    }
                    else
                    {
                        MapStatePlayer[ShipInt] = 3;
                    }
                }

                MapStatePlayerReal = MapStatePlayer.ToList();
                MapStateReal       = MapState.ToList();
                HitShipsReal       = HitShips.ToList();
            }
        }
Exemple #3
0
        public void PlaceShip(Lod Input)
        {
            if (Rotate != RotationState.Unset)
            {
                Input.ShipRotate(Rotate);
            }
            TextToPlayer = "Pokládáš: " + Input.ShipType;
            List <Position> ValidShip = new List <Position>();

            Kurzor = Input.pivot;
            int      ShipMaxIndex = Input.ShipTiles.Count;
            int      BadCount     = 0;
            Position ShipTile     = new Position();
            int      ShipInt;
            int      KurzorInt = (Kurzor.PosX) + ((Kurzor.PosY) * MapSize);

            AbleToPlace = true;
            HitShips.Add(new List <int> {
                0
            });
            for (int i = 0; i < ShipMaxIndex; i++)
            {
                ShipTile = Input.ShipTiles[i];
                ShipInt  = (ShipTile.PosX + Kurzor.PosX) + ((ShipTile.PosY + Kurzor.PosY) * MapSize);

                ValidShip.Add(new Position
                {
                    PosX = ShipTile.PosX + Kurzor.PosX + 1,
                    PosY = ShipTile.PosY + Kurzor.PosY
                });
                ValidShip.Add(new Position
                {
                    PosX = ShipTile.PosX + Kurzor.PosX - 1,
                    PosY = ShipTile.PosY + Kurzor.PosY
                });
                ValidShip.Add(new Position
                {
                    PosX = ShipTile.PosX + Kurzor.PosX,
                    PosY = ShipTile.PosY + Kurzor.PosY + 1
                });
                ValidShip.Add(new Position
                {
                    PosX = ShipTile.PosX + Kurzor.PosX,
                    PosY = ShipTile.PosY + Kurzor.PosY - 1
                });

                if (ShipTile.PosX + Kurzor.PosX >= 0 && ShipTile.PosX + Kurzor.PosX <= MapSize - 1)
                {
                }
                else
                {
                    TextToPlayer = "Zde nelze položit lod";
                    BadCount++;
                }


                if (ShipInt < MapMaxIndex && ShipInt >= 0) /*&& MapSize * (b - 1) <= ShipInt && MapSize * b >= ShipInt*/
                {
                    if (MapState[ShipInt] != 0)
                    {
                        BadCount++;
                        TextToPlayer = "Zde nelze polozit lod";
                    }
                    MapState[ShipInt] = 2;
                    HitShips[HitShipsIndex].Add(ShipInt);
                }
                else
                {
                    //not able place!!!
                    TextToPlayer = "Zde nelze polozit lod";
                    BadCount++;
                }
            }
            if (BadCount == 0 && Place == true)
            {
                int      ShipValidInt;
                Position ShipValidTile = new Position();


                for (int i = 0; i < ValidShip.Count; i++)
                {
                    AbleToPlace   = true;
                    ShipValidTile = ValidShip[i];
                    ShipValidInt  = (ShipValidTile.PosX) + ((ShipValidTile.PosY) * MapSize);

                    if (ShipValidTile.PosX >= 0 && ShipValidTile.PosX <= MapSize - 1)
                    {
                    }
                    else
                    {
                        AbleToPlace = false;
                    }


                    if (ShipValidInt < MapMaxIndex && ShipValidInt >= 0)
                    {
                        if (MapState[ShipValidInt] == 0 && AbleToPlace == true)
                        {
                            MapState[ShipValidInt] = 5;
                        }
                    }
                    else
                    {
                        AbleToPlace = false;
                    }
                }
                NumOFShips++;
                MapStateReal = MapState.ToList();
                HitShipsReal = HitShips.ToList();
                HitShipsIndex++;
            }
        }