data/full_repos/permissive/501710956/my_snake_single.srcs/sources_1/new/Game_ctrl.v
data/verilator_xmls/355c4647-f695-4d65-829b-bb95e2b48ec8.xml
module Game_ctrl(
    input clk,
    input rst_n,
    input [3:0] cmd_out,
    input hit,
    
    output reg [1:0]gamestate
    );
    
    localparam PRE = 2'b10;
    localparam START = 2'b01;

    localparam DIE = 2'b11;
    
    always@(posedge clk or negedge rst_n)
    begin
      if(!rst_n)
      begin
        gamestate <= PRE;
      end
      
      else
      begin
        case(gamestate)
        
          PRE:
          begin
            if(cmd_out <= 4'b1000 && cmd_out >= 4'b0001) gamestate <= START;

            else gamestate <= PRE;
          end
          
          START:
          begin
            if(hit) gamestate <= DIE;
            else gamestate <= START;
          end
          
          DIE:
          begin
            if(cmd_out <= 4'b1000 && cmd_out >= 4'b0001) gamestate <= PRE;

            else gamestate <= DIE;
          end
        
        endcase
      end
    end
    
endmodule
module Game_ctrl(
    input clk,
    input rst_n,
    input [3:0] cmd_out,
    input hit,
    
    output reg [1:0]gamestate
    );

    
    localparam PRE = 2'b10;
    localparam START = 2'b01;

    localparam DIE = 2'b11;
    
    always@(posedge clk or negedge rst_n)
    begin
      if(!rst_n)
      begin
        gamestate <= PRE;
      end
      
      else
      begin
        case(gamestate)
        
          PRE:
          begin
            if(cmd_out <= 4'b1000 && cmd_out >= 4'b0001) gamestate <= START;

            else gamestate <= PRE;
          end
          
          START:
          begin
            if(hit) gamestate <= DIE;
            else gamestate <= START;
          end
          
          DIE:
          begin
            if(cmd_out <= 4'b1000 && cmd_out >= 4'b0001) gamestate <= PRE;

            else gamestate <= DIE;
          end
        
        endcase
      end
    end
    
endmodule