× Main Menu

C# Tutorial – Create a Simple Battle Ship Game in Visual Studio

In this tutorial we will show you how to create a Simple old school battle ship game in visual studio using C# programming language. This game is a complicated one and can be a little daunting for the beginners. If you are unclear about some of the concepts then try out few other tutorials here and come back to this, it will still be here when you are ready. In this game you will create an AI player where you can play against them to win your sea battles.  The old joke “you sunk my battle ship”, may apply here but it’s entirely up to you.

Lesson Objectives –

  1. Complete the simple battle ship game in visual studio
  2. Use custom background on the windows form
  3. AI make decisions in the game
  4. Player controls their ships from list of moves
  5. Keep track of AI movements
  6. Using windows GUI to create a game
  7. Using LIST arrays in C#
  8. Using LOOPs in C#
  9. Searching indexes of the list arrays and matching them to integers
  10. Using System Diagnostics show system debug information in the outputs window
  11. Using multiple timers and controlling them dynamically
  12. Showing customised win, lose and draw message box

Full Video Tutorial


Download the BattlShip game assets here. 


8 responses to “C# Tutorial – Create a Simple Battle Ship Game in Visual Studio”

  1. charlie says:

    if (enemyPosition[index].Enabled && rounds > 0 ) system.argumentoutofrangeexception: ‘Index was out of range. Must be non-negative and less than the size of the collection

  2. John says:

    I have the same error as Charlie

  3. Anhar Ali says:

    Hi this error means that index has either gone over the number of buttons enabled on the enemy position or it has gone below it. The code from the attack enemy position event check the line before the if statement where we have declared the index variable it’s on page 11. I think it might have happened because it cannot find any buttons.

  4. Beth says:

    Does this still work?

  5. Anhar Ali says:


  6. John says:

    Hello, my code is now running and the game works well except for the fact that the enemy does not appear to be placing any ships – I miss every time because there are no ships to hit on the enemy board so the computer always wins. What could be causing this?

  7. slots says:

    the code is working however I can only pick 3 buttons before cpu picks 3, if cpu picked 3 buttons before me then Im unable to pick all 3 and the game never starts… no idea whats wrong… i have also detected a typo in enemyPicksPosition => if (totalEnemyShips > 1) this should be if (totalEnemyShips < 1) otherwise enemy will only pick 1 button.

  8. rosieeemaryyy says:

    Does anyone know a way to do this without buttons? 😛

Comment on this tutorial and let us know how you got on -

%d bloggers like this: