Created
February 11, 2026 10:16
-
-
Save Taresin/deffd2f30e7da177d1597f7a150ed529 to your computer and use it in GitHub Desktop.
his project will demonstrate Robot to Robot messaging using a simple Scissors Paper Rock game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ---------------------------------------------------------------------------- # | |
| # # | |
| # Module: main.py # | |
| # Author: dougy lee # | |
| # Created: 2/7/2026, 8:53:10 AM # | |
| # # | |
| # Project: Scissors Paper Rock # | |
| # Description: This project will demonstrate Robot to Robot messaging # | |
| # using a simple Scissors Paper Rock game # | |
| # # | |
| # ---------------------------------------------------------------------------- # | |
| # Library imports | |
| from vex import * | |
| from vex_globals import * | |
| import random | |
| # Robot should be defined by default | |
| robot = Robot() | |
| # Display identifier | |
| robot.screen.print(robot.get_name()) | |
| # Define Scissors Paper Rock game | |
| SCISSORS = 0 | |
| PAPER = 1 | |
| ROCK = 2 | |
| WIN = 3 | |
| LOSE = 4 | |
| DRAW = 5 | |
| def get_random_action(): | |
| return random.choice([SCISSORS, PAPER, ROCK]) | |
| def print_action(action): | |
| if action == SCISSORS: | |
| print_on_screen("I choose Scissors") | |
| elif action == PAPER: | |
| print_on_screen("I choose Paper") | |
| elif action == ROCK: | |
| print_on_screen("I choose Rock") | |
| def get_game_result(my_action, opponent_action): | |
| print(f"My Action: {my_action}, Opponent Action: {opponent_action}") | |
| if my_action == opponent_action: | |
| return DRAW | |
| if (my_action - opponent_action) % 3 == 2: | |
| return WIN | |
| else: | |
| return LOSE | |
| def print_on_screen(text): | |
| robot.screen.clear_screen() | |
| robot.screen.set_cursor(5, 2) | |
| robot.screen.print(text) | |
| def start_game(): | |
| if robot.link.is_connected(): | |
| robot.sound.play(CHIRP) | |
| print_on_screen("Scissors") | |
| robot.link.send_message("count", 1) | |
| wait(1000, MSEC) | |
| robot.sound.play(CHIRP) | |
| print_on_screen("Paper") | |
| robot.link.send_message("count", 2) | |
| wait(1000, MSEC) | |
| robot.sound.play(CHIRP) | |
| print_on_screen("Rock") | |
| robot.link.send_message("count", 3) | |
| wait(1000, MSEC) | |
| action = get_random_action() | |
| print_action(action) | |
| robot.link.send_message("shoot", action) | |
| def screen_pressed(): | |
| robot.led.on(ALL_LEDS, GREEN) | |
| print(f"Screen pressed") | |
| print(f"Link Status: {robot.link.is_connected()}") | |
| def screen_released(): | |
| robot.led.off(ALL_LEDS) | |
| print(f"Screen released") | |
| print(f"Link Status: {robot.link.is_connected()}") | |
| start_game() | |
| def handle_count(message, count): | |
| print(f"Message: {message}, Count: {count}") | |
| if count == 1: | |
| print_on_screen("Scissors") | |
| elif count == 2: | |
| print_on_screen("Paper") | |
| elif count == 3: | |
| print_on_screen("Rock") | |
| def handle_shoot(message, action_opponent): | |
| print(f"Message: {message}, Action Received: {action_opponent}") | |
| action_mine = get_random_action() | |
| print_action(action_mine) | |
| wait(1000, MSEC) | |
| robot.link.send_message("shoot_answer", action_opponent, action_mine) | |
| result = get_game_result(action_mine, action_opponent) | |
| handle_shoot_result(result) | |
| def handle_shoot_result(result): | |
| if result == WIN: | |
| print_on_screen("I win") | |
| elif result == LOSE: | |
| print_on_screen("I lost") | |
| elif result == DRAW: | |
| print_on_screen("We drew") | |
| def handle_shoot_answer(message, action_mine, action_opponent): | |
| print(f"Message: {message}, Action Received: {action_opponent}") | |
| result = get_game_result(action_mine, action_opponent) | |
| handle_shoot_result(result) | |
| robot.screen.pressed(screen_pressed) | |
| robot.screen.released(screen_released) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment