element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
micro:bit Blog [PROJECT] Battleships game
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join microbit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: andyforeverest
  • Date Created: 30 Nov 2018 2:01 PM Date Created
  • Views 1591 views
  • Likes 3 likes
  • Comments 1 comment
  • intermediate micro:bit projects
  • micro:bit education giveaway
  • micro:bit giveaway
  • intermediate_microbit_projects
Related
Recommended

[PROJECT] Battleships game

andyforeverest
andyforeverest
30 Nov 2018

This is going to be a game played between two micro:bits.

  • Each player has a ship displayed on the LED matrix. A ship can be a single dot/LED or several LEDs.
  • One LED in the ship is “the head” of the ship. When the “head” takes a hit, the game ends.
  • Each player can select the location of the “missile” they are sending to the enemy. X coordinate is selected by pressing button A and Y coordinate is selected by pressing button B.
  • The communication between them is via radio.


Step 1 - Display the shipimage
The “head” of the ship is the point of (3, 2) coordinates. Once this point takes a hit, the player loses the game.
The ship can be a also a single dot/LED. The advantage of this approach is that the ship can be randomly positioned to a location on the display in the beginning of the game.
image








Step 2 - Setting the missile’s coordinates
Pressing button A will select one value between 0 and 4 - this will be x coordinate of the missile.

Pressing button B will select one value between 0 and 4 - this will be y coordinate of the missile.

 

image

 

Step 3 - Sending the missile
I am going to combine the two values (of missile_x and missile_y) like so: 10 * missile_x + missile_y.

For example: if missile_x is 3 and missile_y is 2, then the number we are sending is: 10 * 3 + 2 = 32.

 

image

 

Step 4 - receive the enemy missile
When the number is received, we recover the coordinates and then check if they represent a “kill”.

 

image


The way to recover the coordinates is this:

  • missile_y is the remainder of division between the receivedNumber and 10;
  • missile_x is (receivedNumber - missile_y) / 10

For example:if receivedNumber = 41 then:

  • missile_y = remainder of (41 / 10) = 1;
  • missile_x = (41 - 1)/10 = 4.


If the coordinates are the same with the “head” of the battleship, the variable “iLost” is set to True (the variable was set to False in “on start”).

 

Step 5 - game ending

 

In case we lose, we can send a signal that we lost. This way, the other player will know they won.
The way to do this is by sending a number (that cannot be coordinates) when we take a fatal hit. This number needs to be above 44.
The forever loop looks like this:

 

image

 


The on radio received looks like this:

 

image


Ways to improve the game:

  1. develop a way to make sure that each player takes turns when shooting;
  2. restart the game without resetting and keep a score.
  • Sign in to reply
  • jomoenginer
    jomoenginer over 6 years ago

    Very cool!   I'm looking forward to seeing how this turns out.  

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube