`timescale 1ns/1ns

module game_count
    (
        input rst_n, //异位复位信号,低电平有效
        input clk, 	//时钟信号
        input [9:0]money,
        input set,
        input boost,

        output reg[9:0]remain,
        output reg yellow,
        output reg red
    );

always@(posedge clk or negedge rst_n)
    if(!rst_n)
        remain  <=  10'd0;
    else    if(set)
        remain  <=  remain  + money;
    else    if(boost && remain == 10'd1)
       remain  <=  remain - 1;
    else    if(boost)
        remain  <=  remain - 2;
    else    if(!boost)
        remain  <=  remain - 1;
    else    if(remain == 10'd0 && !set)
        remain  <=  remain;


always@(posedge clk or negedge rst_n)
    if(!rst_n)
        yellow  <=  1'b0;
    else    if(remain!=10'd0 && remain < 10'd10)
        yellow  <=  1'b1;
    else
        yellow  <=  1'b0;

always@(posedge clk or negedge rst_n)
    if(!rst_n)
        red <=  1'b0;
    else    if(boost && remain  < 10'd2)
        red <=  1'b1;
    else    if(!boost && remain < 10'd1)
        red <=  1'b1;
    else    
        red <=  1'b0;
endmodule