Esempio n. 1
0
        public static PlayerMatrix PlaceShips(PlayerMatrix pM, bool player)
        {
            Variable.CZTEROMASZTOWCE = 1;
            Variable.TRZYMASZTOWCE   = 2;
            Variable.DWUMASZTOWCE    = 3;
            Variable.JEDNOMASZTOWIEC = 4;
            for (int i = 1; i <= 1; i++)
            {
                pM = Methods.PlaceShip(4, pM, player);
                Variable.CZTEROMASZTOWCE = 1 - i;
            }
            for (int i = 1; i <= 2; i++)
            {
                pM = Methods.PlaceShip(3, pM, player);
                Variable.TRZYMASZTOWCE = 2 - i;
            }
            for (int i = 1; i <= 3; i++)
            {
                pM = Methods.PlaceShip(2, pM, player);
                Variable.DWUMASZTOWCE = 3 - i;
            }
            for (int i = 1; i <= 4; i++)
            {
                pM = Methods.PlaceShip(1, pM, player);
                Variable.JEDNOMASZTOWIEC = 4 - i;
            }

            return(pM);
        }
Esempio n. 2
0
 public void IsDefeat(bool result, PlayerMatrix pM, int lenght, int truex, int truey, int rotate)
 {
     if (result == true)
     {
         Queue = 0;
     }
 }
Esempio n. 3
0
 public static PlayerMatrix ClearShip(PlayerMatrix pM, Ship s)
 {
     if (s.rotate)
     {
         for (int i = s.y; i < s.y + s.size; i++)
         {
             pM.playerMatrix[i, s.x] -= (s.size * 2) - 1;
         }
     }
     else
     {
         for (int j = s.x; j < s.x + s.size; j++)
         {
             pM.playerMatrix[s.y, j] -= (s.size * 2) - 1;
         }
     }
     return(pM);
 }
Esempio n. 4
0
        public static PlayerMatrix EnemyPlaceShip(int size, PlayerMatrix pM)
        {
            Ship s = new Ship(size);

            SetShip(pM, s);
            do
            {
                ClearShip(pM, s);
                s = Randomize(size);
                SetShip(pM, s);
                if (CheckAllPosition(pM))
                {
                    pM = SuroundShip(pM, s);
                    break;
                }
            } while (true);
            return(pM);
        }
Esempio n. 5
0
        public static PlayerMatrix EnemyPlaceShips(PlayerMatrix pM)
        {
            pM = EnemyPlaceShip(4, pM);
            for (int i = 0; i < 2; i++)
            {
                pM = EnemyPlaceShip(3, pM);
            }
            for (int i = 0; i < 3; i++)
            {
                pM = EnemyPlaceShip(2, pM);
            }
            for (int i = 0; i < 4; i++)
            {
                pM = EnemyPlaceShip(1, pM);
            }

            return(pM);
        }
