简单Elixir游戏服设计-使table测试通过

(可是现在不指出了,该方案看重的excel处理库不够好, 提出转成csv,再从csv生成更好)

留神:输入框两侧的内容为系统自动生成,不用理会,同时上述值没法通过Ctrl+C,Ctrl+V输入(小编是一贯不搞定)需要手动一个个输入,总括了一下,前边8个“00”,03,5个“00”,5b,e0,2个“00”,5c,e0,4个“00”,在输入时只顾比较一下,制止失误。

图片 1图片 2

不过,由于win键在键盘中特其它岗位,在给大家带来便利的还要也给大家带来诸多的劳苦,尤其对于这一个没有通过“键盘指法”训练的爱侣。相信您也有过如此的抑郁,玩游戏的时候在动用快速键操作的进程中一不小心按到的win键,刹那间操作失去了问题,假诺在像吃鸡游戏关键的时候误触到win键这是真得令人抓狂。那么我们好还是不好在玩游戏前把win键屏蔽掉吧?当然可以,上边IT技术资料分享网小编就为我们享用一个解决办法。

除此以外,看代码 join 和 quit 的cond 语句少了true, 显著表明我们的测试还没覆盖到!!!!

以下形式是通过修改注册表实现,假设对注册表不是太熟识指出修改前对注册表举行备份,制止出现未知错误。

还有任何的小改变, seat.ex  simple_poker.ex

http://www.lmdouble.com/1639131504.html

好在for的代码也很简短,而实质上从csv生成的话,也是要做巡回工作,算是安慰)

win键?,位于Ctrl与Alt键之间的可怜四方块键,对于时常应用飞快键的心上人相信不会陌生,许多实用的急忙键操作都离不开它,比如win+E打开资源管理器,win+R打开运行对话框,win+L锁定屏幕等,算是一个使用率相比较高的按键了。假诺单按win键则是一向打开“先河”菜单。

果然,写代码比写测试快得多, 看着测试一个一个经过,仍旧挺享受的。

不过这一形式也有局限性,就是需要重启电脑使其收效,这在这些具有还原卡的公共场地中(比如说网咖)就特别了,那时候假使真得是平日按错win键的话能够在网上查找相关的软件来促成这样的功效,像win键屏蔽器。

