fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Block {
  5. private:
  6. int x, y; // ตำแหน่งของบล็อกบนกริด
  7.  
  8. public:
  9. Block() {
  10. x = 0;
  11. y = 0;
  12. }
  13.  
  14. void moveForward() {
  15. y += 1;
  16. }
  17.  
  18. void moveBackward() {
  19. y -= 1;
  20. }
  21.  
  22. void moveLeft() {
  23. x -= 1;
  24. }
  25.  
  26. void moveRight() {
  27. x += 1;
  28. }
  29.  
  30. void showPosition() {
  31. cout << "ตำแหน่งปัจจุบันของบล็อก: (" << x << ", " << y << ")" << endl;
  32. }
  33. };
  34.  
  35. int main() {
  36. Block block;
  37. char command;
  38.  
  39. cout << "ควบคุมการเคลื่อนที่ของบล็อกสี่เหลี่ยม" << endl;
  40. cout << "กด w = เด
  41.  
Success #stdin #stdout 0.02s 25632KB
stdin
Standard input is empty
stdout
#include <iostream>
using namespace std;

class Block {
private:
    int x, y; // ตำแหน่งของบล็อกบนกริด

public:
    Block() {
        x = 0;
        y = 0;
    }

    void moveForward() {
        y += 1;
    }

    void moveBackward() {
        y -= 1;
    }

    void moveLeft() {
        x -= 1;
    }

    void moveRight() {
        x += 1;
    }

    void showPosition() {
        cout << "ตำแหน่งปัจจุบันของบล็อก: (" << x << ", " << y << ")" << endl;
    }
};

int main() {
    Block block;
    char command;

    cout << "ควบคุมการเคลื่อนที่ของบล็อกสี่เหลี่ยม" << endl;
    cout << "กด w = เด