コード例 #1
0
ファイル: Program.cs プロジェクト: Pakimonia/BattleShip
        static void Main(string[] args)
        {
            User you    = new User();
            Pk   pk     = new Pk();
            int  random = 1;

            pk.FillPk();
            you.FillYou();
            pk.RankingPk();
            you.RankingYourField(random);
            Battle(pk, you);

            if (pk.SumShip == 0)
            {
                Console.WriteLine("You win");
            }
            else if (you.SumShip == 0)
            {
                Console.WriteLine("You lose");
            }
            else if (pk.SumShip == you.SumShip)
            {
                Console.WriteLine("Nichia");
            }
            else
            {
                Console.WriteLine("Eror");
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Pakimonia/BattleShip
 static void Battle(Pk pk, User you)
 {
     do
     {
         BatelPk(pk, you);
         pk.PrintPk();
         BattelYou(you, pk);
         if (pk.SumShip <= 0 || you.SumShip <= 0)
         {
             break;
         }
     } while (true);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: Pakimonia/BattleShip
        static void BatelPk(Pk pk, User you)
        {
            Random rand = new Random();
            int    aty  = rand.Next(1, 10);
            int    atx  = rand.Next(1, 10);
            int    way  = rand.Next(1, 10);

            for (int i = 0; i < 1;)
            {
Label:
                if (you.youField[atx][aty] == "#")
                {
                    you.youField[atx][aty] = "0";
                    i++;
                }
                else if (you.youField[atx][aty] == "1")
                {
                    you.youField[atx][aty] = "¤";
                    aty = rand.Next(1, 10);
                    atx = rand.Next(1, 10);
                    goto Label;
                }
                else if (you.youField[atx][aty] == "2")
                {
                    you.youField[atx][aty] = "¤";
                    way = rand.Next(1, 4);
                    if (way == 1)
                    {
                        atx--;
                    }
                    else if (way == 2)
                    {
                        atx++;
                    }
                    else if (way == 3)
                    {
                        aty++;
                    }
                    else if (way == 4)
                    {
                        aty--;
                    }
                    if (you.youField[atx][aty] == "¤" && you.youField[atx][aty] == "0")
                    {
                        BatelPk(pk, you);
                    }
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Pakimonia/BattleShip
        static void BattelYou(User you, Pk computer)
        {
            char perevx;
            int  perevy;

            Console.WriteLine("Enter cordinete");
            perevx = Console.ReadLine().ToCharArray()[0];
            perevy = Console.Read();
            if (perevx == '@')
            {
                computer.SumShip = 0;
                return;
            }
            if (perevx >= 65 && perevx <= 74)
            {
                you.x = perevx - 64;
            }
            else
            {
                Console.Clear();
                Console.WriteLine("These coordinates are not correct");
                BattelYou(you, computer);
            }
            if (perevy >= 0 && perevy <= 11)
            {
                you.y = perevy + 1;
            }
            else
            {
                Console.Clear();
                Console.WriteLine("These coordinates are not correct");
                BattelYou(you, computer);
            }
            if (you.x >= 11 || you.y >= 11 || you.x == 0 || you.y == 0)
            {
                Console.Clear();
                Console.WriteLine("These coordinates are not correct");
                BattelYou(you, computer);
            }
            else
            {
                if (computer.youField[you.y][you.x] == "#" || computer.youField[you.y][you.x] == "O")
                {
                    Console.Clear();
                    Console.WriteLine("You not catch");
                    you.battleField[you.y][you.x] = "0";
                    you.PrintYou();
                }
                else if (computer.youField[you.y][you.x] == "1")
                {
                    computer.SumShip--;
                    Console.Clear();
                    Console.WriteLine("You killed");
                    you.battleField[you.y][you.x] = "¤";
                    you.PrintYou();
                    BattelYou(you, computer);
                }
                else if (computer.youField[you.y][you.x] == "2")
                {
                    computer.SumShip--;
                    Console.Clear();
                    Console.WriteLine("You catch");
                    you.battleField[you.y][you.x] = "¤";
                    you.PrintYou();
                    BattelYou(you, computer);
                }
                else if (computer.youField[you.y][you.x] == "3")
                {
                    computer.SumShip--;
                    Console.Clear();
                    Console.WriteLine("You catch");
                    you.battleField[you.y][you.x] = "¤";
                    you.PrintYou();
                    BattelYou(you, computer);
                }
                else if (computer.youField[you.y][you.x] == "4")
                {
                    computer.SumShip--;
                    Console.Clear();
                    Console.WriteLine("You catch");
                    you.battleField[you.y][you.x] = "¤";
                    you.PrintYou();
                    BattelYou(you, computer);
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("These coordinates are not correct");
                    BattelYou(you, computer);
                }
            }
        }