(废了点时间,一致在品味抹初这段for,想直接定义个工具宏, 由于生疏了没能很快成功,

首先通过win+R打开运行对话框,输入regedit 回车,打开注册表编辑器

自我早就在博客里有写过方案从excel直接扭转

玩游戏关键时刻怎能按错键?一招帮你屏蔽win键

错误信息也可以从外表文件生成,只是体系本身重要演示基础服务器开发,由此就不更为了。

接下去依次定位到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard
Layout,在左侧空白处单击右键-新建-二进制值,将其重命名为“Scancode
Map”,接着双击该项,在里面输入“00 00 00 00 00 00 00 00 03 00 00 00 00 00
5b e0 00 00 5c e0 00 00 00 00”,最后如下图所示:

defmodule SimpleTable do
    @state_ready  :ready
    @state_playing :playing
    @state_dismiss :dismiss
    def init() do
        %{
            id: 0,
            cards: nil,
            creator: nil,
            seat_map: %{},
            seat_order: [],
            state: @state_ready
        }
    end

    def is_playing?(table), do: table.state == @state_playing
    def is_dismiss?(table), do: table.state == @state_dismiss
    def is_ready?(table), do: table.state == @state_ready

    def set_playing(table), do: put_in(table.state, @state_playing)
    def set_ready(table), do: put_in(table.state, @state_ready)
    def set_dismiss(table), do: put_in(table.state, @state_dismiss)


    def set_cards(table, cards), do: put_in(table.cards, cards)
    def get_cards(table), do: table.cards

    def init_deal(table) do
        table.seat_order
        |> Enum.map(&(find_seat(table, &1)))
        |> Enum.reduce(table, 
            fn seat, new_table ->
                new_table |> init_deal_one(seat)
            end)
    end

    def init_deal_one(table, seat) do
        {:ok, cards, left} = SimplePoker.init_deal(table.cards)
        seat = seat |> Seat.add_cards(cards)
        table |> update_seat(seat)
              |> set_cards(left)
    end

    def set_id(table, id), do: put_in(table.id, id)
    def get_id(table), do: table.id

    def set_creator(table, player), do: put_in(table.creator, player)
    def get_creator(table), do: table.creator

    def seat_count(table), do: table.seat_order |> Enum.count
    def seat_order(table), do: table.seat_order

    def find_seat(table, %{} = player), do: find_seat(table, player |> Player.get_id)
    def find_seat(table, player_id), do: table.seat_map[player_id]


    def add_seat(table, player) do
        seat = Seat.init(player)
        seat_id = seat |> Seat.get_id
        table = table |> update_seat(seat)
        add_to_order(table, seat_id)
    end

    def update_seat(table, seat), do: put_in(table.seat_map[seat |> Seat.get_id], seat)

    def add_to_order(table, seat_id), do: update_in(table.seat_order, &(&1 ++ [seat_id]))

    def remove_seat(table, %{} = player), do: remove_seat(table, player |> Player.get_id)
    def remove_seat(table, player_id) do
        table = update_in(table.seat_map, fn m -> Map.delete(m, player_id) end)
        update_in(table.seat_order, fn o -> List.delete(o, player_id) end)
    end

    def start(table, player) do
        cond do
            is_playing?(table) -> {:error, ErrorMsg.can_not_start_when_playing}
            seat_count(table) < 2 -> {:error, ErrorMsg.player_not_enough}
            not is_creator?(table, player) -> {:error, ErrorMsg.just_creator_can_start}
            true ->
                table = table |> set_playing
                {:ok, table}
        end
    end

    def quit(table, player) do
        cond do
            is_playing?(table) -> {:error, ErrorMsg.can_not_quit_when_playing}
            is_creator?(table, player) -> {:error, ErrorMsg.can_not_quit_when_creator}
        end
    end

    def dismiss(table, player) do
        cond do
            is_playing?(table) -> {:error, ErrorMsg.can_not_dismiss_when_playing}
            not is_creator?(table, player) -> {:error, ErrorMsg.just_creator_can_dismiss}
            true ->
                table = table |> set_dismiss
                {:ok, table}
        end
    end

    def make_up(table, player) do
        cond do
            is_ready?(table) -> {:error, ErrorMsg.can_not_make_up_when_not_playing}
            find_seat(table, player) |> Seat.is_open? -> {:error, ErrorMsg.can_not_make_up_when_open}
            find_seat(table, player) |> Seat.is_full? -> {:error, ErrorMsg.can_not_make_up_when_full}
        end
    end

    def join(table, player) do
        cond do
            is_playing?(table) -> {:error, ErrorMsg.can_not_join_when_playing}
            find_seat(table, player) -> {:error, ErrorMsg.repeated_join}
            true -> 
                table = table |> add_seat(player)
                {:ok, table}
        end
    end

    def open(table, player) do
        cond do
            find_seat(table, player) |> Seat.is_open? -> {:error, ErrorMsg.repeated_open}
            not (find_seat(table, player) |> Seat.get_cards |> SimplePoker.can_be_tian_gong?) -> {:error, ErrorMsg.just_tian_gong_can_open}
        end
    end


    def is_creator?(table, player), do: table.creator |> Player.get_id == player |> Player.get_id

end

说到底,假若重复再次来到win键使用的话,只需将下面建立的登记表项删除重启电脑就足以了,不过这里要打开运行对话框要通过此外的路线了,初阶-所有程序-附件-运行,或者开始菜单左侧栏下方已经存在了运行对话框点击进入也足以。

测试使代码更易于编写,代码又扶助发现测试不足。相辅相成。

最终关闭注册表,重启电脑看一下效率。

测试果然发现需要调整,分解测试如故需要小心。

IT技术资料分享-个人整理自互联网

defmodule ErrorMsg do
    @msgs %{
        player_not_enough: "player_not_enough",
        can_not_start_when_playing: "can_not_start_when_playing",
        can_not_dismiss_when_playing: "can_not_dismiss_when_playing",
        just_creator_can_start: "just_creator_can_start",
        just_creator_can_dismiss: "just_creator_can_dismiss",
        can_not_join_when_playing: "can_not_join_when_playing",
        repeated_join: "repeated_join",
        can_not_quit_when_playing: "can_not_quit_when_playing",
        can_not_quit_when_creator: "can_not_quit_when_creator",
        can_not_make_up_when_not_playing: "can_not_makeup_when_not_playing",
        can_not_make_up_when_open: "can_not_make_up_when_open",
        can_not_make_up_when_full: "can_not_make_up_when_full",
        just_tian_gong_can_open: "just_tian_gong_can_open",
        repeated_open: "repeated_open"
    }

    for {tag, text} <- @msgs do
        def unquote(tag)() do
            unquote text
        end
    end


end

error_msg.ex  使用了点宏

simple_table.ex 新增的使测试通过的代码

具体看git吧

好在有测试的话,很容易就意识问题。那大概是测试的益处了吗。

error_msg.ex

simple_table.ex

图片 3图片 4