Esempio n. 1
0
 public void Init(Size size, Player player, bool autoFill = false)
 {
     this.size   = size;
     this.player = player;
     GameInit.setField(this, size, player);
     ships = new List <Ship>();
     if (autoFill)
     {
         RandomPutShip();
     }
 }
Esempio n. 2
0
        // Button reset handler
        private void buttonReset_Click(object sender, EventArgs e)
        {
            if (programState == ProgramState.init)
            {
                buttonChangeGameState.Text = "Begin battle!";
                setStatusLabel();


                // Reset ally field
                fieldAlly.Reset();

                // Init buttons for ship chosing
                GameInit.SetInitButtons(groupBoxInit, fieldAlly);
                ShipButton.active = false;
            }
        }
Esempio n. 3
0
        void InitProgramm()
        {
            buttonChangeGameState.Text = "Begin battle!";
            setStatusLabel();

            // Open addition buttons
            buttonReset.Visible      = true;
            buttonFillRandom.Visible = true;

            // Init field
            fieldEnemy.Init(fieldSize, Player.enemy);
            fieldAlly.Init(fieldSize, Player.ally);


            // Init buttons for ship chosing
            GameInit.SetInitButtons(groupBoxInit, fieldAlly);
        }
Esempio n. 4
0
        // Fill field in random way
        public void RandomPutShip()
        {
            if (player == Player.ally)
            {
                Reset();
                // block shipButtons
                ShipButton.ResetShipLeftToZero();
            }
            var random = new Random();

            //var ships =;
            foreach (var ship in GameInit.GetShips())
            {
                curShip = ship;
                for (int i = 0; i < curShip.count; i++)
                {
                    bool possible, commit;
                    do
                    {
                        curPos    = new Point(random.Next(0, size.Width - 1), random.Next(0, size.Height - 1));
                        curRotate = random.Next(10) % 2 == 0;

                        possible = PossiblePosition(curPos, curRotate);
                        commit   = false;
                        if (possible)
                        {
                            PutShip(true);
                            commit = CanCommit();
                            if (!commit)
                            {
                                PutShip(false);
                            }
                            else
                            {
                                // Add ship to curships
                                ships.Add(new Ship(curShip));
                            }
                        }
                    } while (!(possible && commit));
                }
            }
        }
Esempio n. 5
0
        // Inicialization part---------------------------------------------

        // Make field empty
        public void Reset()
        {
            // Clear field and
            ships.Clear();
            GameInit.setField(this, size, player);
        }