{"id":203719,"date":"2025-05-22T10:31:45","date_gmt":"2025-05-22T02:31:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203719\/"},"modified":"2025-05-22T10:31:45","modified_gmt":"2025-05-22T02:31:45","slug":"%e7%8a%b6%e6%80%81","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203719\/","title":{"rendered":"\u72b6\u6001"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u72b6\u6001<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u72b6\u6001\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241119\/1732011009673c64012a72a.jpg\" class=\"aligncenter\"><\/p>\n<p>\u72b6\u6001\u662f\u884c\u4e3a\u8bbe\u8ba1\u200b\u200b\u6a21\u5f0f\u4e4b\u4e00\uff0c\u5176\u4e2d\u7c7b\u7684\u884c\u4e3a\u6839\u636e\u5176\u72b6\u6001\u800c\u53d8\u5316\u3002<\/p>\n<p><strong>\u5173\u952e\u6982\u5ff5<\/strong>\uff1a<br \/><em>\u4e0a\u4e0b\u6587<\/em>\uff1a\u884c\u4e3a\u6839\u636e\u72b6\u6001\u53d8\u5316\u7684\u7c7b\/\u5bf9\u8c61<br \/><em>\u72b6\u6001<\/em>\uff1a\u62bd\u8c61\u72b6\u6001<br \/><em>\u5177\u4f53\u72b6\u6001<\/em>\uff1a\u4ee3\u8868\u5404\u79cd\u72b6\u6001\uff0c\u5b83\u6539\u53d8context\u7c7b\u7684\u884c\u4e3a\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u7406\u89e3\u8fd9\u4e00\u70b9\uff1a<\/p>\n<p>state.java<\/p>\n<pre>public interface state {\n    public void doaction(context context);\n}\n<\/pre>\n<p>\u56fd\u5bb6\u5177\u4f53\u5b9e\u65bd<\/p>\n<pre>public class startstate implements state {\n    private context context;\n    public startstate(){}\n    @override\n    public void doaction(context context){\n        this.context = context;\n        this.context.setstate(this);\n        system.out.println(\"player is in startstate\");\n    }\n\n    public string tostring(){\n        return \"start state\";\n    }\n}\n\npublic class endstate implements state {\n    private context context;\n    public endstate(){}\n    @override\n    public void doaction(context context){\n        this.context = context;\n        this.context.setstate(this);\n        system.out.println(\"player is in endstate\");\n    }\n\n    public string tostring(){\n        return \"end state\";\n    } \n}\n\n<\/pre>\n<p>\u4e3b\u8981<\/p>\n<pre>public class main {\n    public static void main(string args[]){\n        context context = new context();\n        state state = new startstate();\n        state.doaction(context);\n        \/\/current state\n        system.out.println(context.getstate().tostring());\n\n        state state2 = new endstate();\n        state2.doaction(context);\n        \/\/new state\n        system.out.println(context.getstate().tostring());\n    }\n}\n<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Player is in StartState\nStart State\nPlayer is in EndState\nEnd State\n<\/pre>\n<p>\u6ce8\u610f\uff1a\u4ee5\u4e0a\u4ee3\u7801\u9075\u5faaisp\u3001lsp\u3001srp\u3001ocp\u7684\u624e\u5b9e\u539f\u5219<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u72b6\u6001\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u72b6\u6001 \u6536\u85cf \u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u72b6&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203719","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203719"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203719\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}