-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_state.v
40 lines (35 loc) · 979 Bytes
/
game_state.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module game_state(
input wire clk,
input wire start_game,
input wire game_over,
input wire restart,
output reg [1:0] state = 0
);
localparam
GAME_INITIAL = 2'd0,
GAME_PLAYING = 2'd1,
GAME_OVER = 2'd2;
reg [1:0] next_state = GAME_INITIAL;
always @ (posedge clk) begin
state <= next_state;
end
always @ (*) begin
next_state = state;
case (state)
GAME_INITIAL: begin
if (start_game & ~restart)
next_state = GAME_PLAYING;
end
GAME_PLAYING: begin
if (game_over)
next_state = GAME_OVER;
else if (restart)
next_state = GAME_PLAYING;
end
GAME_OVER: begin
if (restart)
next_state = GAME_PLAYING;
end
endcase
end
endmodule