微信登录

Controller - GameController.cs - 游戏操作

  1. class GameController:BaseController
  2. {
  3. public GameController(){}
  4. //开始比赛
  5. public string StartGame(数据, 客户端, 系统){}
  6. //移动
  7. public string Move(数据, 客户端, 系统) {}
  8. //攻击
  9. public string Shoot(数据, 客户端, 系统) {}
  10. //受到伤害
  11. public string Attack(数据, 客户端, 系统){}
  12. //离开比赛
  13. public string QuitBattle(数据, 客户端, 系统){}
  14. }
  1. class GameController:BaseController
  2. {
  3. public GameController(){}
  4. //开始比赛
  5. public string StartGame(string data, Client client, Server server){}
  6. //移动
  7. public string Move(string data, Client client, Server server) {}
  8. //攻击
  9. public string Shoot(string data, Client client, Server server) {}
  10. //受到伤害
  11. public string Attack(string data, Client client, Server server){}
  12. //离开比赛
  13. public string QuitBattle(string data, Client client, Server server){}
  14. }
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Common;
  7. using GameServer.Servers;
  8. namespace GameServer.Controller
  9. {
  10. class GameController:BaseController
  11. {
  12. public GameController()
  13. {
  14. requestCode = RequestCode.Game;
  15. }
  16. //开始比赛
  17. public string StartGame(string data, Client client, Server server)
  18. {
  19. if (client.IsHouseOwner())
  20. {
  21. Room room = client.Room;
  22. room.BroadcastMessage(client, ActionCode.StartGame, ((int)ReturnCode.Success).ToString());
  23. room.StartTimer();
  24. return ((int)ReturnCode.Success).ToString();
  25. }
  26. else
  27. {
  28. return ((int)ReturnCode.Fail).ToString();
  29. }
  30. }
  31. //移动
  32. public string Move(string data, Client client, Server server)
  33. {
  34. Room room = client.Room;
  35. if (room != null)
  36. room.BroadcastMessage(client, ActionCode.Move, data);
  37. return null;
  38. }
  39. //攻击
  40. public string Shoot(string data, Client client, Server server)
  41. {
  42. Room room = client.Room;
  43. if (room != null)
  44. room.BroadcastMessage(client, ActionCode.Shoot, data);
  45. return null;
  46. }
  47. //受到伤害
  48. public string Attack(string data, Client client, Server server)
  49. {
  50. int damage = int.Parse(data);
  51. Room room = client.Room;
  52. if (room == null) return null;
  53. room.TakeDamage(damage, client);
  54. return null;
  55. }
  56. //离开比赛
  57. public string QuitBattle(string data, Client client, Server server)
  58. {
  59. Room room = client.Room;
  60. if (room != null)
  61. {
  62. room.BroadcastMessage(null, ActionCode.QuitBattle, "r");
  63. room.Close();
  64. }
  65. return null;
  66. }
  67. }
  68. }