Esempio n. 6
0
 public static bool CheckAllPosition(PlayerMatrix pM)
 {
     try
     {
         for (int i = 0; i < 10; i++)
         {
             for (int j = 0; j < 10; j++)
             {
                 if ((pM.playerMatrix[i, j] != 0) && (pM.playerMatrix[i, j] != 1) && (pM.playerMatrix[i, j] != 3) && (pM.playerMatrix[i, j] != 5) && (pM.playerMatrix[i, j] != 7) && (pM.playerMatrix[i, j] != 9))
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 7
0
 public static PlayerMatrix SuroundShip(PlayerMatrix pM, Ship s)
 {
     if (s.rotate)
     {
         for (int i = s.x - 1; i <= s.x + 1; i++)
         {
             for (int j = s.y - 1; j <= s.y + s.size; j++)
             {
                 if (i < 10 && j < 10 && i >= 0 && j >= 0)
                 {
                     if (pM.playerMatrix[j, i] == 0)
                     {
                         pM.playerMatrix[j, i] = 9;
                     }
                 }
             }
         }
     }
     else
     {
         for (int i = s.x - 1; i <= s.x + s.size; i++)
         {
             for (int j = s.y - 1; j <= s.y + 1; j++)
             {
                 if (i < 10 && j < 10 && i >= 0 && j >= 0)
                 {
                     if (pM.playerMatrix[j, i] == 0)
                     {
                         pM.playerMatrix[j, i] = 9;
                     }
                 }
             }
         }
     }
     return(pM);
 }
Esempio n. 8
0
        public static PlayerMatrix ShootEnemy(PlayerMatrix pM, int x, int y)
        {
            if (pM.playerMatrix[x, y] == 1 || pM.playerMatrix[x, y] == 3 || pM.playerMatrix[x, y] == 5 || pM.playerMatrix[x, y] == 7)
            {
                if (pM.playerMatrix[x, y] == 1)
                {
                    pM.playerMatrix[x, y] = 999; // zatopiony
                    defeat = true;
                    hit    = false;
                    int truey  = y;
                    int truex  = x;
                    int rotate = 2; // pozioma
                    int lenght = 0;


                    y--; //zatapiamy pozostałe maszty
                    if (y >= 0)
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            rotate = 2;//poziom
                            pM.playerMatrix[x, y] = 999;
                            y--;
                            if (y < 0)
                            {
                                break;
                            }
                        }
                    }
                    y = truey + 1;
                    if (y <= 9)
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            rotate = 2;//poziom
                            pM.playerMatrix[x, y] = 999;
                            y++;
                            if (y > 9)
                            {
                                break;
                            }
                        }
                    }
                    x--;
                    y = truey;
                    if (x >= 0)
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            rotate = 1;//pionowa
                            pM.playerMatrix[x, y] = 999;
                            x--;
                            if (x < 0)
                            {
                                break;
                            }
                        }
                    }
                    x = truex + 1;
                    if (x <= 9)
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            rotate = 1;//pionowa
                            pM.playerMatrix[x, y] = 999;
                            x++;
                            if (x > 9)
                            {
                                break;
                            }
                        }
                    }

                    x = truex;
                    y = truey;
                    if (rotate == 1) //pionowa
                    {
                        while (x > 0 && pM.playerMatrix[x, y] == 999)
                        {
                            if (pM.playerMatrix[x - 1, y] == 999)
                            {
                                truex = x - 1;
                            }
                            x--;
                        }
                        x = truex;
                        while (x < 9 && pM.playerMatrix[x, y] == 999)
                        {
                            x++;
                            lenght++;
                        }
                    }
                    else //poziom
                    {
                        while (y > 0 && pM.playerMatrix[x, y] == 999)
                        {
                            if (pM.playerMatrix[x, y - 1] == 999)
                            {
                                truey = y - 1;
                            }
                            y--;
                        }
                        y = truey;
                        while (y < 9 && pM.playerMatrix[x, y] == 999)
                        {
                            y++;
                            lenght++;
                        }
                    }
                    defeatr      = rotate;
                    defeatx      = truey;
                    defeaty      = truex;
                    defeatlenght = lenght;
                    if (rotate == 1)
                    {
                        for (int i = truey - 1; i <= truey + 1; i++)
                        {
                            for (int j = truex - 1; j <= truex + lenght; j++)
                            {
                                if (i < 10 && j < 10 && i >= 0 && j >= 0)
                                {
                                    if (pM.playerMatrix[j, i] != 999)
                                    {
                                        pM.playerMatrix[j, i] = 123;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = truex - 1; i <= truex + 1; i++)
                        {
                            for (int j = truey - 1; j <= truey + lenght; j++)
                            {
                                if (i < 10 && j < 10 && i >= 0 && j >= 0)
                                {
                                    if (pM.playerMatrix[i, j] != 999)
                                    {
                                        pM.playerMatrix[i, j] = 123;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    pM.playerMatrix[x, y] = 321; //trafiony
                    hit = true;
                    int truey = y;
                    int truex = x;

                    y--;
                    if (y >= 0)   //odejmujemy stałą 2 od pozostałych masztów
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            if (pM.playerMatrix[x, y] != 321)
                            {
                                pM.playerMatrix[x, y] -= 2;
                            }
                            y--;
                            if (y < 0)
                            {
                                break;
                            }
                        }
                    }
                    y = truey + 1;
                    if (y <= 9)
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            if (pM.playerMatrix[x, y] != 321)
                            {
                                pM.playerMatrix[x, y] -= 2;
                            }
                            y++;
                            if (y > 9)
                            {
                                break;
                            }
                        }
                    }
                    x--;
                    y = truey;
                    if (x >= 0)
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            if (pM.playerMatrix[x, y] != 321)
                            {
                                pM.playerMatrix[x, y] -= 2;
                            }
                            x--;
                            if (x < 0)
                            {
                                break;
                            }
                        }
                    }
                    x = truex + 1;
                    if (x <= 9)
                    {
                        while (pM.playerMatrix[x, y] != 9 && pM.playerMatrix[x, y] != 18 && pM.playerMatrix[x, y] != 123)
                        {
                            if (pM.playerMatrix[x, y] != 321)
                            {
                                pM.playerMatrix[x, y] -= 2;
                            }
                            x++;
                            if (x > 9)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            if (pM.playerMatrix[x, y] != 321 && pM.playerMatrix[x, y] != 999)
            {
                hit = false;
                pM.playerMatrix[x, y] = 123;
            }
            return(pM);
        }
Esempio n. 9
0
        public static void StartNewGame()
        {
            PlayerMatrix pM = new PlayerMatrix();
            PlayerMatrix eM = new PlayerMatrix();
            EnenemyPlans eP = new EnenemyPlans();

            Methods.EnterNicknameP1();


            PlaceShips(pM, true);
            EnemyPlaceShips(eM);
            Methods.CreateScreen(eM, true);

            Console.Clear();
            Methods.GameScreen2(0, 0, pM, Const.COMPUTER_NICKNAME);
            //W GAME SCREEN ZROBIC 2 OBRAZY
            while (game)
            {
                Methods.GameScreen2(0, 0, pM, Const.COMPUTER_NICKNAME);
                if (turn == false)
                {
                    eM = Methods.PlaceBomb(eM);

                    Methods.GameScreen(0, 0, eM);

                    if (eM.playerMatrix[playerHit.X, playerHit.Y] == 999 || eM.playerMatrix[playerHit.X, playerHit.Y] == 321) //to nie działa
                    {
                        turn = false;
                        g1  += state * combo;
                        combo++;
                    }
                    else
                    {
                        turn  = true;
                        combo = 1;
                    }
                }

                else
                {
                    coordinate = eP.Shoot(hit, pM);
                    pM         = ShootEnemy(pM, coordinate.X, coordinate.Y);

                    Methods.GameScreen2(0, 0, pM, Const.COMPUTER_NICKNAME);

                    if (pM.playerMatrix[coordinate.X, coordinate.Y] == 999 || pM.playerMatrix[coordinate.X, coordinate.Y] == 321)
                    {
                        turn = true;
                        g2  += state * combo;
                        combo++;
                    }
                    else
                    {
                        turn  = false;
                        combo = 1;
                    }
                }

                if (defeat == true)
                {
                    eP.IsDefeat(defeat, pM, defeatlenght, defeaty, defeatx, defeatr);
                    defeat = false;
                }
                int count = 0;
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (pM.playerMatrix[i, j] == 999)
                        {
                            count++;
                        }
                    }
                }
                if (count == 20)
                {
                    game = false;
                    Methods.SetCursor(35, 16);
                    Methods.ColorText(String.Format("Wygrał: {0}", Const.COMPUTER_NICKNAME));
                    DAL.HighscoreModel.InsertInto(Const.COMPUTER_NICKNAME, g2);
                }
                else
                {
                    count = 0;
                    for (int i = 0; i < 10; i++)
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            if (eM.playerMatrix[i, j] == 999)
                            {
                                count++;
                            }
                        }
                    }
                    if (count == 20)
                    {
                        game = false;
                        Methods.SetCursor(35, 16);
                        Methods.ColorText(String.Format("Wygrał: {0}", Variable.PLAYER1_NICKNAME));
                        DAL.HighscoreModel.InsertInto(Variable.PLAYER1_NICKNAME, g1);
                        Console.Read();
                        //MATKO JAKI PRL
                    }
                }
            }
        }
