data/full_repos/permissive/114380772/Snake/Game_ctrl_module.v
data/verilator_xmls/d40a2d17-57e4-40fe-9674-f540f24b8a93.xml
module Game_ctrl_module
(
	input Clk_24mhz,
	input Rst_n,
	input Key_left,
	input Key_right,
	input Key_up,
	input Key_down,
	output reg  [2:0] Game_status,
	input Hit_wall_sig,
	input Hit_body_sig,
	output reg Flash_sig
);

	parameter START = 3'b001;
	parameter  PLAY = 3'b010;
	parameter   END = 3'b100;

	always @ (posedge Clk_24mhz or negedge Rst_n)
	begin
		if(!Rst_n)
		begin
			Game_status <= START;;
			Flash_sig <= 1'd1;
		end
		else
		begin
			Game_status <= START;
			case(Game_status)
				START:
					begin	
						if(Key_left | Key_right | Key_up | Key_down)
						begin		
							Game_status <= PLAY;
						end
						else
							Game_status <= START;
					end 
				PLAY:
					begin
						if(Hit_wall_sig | Hit_body_sig)
						begin		
							Game_status <= END;
						end
						else
							Game_status <= PLAY;
					end
				END:
					begin
						if(Key_left | Key_right | Key_up | Key_down)
						begin
							Game_status <= START;
							Flash_sig <= 1'd1;
						end
						else
						begin
							Game_status <= END;
							Flash_sig <= 1'd1;
						end		
					end
			endcase
		end
	end
endmodule
module Game_ctrl_module
(
	input Clk_24mhz,
	input Rst_n,
	input Key_left,
	input Key_right,
	input Key_up,
	input Key_down,
	output reg  [2:0] Game_status,
	input Hit_wall_sig,
	input Hit_body_sig,
	output reg Flash_sig
);


	parameter START = 3'b001;
	parameter  PLAY = 3'b010;
	parameter   END = 3'b100;

	always @ (posedge Clk_24mhz or negedge Rst_n)
	begin
		if(!Rst_n)
		begin
			Game_status <= START;;
			Flash_sig <= 1'd1;
		end
		else
		begin
			Game_status <= START;
			case(Game_status)
				START:
					begin	
						if(Key_left | Key_right | Key_up | Key_down)
						begin		
							Game_status <= PLAY;
						end
						else
							Game_status <= START;
					end 
				PLAY:
					begin
						if(Hit_wall_sig | Hit_body_sig)
						begin		
							Game_status <= END;
						end
						else
							Game_status <= PLAY;
					end
				END:
					begin
						if(Key_left | Key_right | Key_up | Key_down)
						begin
							Game_status <= START;
							Flash_sig <= 1'd1;
						end
						else
						begin
							Game_status <= END;
							Flash_sig <= 1'd1;
						end		
					end
			endcase
		end
	end
endmodule