Exemple #1
0
 // Commit position of curShip
 void CommitCurShip()
 {
     if (!CanCommit())
     {
         MessageBox.Show("You can't put " + curShip.name + " ship here");
         return;
     }
     // Unblock other buttons
     ShipButton.active = false;
     // Decrease ships count
     ShipButton.decreseShipLeft();
     // Put ship into the list
     ships.Add(curShip);
 }
Exemple #2
0
 void setProgramState(ProgramState state)
 {
     if (state == ProgramState.init)
     {
         InitProgramm();
         programState = state;
     }
     else if (state == ProgramState.end)
     {
         EndGame();
         programState = state;
     }
     else if (state == ProgramState.game && ShipButton.GetShipsLeft() == 0)
     {
         programState = state;
         BeginGame();
     }
 }
Exemple #3
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));
                }
            }
        }