Exemplo n.º 1
0
        //End drop and drag stuff

        //once this button is hit it will do 1 of two things
        //when game mode is false
        //1st it check to make sure the player has added all ships, and it will also make sure i didnt screw up... :P
        //then it will send array of players ships to board class *still not coded...
        //when game mode is true
        //this is were the player drops pegs onto board
        private void nextStepButton_Click(object sender, EventArgs e)
        {
            resetexceptionTime(); //resets 30 min exception thing

            //next step button has two stages 1st Ship placement, 2nd Attacking
            switch (Globals.gameMode)
            {
            //Ship placement stage
            case false:

                //this is to make sure all 20 ship and ship parts are there.
                if (checkTotalShips() != 0)
                {
                    playerActionLabel.Text = Globals.stringTheme[1];
                }
                else
                {
                    Globals.gameMode = true;

                    //stops button animation
                    buttonTimer.Stop();
                    nextStepButton.BackgroundImage = null;

                    playSound(Globals.soundPath + NEWGAMESOUND);

                    //builds player board
                    foreach (PictureBox pb in playerSHPPanel.Controls)
                    {
                        Globals.SHPBox  = breakUpName((pb.Tag).ToString());
                        Globals.SHPType = breakUpName(pb.Name);

                        Globals.playerBoard[Convert.ToInt32(Globals.SHPBox[1])] = (Convert.ToChar(Globals.SHPType[0]) == AIRCRAFTCARRIER) ? AIRCRAFTCARRIER :
                                                                                  (Convert.ToChar(Globals.SHPType[0]) == BATTLESHIP) ? BATTLESHIP :
                                                                                  (Convert.ToChar(Globals.SHPType[0]) == DESTROYER) ? DESTROYER :
                                                                                  (Convert.ToChar(Globals.SHPType[0]) == SUBMARINE) ? SUBMARINE :
                                                                                  (Convert.ToChar(Globals.SHPType[0]) == PATROLBOAT) ? PATROLBOAT : OPENWATER;
                    }

                    //changes labels to say attack and drag peg
                    nextStepButton.Text    = Globals.stringTheme[2];
                    playerActionLabel.Text = Globals.stringTheme[3];

                    //sends players board to Game class
                    makeGame.setBoards(Globals.difficulty, Globals.playerBoard);
                }
                break;

            //Attacking stage
            case true:
                //This checks to see if the user placed a peg
                if (Globals.pegPlaced == false && makeGame.hasWon() == NOBODY)
                {
                    playerActionLabel.Text = Globals.stringTheme[3];
                }
                else if (makeGame.hasWon() == NOBODY)
                {
                    //pass's user attack cord to set the spot the user hits to 'x' on the aiboard in game class
                    char player_hit = makeGame.userAttack(Globals.AttackSpot);

                    bool userHit = (player_hit != OPENWATER) ? true : false;

                    int shipSize = getShipSize(player_hit);

                    int stringnum = (player_hit == AIRCRAFTCARRIER) ? 5 :
                                    (player_hit == BATTLESHIP) ? 6 :
                                    (player_hit == DESTROYER) ? 7 :
                                    (player_hit == SUBMARINE) ? 8 :
                                    (player_hit == PATROLBOAT) ? 9 : 11;

                    Globals.makeHit = (player_hit != OPENWATER) ? true : false;
                    fireSound();

                    //changes label to say hit or miss
                    playerActionLabel.Text = (player_hit != OPENWATER) ? Globals.stringTheme[16] : Globals.stringTheme[11];

                    //change the image to hit or miss
                    ((PictureBox)playerATKPanel.Controls[Globals.SHPBox[0] + Globals.SHPBox[1]]).Image = Image.FromFile(Globals.imgPath + ((player_hit != OPENWATER) ? HIT : MISS));
                    ((PictureBox)playerATKPanel.Controls[Globals.SHPBox[0] + Globals.SHPBox[1]]).Name  = player_hit.ToString() + Globals.SHPBox[1];

                    //if ship has sunk change images to show ship and tell user what ship was sunk
                    if (makeGame.checkShipHealth(player_hit) == 0)
                    {
                        playerActionLabel.Text = Globals.stringTheme[18] + Globals.stringTheme[stringnum];
                        changeAiShipImages(player_hit, shipSize, player_hit);
                    }

                    //this checks to see if the user wins
                    if (makeGame.hasWon() == USER)
                    {
                        playSound(Globals.soundPath + WINSOUND);

                        //this tell player if they won.
                        playerActionLabel.Text = Globals.stringTheme[17];

                        //destroy all SHPPanel Picktureboxs and add victory image
                        destroy_Grid();

                        //sets SHPPanel image to win
                        playerSHPPanel.BackgroundImage = Image.FromFile(Globals.imgPath + VICTORY);
                    }

                    //sets game info so player can attack again
                    Globals.AttackSpot = -1;
                    Globals.pegPlaced  = false;
                    buttonTimer.Stop();
                    nextStepButton.BackgroundImage     = null;
                    undoPegPlaceButton.BackgroundImage = null;

                    aiAttack();
                }
                break;
            }
        }