บทความ

กำลังแสดงโพสต์จาก มกราคม, 2025
ตัวอย่างสร้างเกมส์แนวเนื้อเรื่องด้วย wayOS You wake up in an abandoned house.   The floor creaks under your weight, and the air smells of dust and decay.   A faint light flickers from the hallway.      What happened here?   , menu1      menu1,   You hear a strange noise coming from upstairs.   - Investigate the noise #courage+, upstairs #courage   - Look for an exit, search   - Stay put and observe, wait      upstairs gt0,   You cautiously step upstairs. A shadow moves at the end of the hallway.   - Call out, callout   - Approach quietly #stealth+, sneak      search,   You find the front door locked tight. A window is slightly open.   - Try to squeeze through #agility+, escape #agility   - Look for another way out, investigate      wait,   You wait in silence. Footsteps approach from the hallway.   - Hide under the table #stealth+, hide #s...
การใช้งาน RPC (Remote Procedure Call) ด้วย Java พร้อมตัวอย่างเกมออนไลน์ (ต่อ) เพื่อให้สามารถอัปเดตสถานะของผู้เล่นคนอื่นในเกมออนไลน์ผ่าน RPC ได้ คุณสามารถใช้ฟีเจอร์  Server Streaming RPC  ของ gRPC เพื่อให้เซิร์ฟเวอร์ส่งข้อมูลสถานะของผู้เล่นแบบเรียลไทม์ไปยังไคลเอนต์ที่กำลังเชื่อมต่ออยู่ ตัวอย่างด้านล่างแสดงวิธีการเพิ่มฟีเจอร์นี้ในเกม: อัปเดตไฟล์  game.proto เพิ่มเมธอดสำหรับการสตรีมสถานะของผู้เล่น: syntax = "proto3" ; service GameService { rpc JoinGame (JoinRequest) returns (JoinResponse) ; rpc SendMove (MoveRequest) returns (MoveResponse) ; rpc StreamPlayerUpdates (PlayerUpdateRequest) returns (stream PlayerUpdateResponse) ; } message JoinRequest { string playerName = 1 ; } message JoinResponse { string welcomeMessage = 1 ; } message MoveRequest { string playerName = 1 ; string move = 2 ; } message MoveResponse { string result = 1 ; } message PlayerUpdateRequest { string playerName = 1 ; // ชื่อผู้เล่นที่ต้อง...
การใช้งาน RPC (Remote Procedure Call) ด้วย Java พร้อมตัวอย่างเกมออนไลน์อย่างง่าย RPC (Remote Procedure Call) เป็นเทคนิคในการเรียกใช้ฟังก์ชันหรือเมธอดที่อยู่ในระบบอื่น (เช่นเซิร์ฟเวอร์) เสมือนเป็นการเรียกฟังก์ชันในเครื่องของเราเอง เหมาะสำหรับการพัฒนาแอปพลิเคชันแบบกระจาย (Distributed Applications) เช่น เกมออนไลน์ที่ต้องสื่อสารระหว่างผู้เล่นกับเซิร์ฟเวอร์ ด้านล่างนี้เป็นการอธิบายวิธีการใช้งาน RPC ด้วย Java โดยใช้  gRPC  ซึ่งเป็นหนึ่งในไลบรารีที่ได้รับความนิยม การตั้งค่าพื้นฐาน เพิ่ม Dependency ใน  build.gradle  หรือ  pom.xml สำหรับ Gradle: implementation 'io.grpc:grpc-netty:1.57.2' implementation 'io.grpc:grpc-protobuf:1.57.2' implementation 'io.grpc:grpc-stub:1.57.2' implementation 'com.google.protobuf:protobuf-java:3.23.0' สำหรับ Maven: < dependencies > < dependency > < groupId > io.grpc </ groupId > < artifactId > grpc-netty </ artifactId > < version > 1.57.2 </ version ...