Add game 2048
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
use core::{
|
||||
iter::Cloned,
|
||||
mem::MaybeUninit,
|
||||
ops::{Index, IndexMut},
|
||||
};
|
||||
@@ -100,7 +99,7 @@ where
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
grid: [0; SIZE * SIZE],
|
||||
rng: rand::rngs::SmallRng::seed_from_u64(9543223934),
|
||||
rng: rand::rngs::SmallRng::seed_from_u64(compile_rand::compile_rand!(u64)),
|
||||
score: 0,
|
||||
}
|
||||
}
|
||||
@@ -208,43 +207,36 @@ where
|
||||
pub fn run(&mut self) -> ! {
|
||||
let mut buttons = [false; 4];
|
||||
let funcs = [Self::left, Self::right, Self::up, Self::down];
|
||||
let mut lost = false;
|
||||
self.draw();
|
||||
loop {
|
||||
let mut lost = false;
|
||||
self.draw();
|
||||
loop {
|
||||
for direction in 0..4 {
|
||||
let button =
|
||||
unsafe { fpga_lib::interface::Buttons::get_button(direction as u8) };
|
||||
if button && !buttons[direction] {
|
||||
buttons[direction] = true;
|
||||
for direction in 0..4 {
|
||||
let button = unsafe { fpga_lib::interface::Buttons::get_button(direction as u8) };
|
||||
if button && !buttons[direction] {
|
||||
buttons[direction] = true;
|
||||
|
||||
if funcs[direction](self) {
|
||||
self.add();
|
||||
self.draw();
|
||||
if self.lost() {
|
||||
lost = true;
|
||||
break;
|
||||
}
|
||||
if funcs[direction](self) {
|
||||
self.add();
|
||||
self.draw();
|
||||
if self.lost() {
|
||||
lost = true;
|
||||
break;
|
||||
}
|
||||
} else if !button && buttons[direction] {
|
||||
buttons[direction] = false
|
||||
}
|
||||
} else if !button && buttons[direction] {
|
||||
buttons[direction] = false
|
||||
}
|
||||
if lost {
|
||||
unsafe {
|
||||
fpga_lib::vga::VGA::draw_string(
|
||||
OFFSET,
|
||||
OFFSET + (SIZE as u16) * BLOCK_SIZE + FONT_HEIGHT as u16 + 10,
|
||||
"Game Over !",
|
||||
RED,
|
||||
)
|
||||
};
|
||||
self.reset();
|
||||
while !(0..4).any(|direction| unsafe {
|
||||
fpga_lib::interface::Buttons::get_button(direction as u8)
|
||||
}) {}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if lost {
|
||||
unsafe {
|
||||
fpga_lib::vga::VGA::draw_string(
|
||||
OFFSET,
|
||||
OFFSET + (SIZE as u16) * BLOCK_SIZE + FONT_HEIGHT as u16 + 10,
|
||||
"Game Over !",
|
||||
RED,
|
||||
)
|
||||
};
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user