Exemplo n.º 1
0
        internal static void Initialize()
        {
            Console.Clear();

            int pos = 0;

            //Clear matrix
            Array.Clear(Dipendences.campoNostro, 0, Dipendences.campoNostro.GetLength(0) * Dipendences.campoNostro.GetLength(1));
            Array.Clear(Dipendences.campoNemico, 0, Dipendences.campoNemico.GetLength(0) * Dipendences.campoNemico.GetLength(1));

            Game_Form.Put p = new Game_Form.Put(); //Chiedi le posizioni
            p.ShowDialog();

            foreach (int n in Dipendences.x) //Inserisci le posizioni dentro la matrice
            {
                Dipendences.campoNostro[n, Dipendences.y[pos]] = Dipendences.defStatus;

                pos++;
            }

            Instruments.GMMessage("Initializing AI.....");

            AI.Intialize();

            Console.Clear();

            Aggiorna();

            //Il primo turno è il mio

            Console.ReadKey();
        }
Exemplo n.º 2
0
        /*
         * Programmers: Leonardo Baldazzi, Tommaso Brandinelli
         * Company: OSS inc.
         * Program summary: Simulating Battleship Online via MYSQL Database
         * SubProgram summary: Log-In/Sign-Up user, download `.conf` files, check for updates
         * Class summary: Matchmaking Class
         *
         * Copyright (c) 2018-19 OSS inc. - All Rights Reserved
         */
        internal static void Start()
        {
            string[] usrs; //Usernames array
            Random   rand = new Random();
            int      randomized;

            MySqlCommand com = new MySqlCommand("INSERT INTO `matchmaking`(`username`) VALUES (@usr)", Usr.conn); //Insert user in matchmaking database

            com.Parameters.Add("@usr", MySqlDbType.VarChar).Value = Dipendences.username;

            com.ExecuteNonQuery();

            while (true)
            {
                Usr.adapter = new MySqlDataAdapter("SELECT * FROM `matchmaking` WHERE 1", Usr.conn);
                Usr.adapter.Fill(Usr.table);

                usrs = new string[Usr.table.Rows.Count];

                for (int i = 0; i < Usr.table.Rows.Count; i++) //Put query in usrs
                {
                    usrs[i] = Usr.table.Rows[i][0].ToString();
                }

                if (usrs.Length >= 1)
                {
                    randomized = rand.Next(0, usrs.Length);
                    Dipendences.enemyUsername = usrs[randomized]; //Select a random enemy from table

                    if (Dipendences.enemyUsername != Dipendences.username)
                    {
                        break; //Matched
                    }
                }

                Console.Clear();
                Console.WriteLine("Matchmaking....");
            }

            Usr.table.Clear();

            Thread.Sleep(1000);

            MySqlCommand delM = new MySqlCommand("DELETE FROM `matchmaking` WHERE `username` = '" + Dipendences.username + "'", Usr.conn); //Delete in matchmaking table

            delM.ExecuteNonQuery();

            Console.WriteLine("The enemy is: " + Dipendences.enemyUsername);

            Thread.Sleep(1000);

            Console.Clear();

            Game_Form.Put p = new Game_Form.Put();
            p.ShowDialog();

            Console.WriteLine("I'm waiting.....");

            Console.Clear();


            Game_Form.Game.Initialize();
        }