Advertisement
daringdan100

Untitled

Feb 22nd, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. // Define the player type
  2. type
  3. player
  4. var
  5. name as text
  6. health as num = 10
  7. turn_done as num = 0 // Flag indicating whether the player's turn is done (0 = no, 1 = yes)
  8. connection as /mob // The client connection associated with the player
  9. proc
  10. TakeTurn(target as mob)
  11. // Perform the player's turn on the specified target mob
  12. // For example, the player might attack the target and reduce its health
  13. target << "You were attacked by [self.name]!"
  14. target.health -= 1
  15. world << "[self.name] attacked [target.name]!"
  16. self.turn_done = 1
  17. return
  18.  
  19. // Define the mob type
  20. type
  21. mob
  22. var
  23. name as text
  24. health as num = 5
  25. proc
  26. IsAlive()
  27. // Check whether the mob is still alive
  28. return self.health > 0
  29.  
  30. // Define the game state
  31. global
  32. var
  33. player_list as list // The list of players in the game
  34. mob_list as list // The list of mobs in the game
  35. current_player as player // The player whose turn it is currently
  36. game_over as num = 0 // Flag indicating whether the game is over (0 = no, 1 = player victory, 2 = mob victory)
  37. turn_num as num = 0 // The current turn number
  38.  
  39. // Initialize the game state
  40. New()
  41. // Create the mobs
  42. for (var /i = 1 to 3)
  43. var /m = new mob
  44. m.name = "Mob " + i
  45. mob_list += m
  46.  
  47. // Define the client-side handler for when a player clicks on a mob
  48. client
  49. proc
  50. ClickMob(mob as /mob)
  51. // Check whether it is the player's turn and the mob is still alive
  52. if (current_player.connection == src && mob.IsAlive())
  53. // Perform the player's turn on the specified target mob
  54. current_player.TakeTurn(mob)
  55. // Set the turn done flag for the player
  56. current_player.turn_done = 1
  57.  
  58. // Define the server-side handler for processing a player's turn
  59. proc
  60. ProcessTurn(player as player, mob as mob)
  61. // Allow the player to take their turn
  62. player.connection << "It's your turn! Click on a mob to attack it."
  63. player.turn_done = 0
  64. current_player = player
  65. while (!player.turn_done)
  66. // Wait for the player to take their turn
  67. sleep(1)
  68.  
  69. // Check whether the game is over
  70. var /mobs_alive = 0
  71. for (var /mob in mob_list)
  72. if (mob.IsAlive())
  73. mobs_alive += 1
  74. if (mobs_alive == 0)
  75. game_over = 1 // Player victory
  76. return
  77. if (!current_player.turn_done)
  78. game_over = 2 // Mob victory
  79. return
  80.  
  81. // Move to the next turn
  82. turn_num += 1
  83.  
  84. // Define the game loop
  85. proc
  86. GameLoop()
  87. // Create the players
  88. for (var /i = 1 to 2)
  89. var /p = new player
  90. p.name = "Player " + i
  91. p.connection = connect()
  92. player_list += p
  93.  
  94. // Wait for all players to connect
  95. while (len(player_list) < 2)
  96. sleep(1)
  97.  
  98. // Main game loop
  99. while (!game_over)
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement