Site icon YetiCraft

Micro:Battleship

This is the first of many ‘Micro:Challenges’ for use by TAG Junior-Engineers with Micro:Bit devices. The intent of this particular post is to create an initial layout, feedback flow, and some interaction to test the concept for ongoing use.

Description

This program, when loaded on two or more Micro:Bits and running in near proximity to each other will allow players to play a simple game that is vaguely similar to Battleship.

How it works | How to play:

Program Code

The code can also be found at https://makecode.microbit.org/_MohWmDViRdJ0

def on_received_number(receivedNumber):
    global channel
    channel = receivedNumber
    basic.show_number(channel)
    radio.set_group(channel)
radio.on_received_number(on_received_number)

def on_button_pressed_a():
    global channel
    channel = randint(0, 5)
    radio.send_number(channel)
    basic.show_number(channel)
    radio.set_group(channel)
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_received_string(receivedString):
    basic.show_icon(IconNames.NO)
    music.start_melody(music.built_in_melody(Melodies.DADADADUM),
        MelodyOptions.ONCE)
radio.on_received_string(on_received_string)

def on_button_pressed_b():
    radio.send_string("BOOM")
input.on_button_pressed(Button.B, on_button_pressed_b)

channel = 0
radio.set_group(channel)

Challenges

Players can still press the B key – even after they have been disqualified. That does not seem fair.

Players can immediately hit the B key at start of the game – this might be a quick strategy, or it might be a flaw. Perhaps the first press of the B key should be disallowed until after the first channel change?

Can you think of more improvements?

Exit mobile version