Esempio n. 10
0
        public static void StartNewGame2Players()
        {
            PlayerMatrix pM = new PlayerMatrix();
            PlayerMatrix eM = new PlayerMatrix();
            EnenemyPlans eP = new EnenemyPlans();

            //NIE MAM POJECIA DLACZEGO DOUBLE ENTER
            Methods.EnterNicknameP2();



            PlaceShips(pM, true);
            PlaceShips(eM, false);
            //EnemyPlaceShips(eM);
            //EnemyPlaceShips(pM);

            Console.Clear();
            Methods.GameScreen2(0, 0, pM, Variable.PLAYER2_NICKNAME);
            while (game)
            {
                if (turn == false)
                {
                    eM = Methods.PlaceBomb(eM);
                    Methods.GameScreen(0, 0, eM);

                    if (eM.playerMatrix[playerHit.X, playerHit.Y] == 999 || eM.playerMatrix[playerHit.X, playerHit.Y] == 321) //to nie działa
                    {
                        turn = false;
                        g1  += state * combo;
                        combo++;
                    }
                    else
                    {
                        turn  = true;
                        combo = 1;
                    }
                }

                else
                {
                    pM = Methods.PlaceBomb2(pM);
                    Methods.GameScreen2(0, 0, pM, Variable.PLAYER2_NICKNAME);


                    if (pM.playerMatrix[playerHit.X, playerHit.Y] == 999 || pM.playerMatrix[playerHit.X, playerHit.Y] == 321)
                    {
                        turn = true;
                        g2  += state * combo;
                        combo++;
                    }
                    else
                    {
                        turn  = false;
                        combo = 1;
                    }
                }


                int count = 0;
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (pM.playerMatrix[i, j] == 999)
                        {
                            count++;
                        }
                    }
                }
                if (count == 20)
                {
                    game = false;
                    Methods.SetCursor(35, 16);
                    Methods.ColorText(String.Format("Wygrał: {0}", Variable.PLAYER2_NICKNAME));
                    DAL.HighscoreModel.InsertInto(Variable.PLAYER2_NICKNAME, g2);
                    Console.Read();
                }
                else
                {
                    count = 0;
                    for (int i = 0; i < 10; i++)
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            if (eM.playerMatrix[i, j] == 999)
                            {
                                count++;
                            }
                        }
                    }
                    if (count == 20)
                    {
                        game = false;
                        Methods.SetCursor(35, 16);
                        Methods.ColorText(String.Format("Wygrał: {0}", Variable.PLAYER1_NICKNAME));
                        DAL.HighscoreModel.InsertInto(Variable.PLAYER1_NICKNAME, g1);
                        Console.Read();
                        //MATKO JAKI PRL
                    }
                }
            }
        }
Esempio n. 11
0
        public Coordinate Shoot(bool result, PlayerMatrix pM) // ta pizda na granicy x0 lub x9

        {
            Available = 0;
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (pM.playerMatrix[i, j] != 123 && pM.playerMatrix[i, j] != 999 && pM.playerMatrix[i, j] != 321 /* && pM.playerMatrix[i, j] != 9 && pM.playerMatrix[i, j] != 18*/)
                    {
                        RestPoints[Available++] = i * 10 + j;
                    }
                }
            }
            if (!result)
            {
                if (Queue == 0)     //nie trafił i nie był w sekwencji
                {
                    Random r      = new Random();
                    int    random = r.Next(0, Available);
                    coordinate = new Coordinate(RestPoints[random]);
                    RemovePoint(RestPoints[random]);
                    return(coordinate);
                }
                else     // nie trafił ale był w sekwencji
                {
                    coordinate = State[Matrix[0, Point]];

                    if (coordinate.X > 9 || coordinate.X < 0 || coordinate.Y > 9 || coordinate.Y < 0)
                    {
                        while (coordinate.X > 9 || coordinate.X < 0 || coordinate.Y > 9 || coordinate.Y < 0)
                        {
                            Point      = Matrix[0, Point];
                            coordinate = State[Matrix[0, Point]];
                        }
                        //   coordinate = CheckisFree(coordinate, 0);
                    }
                    else
                    {
                        Point = Matrix[0, Point];
                        ///coordinate = CheckisFree(coordinate, 0);
                    }

                    RemovePoint(State[Point].X * 10 + State[Point].Y);
                    Queue++;
                    return(coordinate);
                }
            }
            else
            {
                if (Queue == 0)
                {
                    Coordinate point = FirstHit(coordinate);
                    Queue++;
                    coordinate = point;
                    if (coordinate.X > 9 || coordinate.X < 0 || coordinate.Y > 9 || coordinate.Y < 0)
                    {
                        while (coordinate.X > 9 || coordinate.X < 0 || coordinate.Y > 9 || coordinate.Y < 0)
                        {
                            coordinate = State[Matrix[0, Point]];
                            Point      = Matrix[0, Point];
                        }
                        //coordinate = CheckisFree(coordinate, 0);
                    }
                }
                else
                {
                    Queue++;
                    coordinate = State[Matrix[1, Point]];
                    if (coordinate.X > 9 || coordinate.X < 0 || coordinate.Y > 9 || coordinate.Y < 0)
                    {
                        while (coordinate.X > 9 || coordinate.X < 0 || coordinate.Y > 9 || coordinate.Y < 0)
                        {
                            coordinate = State[Matrix[0, Point]];
                            Point      = Matrix[0, Point];
                        }
                        // coordinate = CheckisFree(coordinate, 0);
                    }
                    else
                    {
                        Point = Matrix[1, Point];
                        // coordinate = CheckisFree(coordinate, 1);
                    }
                }


                RemovePoint(State[Point].X * 10 + State[Point].Y);
                return(coordinate);
            }
        }