#![no_std]
#![allow(non_upper_case_globals)]
use arduboy_rust::prelude::*;
const arduboy: Arduboy2 = Arduboy2::new();
static mut playerwin: c_int = 0;
static mut attempts: c_int = 0;
static mut guessednumber: c_int = 0;
static mut randomnumber: c_int = 0;
static mut lastguess: c_int = 0;
#[no_mangle]
pub unsafe extern "C" fn setup() {
arduboy.begin();
arduboy.clear();
arduboy.init_random_seed();
randomnumber = random_between(1, 101) as i16;
}
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
arduboy.clear();
arduboy.poll_buttons();
if playerwin == 0 {
if attempts == 7 {
arduboy.set_cursor(0, 0);
arduboy.print(f!(b"You lost!\0"));
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Correct Number: \0"));
arduboy.print(randomnumber);
if A.just_pressed() {
randomnumber = random_between(1, 101) as i16;
attempts = 0;
playerwin = 0;
}
} else {
if UP.just_pressed() {
guessednumber += 1;
}
if DOWN.just_pressed() {
guessednumber -= 1;
}
if A.just_pressed() {
if guessednumber == randomnumber {
playerwin += 1;
} else {
attempts += 1;
lastguess = guessednumber
}
}
arduboy.set_cursor(0, 0);
arduboy.print(f!(b"Attempt: \0"));
arduboy.print(attempts);
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Number to guess: \0"));
arduboy.print(guessednumber);
arduboy.print(f!(b"\n\0"));
if attempts == 0 {
arduboy.print(f!(b"Good luck!\0"));
} else {
arduboy.print(lastguess);
if lastguess > randomnumber {
arduboy.print(f!(b" is too high!\0"));
}
if lastguess < randomnumber {
arduboy.print(f!(b" is too low!\0"));
}
}
}
} else {
arduboy.set_cursor(0, 0);
arduboy.print(f!(b"You won!\0"));
arduboy.print(f!(b"\n\0"));
arduboy.print(f!(b"Correct Number: \0"));
arduboy.print(randomnumber);
if A.just_pressed() {
randomnumber = random_between(1, 101) as c_int;
attempts = 0;
playerwin = 0;
}
}
arduboy.display();
}