一、运行流程

  开始界面

斗地主项目总结

  1. 点击开始游戏按钮,执行 PlayPanel 类 startClick 函数,

1 /// <summary>
2 /// 开始游戏按钮响应函数
3 /// </summary>
4 private void startClick()
5 {
6     Dispatch(AreaCode.UI, UIEvent.START_PANEL_ACTIVE, true);      
7 }

 

  该函数向 UI 层发送 START_PANEL_ACTIVE 事件,传输消息 true。

  然后是 StartPanel 类 Execute 函数,

 1 public override void Execute(int eventCode, object message)
 2 {
 3     switch (eventCode)
 4     {
 5         case UIEvent.START_PANEL_ACTIVE:
 6             setPanelActive((bool)message);
 7             break;
 8         default:
 9             break;
10     }
11 }

  该函数接收消息,调用 setPanelActive 函数显示开始游戏面板。

  点击注册账号按钮流程类似。

 

  登录界面:

斗地主项目总结

 

  2. 点击登录按钮,执行 StartPanel 类 loginClick 函数,

 1 /// <summary>
 2 /// 登录按钮的点击事件处理
 3 /// </summary>
 4 private void loginClick()
 5 {
 6     // 若用户名输入为空
 7     if (string.IsNullOrEmpty(inputAccount.text))
 8     {
 9         promptMsg.Change("用户名输入为空", Color.red);
10         Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg);
11         return;
12     }  
13     // 若密码输入为空
14     if (string.IsNullOrEmpty(inputPassword.text))      
15     {
16         promptMsg.Change("密码输入为空", Color.red);
17         Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg);
18         return;
19     }
20     // 若密码输入不是4到16位
21     if(inputPassword.text.Length < 4
22         || inputPassword.text.Length > 16)
23     {
24         promptMsg.Change("密码输入不是4到16位", Color.red);
25         Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg);
26         return;
27     }
28 
29     //需要和服务器交互了
30     AccountDto dto = new AccountDto(inputAccount.text, inputPassword.text);
31     socketMsg.Change(OpCode.ACCOUNT, AccountCode.LOGIN, dto);
32     Dispatch(AreaCode.NET, 0, socketMsg);
33 }
loginClick

相关文章:

  • 2021-12-25
  • 2021-12-10
  • 2021-11-30
  • 2021-05-10
  • 2021-08-18
  • 2021-09-02
  • 2021-12-12
猜你喜欢
  • 2021-12-27
  • 2021-07-25
  • 2022-12-23
  • 2021-12-25
  • 2021-08-04
  • 2022-12-23
相关资源
相似解决方案