diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/DaFuWeng.iml b/.idea/DaFuWeng.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/DaFuWeng.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2a2c1b9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a31e05c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/__pycache__/draw.cpython-312.pyc b/__pycache__/draw.cpython-312.pyc new file mode 100644 index 0000000..f317f4a Binary files /dev/null and b/__pycache__/draw.cpython-312.pyc differ diff --git a/__pycache__/game.cpython-312.pyc b/__pycache__/game.cpython-312.pyc new file mode 100644 index 0000000..d6d1f27 Binary files /dev/null and b/__pycache__/game.cpython-312.pyc differ diff --git a/__pycache__/player.cpython-312.pyc b/__pycache__/player.cpython-312.pyc new file mode 100644 index 0000000..8509f18 Binary files /dev/null and b/__pycache__/player.cpython-312.pyc differ diff --git a/dafuweng-backend/pom.xml b/dafuweng-backend/pom.xml new file mode 100644 index 0000000..a762dc9 --- /dev/null +++ b/dafuweng-backend/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + com.dafuweng + dafuweng-backend + 1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 3.2.0 + + + + + 17 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.h2database + h2 + runtime + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/Application.java b/dafuweng-backend/src/main/java/com/dafuweng/Application.java new file mode 100644 index 0000000..8020f89 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/Application.java @@ -0,0 +1,11 @@ +package com.dafuweng; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/DataInitializer.java b/dafuweng-backend/src/main/java/com/dafuweng/DataInitializer.java new file mode 100644 index 0000000..3199fd5 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/DataInitializer.java @@ -0,0 +1,191 @@ +package com.dafuweng; + +import com.dafuweng.model.*; +import com.dafuweng.repository.RoleRepository; +import com.dafuweng.repository.ItemRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class DataInitializer implements CommandLineRunner { + @Autowired + private RoleRepository roleRepository; + + @Autowired + private ItemRepository itemRepository; + + @Override + public void run(String... args) throws Exception { + // 创建初始角色 + createInitialRoles(); + + // 创建初始道具 + createInitialItems(); + } + + private void createInitialRoles() { + // 检查是否已存在角色数据 + if (roleRepository.count() == 0) { + // 创建小E角色 + Role xiaoE = new Role(); + xiaoE.setName("xiao_e"); + xiaoE.setDisplayName("小E"); + xiaoE.setAvatarUrl("/images/role/小e.jpg"); + xiaoE.setDescription("聪明机智的小E,擅长策略和谈判。"); + + RoleAttribute xiaoEAttribute = new RoleAttribute(); + xiaoEAttribute.setStrength(5); + xiaoEAttribute.setIntelligence(9); + xiaoEAttribute.setAgility(7); + xiaoEAttribute.setLuck(6); + xiaoEAttribute.setCharm(8); + xiaoEAttribute.setMaxHealth(100); + xiaoEAttribute.setCurrentHealth(100); + xiaoEAttribute.setBaseMoney(3000); + + xiaoE.setAttribute(xiaoEAttribute); + + // 创建皮卡丘角色 + Role pikachu = new Role(); + pikachu.setName("pikachu"); + pikachu.setDisplayName("皮卡丘"); + pikachu.setAvatarUrl("/images/role/皮卡丘.jpg"); + pikachu.setDescription("可爱的皮卡丘,拥有强大的电力和速度。"); + + RoleAttribute pikachuAttribute = new RoleAttribute(); + pikachuAttribute.setStrength(7); + pikachuAttribute.setIntelligence(6); + pikachuAttribute.setAgility(9); + pikachuAttribute.setLuck(8); + pikachuAttribute.setCharm(7); + pikachuAttribute.setMaxHealth(120); + pikachuAttribute.setCurrentHealth(120); + pikachuAttribute.setBaseMoney(2800); + + pikachu.setAttribute(pikachuAttribute); + + // 创建可达鸭角色 + Role可达鸭 = new Role(); + 可达鸭.setName("ke_da_ya"); + 可达鸭.setDisplayName("可达鸭"); + 可达鸭.setAvatarUrl("/images/role/可达鸭.jpg"); + 可达鸭.setDescription("有点迟钝的可达鸭,但是运气非常好。"); + + RoleAttribute 可达鸭Attribute = new RoleAttribute(); + 可达鸭Attribute.setStrength(8); + 可达鸭Attribute.setIntelligence(5); + 可达鸭Attribute.setAgility(6); + 可达鸭Attribute.setLuck(10); + 可达鸭Attribute.setCharm(6); + 可达鸭Attribute.setMaxHealth(130); + 可达鸭Attribute.setCurrentHealth(130); + 可达鸭Attribute.setBaseMoney(2500); + + 可达鸭.setAttribute(可达鸭Attribute); + + // 创建小黄鸡角色 + Role xiaoHuangJi = new Role(); + xiaoHuangJi.setName("xiao_huang_ji"); + xiaoHuangJi.setDisplayName("小黄鸡"); + xiaoHuangJi.setAvatarUrl("/images/role/小黄鸡.jpg"); + xiaoHuangJi.setDescription("活泼可爱的小黄鸡,拥有出色的社交能力。"); + + RoleAttribute xiaoHuangJiAttribute = new RoleAttribute(); + xiaoHuangJiAttribute.setStrength(6); + xiaoHuangJiAttribute.setIntelligence(7); + xiaoHuangJiAttribute.setAgility(8); + xiaoHuangJiAttribute.setLuck(7); + xiaoHuangJiAttribute.setCharm(9); + xiaoHuangJiAttribute.setMaxHealth(110); + xiaoHuangJiAttribute.setCurrentHealth(110); + xiaoHuangJiAttribute.setBaseMoney(2700); + + xiaoHuangJi.setAttribute(xiaoHuangJiAttribute); + + // 保存角色 + roleRepository.save(xiaoE); + roleRepository.save(pikachu); + roleRepository.save(可达鸭); + roleRepository.save(xiaoHuangJi); + + System.out.println("初始角色数据已加载完成。"); + } else { + System.out.println("角色数据已存在,无需重复加载。"); + } + } + + private void createInitialItems() { + // 检查是否已存在道具数据 + if (itemRepository.count() == 0) { + // 创建各种道具 + List items = new ArrayList<>(); + + // 恢复药水 + Item healthPotion = new Item(); + healthPotion.setName("health_potion"); + healthPotion.setDisplayName("恢复药水"); + healthPotion.setIconUrl("/images/items/health_potion.png"); + healthPotion.setDescription("恢复50点生命值。"); + healthPotion.setType("consumable"); + healthPotion.setEffectValue(50); + healthPotion.setEffectTarget("self"); + healthPotion.setEffectDuration("instant"); + healthPotion.setPrice(50); + healthPotion.setMaxStackSize(10); + items.add(healthPotion); + + // 幸运符 + Item luckCharm = new Item(); + luckCharm.setName("luck_charm"); + luckCharm.setDisplayName("幸运符"); + luckCharm.setIconUrl("/images/items/luck_charm.png"); + luckCharm.setDescription("增加10点运气,持续3回合。"); + luckCharm.setType("consumable"); + luckCharm.setEffectValue(10); + luckCharm.setEffectTarget("self"); + luckCharm.setEffectDuration("3_turns"); + luckCharm.setPrice(100); + luckCharm.setMaxStackSize(5); + items.add(luckCharm); + + // 地产升级卡 + Item propertyUpgradeCard = new Item(); + propertyUpgradeCard.setName("property_upgrade_card"); + propertyUpgradeCard.setDisplayName("地产升级卡"); + propertyUpgradeCard.setIconUrl("/images/items/property_upgrade_card.png"); + propertyUpgradeCard.setDescription("立即升级一块地产,无需支付费用。"); + propertyUpgradeCard.setType("consumable"); + propertyUpgradeCard.setEffectValue(1); + propertyUpgradeCard.setEffectTarget("property"); + propertyUpgradeCard.setEffectDuration("instant"); + propertyUpgradeCard.setPrice(200); + propertyUpgradeCard.setMaxStackSize(3); + items.add(propertyUpgradeCard); + + // 通行卡 + Item passCard = new Item(); + passCard.setName("pass_card"); + passCard.setDisplayName("通行卡"); + passCard.setIconUrl("/images/items/pass_card.png"); + passCard.setDescription("可以免费通过任何收费区域。"); + passCard.setType("consumable"); + passCard.setEffectValue(1); + passCard.setEffectTarget("self"); + passCard.setEffectDuration("1_turn"); + passCard.setPrice(150); + passCard.setMaxStackSize(5); + items.add(passCard); + + // 保存道具 + itemRepository.saveAll(items); + + System.out.println("初始道具数据已加载完成。"); + } else { + System.out.println("道具数据已存在,无需重复加载。"); + } + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/controller/BackpackController.java b/dafuweng-backend/src/main/java/com/dafuweng/controller/BackpackController.java new file mode 100644 index 0000000..1002476 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/controller/BackpackController.java @@ -0,0 +1,65 @@ +package com.dafuweng.controller; + +import com.dafuweng.model.BackpackItem; +import com.dafuweng.service.BackpackService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/backpack") +public class BackpackController { + @Autowired + private BackpackService backpackService; + + @GetMapping("/player/{playerId}") + public List getBackpackByPlayerId(@PathVariable Long playerId) { + return backpackService.getBackpackByPlayerId(playerId); + } + + @PostMapping("/add") + public ResponseEntity addItemToBackpack( + @RequestParam Long playerId, + @RequestParam Long itemId, + @RequestParam int quantity) { + + BackpackItem item = backpackService.addItemToBackpack(playerId, itemId, quantity); + if (item != null) { + return ResponseEntity.ok(item); + } else { + return ResponseEntity.badRequest().build(); + } + } + + @DeleteMapping("/remove/{backpackItemId}") + public ResponseEntity removeItemFromBackpack(@PathVariable Long backpackItemId) { + boolean result = backpackService.removeItemFromBackpack(backpackItemId); + if (result) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } + + @PostMapping("/use/{backpackItemId}") + public ResponseEntity useItem(@PathVariable Long backpackItemId) { + boolean result = backpackService.useItem(backpackItemId); + if (result) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } + + @PostMapping("/equip/{backpackItemId}") + public ResponseEntity equipItem(@PathVariable Long backpackItemId) { + boolean result = backpackService.equipItem(backpackItemId); + if (result) { + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/controller/ItemController.java b/dafuweng-backend/src/main/java/com/dafuweng/controller/ItemController.java new file mode 100644 index 0000000..a32d09e --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/controller/ItemController.java @@ -0,0 +1,81 @@ +package com.dafuweng.controller; + +import com.dafuweng.model.Item; +import com.dafuweng.service.ItemService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/items") +public class ItemController { + @Autowired + private ItemService itemService; + + @GetMapping + public List getAllItems() { + return itemService.getAllItems(); + } + + @GetMapping("/{id}") + public ResponseEntity getItemById(@PathVariable Long id) { + Item item = itemService.getItemById(id); + if (item != null) { + return ResponseEntity.ok(item); + } else { + return ResponseEntity.notFound().build(); + } + } + + @GetMapping("/name/{name}") + public ResponseEntity getItemByName(@PathVariable String name) { + Item item = itemService.getItemByName(name); + if (item != null) { + return ResponseEntity.ok(item); + } else { + return ResponseEntity.notFound().build(); + } + } + + @PostMapping + public Item createItem(@RequestBody Item item) { + return itemService.saveItem(item); + } + + @PutMapping("/{id}") + public ResponseEntity updateItem(@PathVariable Long id, @RequestBody Item itemDetails) { + Item item = itemService.getItemById(id); + + if (item != null) { + item.setName(itemDetails.getName()); + item.setDisplayName(itemDetails.getDisplayName()); + item.setIconUrl(itemDetails.getIconUrl()); + item.setDescription(itemDetails.getDescription()); + item.setType(itemDetails.getType()); + item.setEffectValue(itemDetails.getEffectValue()); + item.setEffectTarget(itemDetails.getEffectTarget()); + item.setEffectDuration(itemDetails.getEffectDuration()); + item.setPrice(itemDetails.getPrice()); + item.setMaxStackSize(itemDetails.getMaxStackSize()); + + Item updatedItem = itemService.saveItem(item); + return ResponseEntity.ok(updatedItem); + } else { + return ResponseEntity.notFound().build(); + } + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteItem(@PathVariable Long id) { + Item item = itemService.getItemById(id); + + if (item != null) { + itemService.deleteItem(id); + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/controller/PlayerController.java b/dafuweng-backend/src/main/java/com/dafuweng/controller/PlayerController.java new file mode 100644 index 0000000..62e69f5 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/controller/PlayerController.java @@ -0,0 +1,99 @@ +package com.dafuweng.controller; + +import com.dafuweng.model.Player; +import com.dafuweng.service.PlayerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/players") +public class PlayerController { + @Autowired + private PlayerService playerService; + + @GetMapping + public List getAllPlayers() { + return playerService.getAllPlayers(); + } + + @GetMapping("/{id}") + public ResponseEntity getPlayerById(@PathVariable Long id) { + Player player = playerService.getPlayerById(id); + if (player != null) { + return ResponseEntity.ok(player); + } else { + return ResponseEntity.notFound().build(); + } + } + + @GetMapping("/name/{name}") + public ResponseEntity getPlayerByName(@PathVariable String name) { + Player player = playerService.getPlayerByName(name); + if (player != null) { + return ResponseEntity.ok(player); + } else { + return ResponseEntity.notFound().build(); + } + } + + @PostMapping + public Player createPlayer(@RequestBody Player player) { + return playerService.savePlayer(player); + } + + @PutMapping("/{id}") + public ResponseEntity updatePlayer(@PathVariable Long id, @RequestBody Player playerDetails) { + Player player = playerService.getPlayerById(id); + + if (player != null) { + player.setName(playerDetails.getName()); + player.setDisplayName(playerDetails.getDisplayName()); + player.setPosition(playerDetails.getPosition()); + player.setMoney(playerDetails.getMoney()); + player.setGpa(playerDetails.getGpa()); + player.setStop(playerDetails.getStop()); + player.setTurnOrder(playerDetails.getTurnOrder()); + player.setActive(playerDetails.isActive()); + player.setRole(playerDetails.getRole()); + player.setBackpack(playerDetails.getBackpack()); + + Player updatedPlayer = playerService.savePlayer(player); + return ResponseEntity.ok(updatedPlayer); + } else { + return ResponseEntity.notFound().build(); + } + } + + @DeleteMapping("/{id}") + public ResponseEntity deletePlayer(@PathVariable Long id) { + Player player = playerService.getPlayerById(id); + + if (player != null) { + playerService.deletePlayer(id); + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } + + @PutMapping("/{id}/money") + public ResponseEntity updatePlayerMoney(@PathVariable Long id, @RequestParam int amount) { + playerService.updatePlayerMoney(id, amount); + return ResponseEntity.ok(playerService.getPlayerById(id)); + } + + @PutMapping("/{id}/position") + public ResponseEntity updatePlayerPosition(@PathVariable Long id, @RequestParam int position) { + playerService.updatePlayerPosition(id, position); + return ResponseEntity.ok(playerService.getPlayerById(id)); + } + + @PutMapping("/{id}/gpa") + public ResponseEntity updatePlayerGpa(@PathVariable Long id, @RequestParam double gpaChange) { + playerService.updatePlayerGpa(id, gpaChange); + return ResponseEntity.ok(playerService.getPlayerById(id)); + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/controller/RoleController.java b/dafuweng-backend/src/main/java/com/dafuweng/controller/RoleController.java new file mode 100644 index 0000000..d2efce7 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/controller/RoleController.java @@ -0,0 +1,77 @@ +package com.dafuweng.controller; + +import com.dafuweng.model.Role; +import com.dafuweng.service.RoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/roles") +public class RoleController { + @Autowired + private RoleService roleService; + + @GetMapping + public List getAllRoles() { + return roleService.getAllRoles(); + } + + @GetMapping("/{id}") + public ResponseEntity getRoleById(@PathVariable Long id) { + Role role = roleService.getRoleById(id); + if (role != null) { + return ResponseEntity.ok(role); + } else { + return ResponseEntity.notFound().build(); + } + } + + @GetMapping("/name/{name}") + public ResponseEntity getRoleByName(@PathVariable String name) { + Role role = roleService.getRoleByName(name); + if (role != null) { + return ResponseEntity.ok(role); + } else { + return ResponseEntity.notFound().build(); + } + } + + @PostMapping + public Role createRole(@RequestBody Role role) { + return roleService.saveRole(role); + } + + @PutMapping("/{id}") + public ResponseEntity updateRole(@PathVariable Long id, @RequestBody Role roleDetails) { + Role role = roleService.getRoleById(id); + + if (role != null) { + role.setName(roleDetails.getName()); + role.setDisplayName(roleDetails.getDisplayName()); + role.setAvatarUrl(roleDetails.getAvatarUrl()); + role.setDescription(roleDetails.getDescription()); + role.setAttribute(roleDetails.getAttribute()); + role.setSkills(roleDetails.getSkills()); + + Role updatedRole = roleService.saveRole(role); + return ResponseEntity.ok(updatedRole); + } else { + return ResponseEntity.notFound().build(); + } + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteRole(@PathVariable Long id) { + Role role = roleService.getRoleById(id); + + if (role != null) { + roleService.deleteRole(id); + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/model/BackpackItem.java b/dafuweng-backend/src/main/java/com/dafuweng/model/BackpackItem.java new file mode 100644 index 0000000..e1dacd8 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/model/BackpackItem.java @@ -0,0 +1,62 @@ +package com.dafuweng.model; + +import jakarta.persistence.*; + +@Entity +public class BackpackItem { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "player_id") + private Player player; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "item_id") + private Item item; + + private int quantity; + private boolean isEquipped; + + // Getters and Setters + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Player getPlayer() { + return player; + } + + public void setPlayer(Player player) { + this.player = player; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public boolean isEquipped() { + return isEquipped; + } + + public void setEquipped(boolean equipped) { + isEquipped = equipped; + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/model/Item.java b/dafuweng-backend/src/main/java/com/dafuweng/model/Item.java new file mode 100644 index 0000000..0210da0 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/model/Item.java @@ -0,0 +1,112 @@ +package com.dafuweng.model; + +import jakarta.persistence.*; + +@Entity +public class Item { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + private String displayName; + private String iconUrl; + private String description; + private String type; + + private int effectValue; + private String effectTarget; + private String effectDuration; + + private int price; + private int maxStackSize; + + // Getters and Setters + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getIconUrl() { + return iconUrl; + } + + public void setIconUrl(String iconUrl) { + this.iconUrl = iconUrl; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public int getEffectValue() { + return effectValue; + } + + public void setEffectValue(int effectValue) { + this.effectValue = effectValue; + } + + public String getEffectTarget() { + return effectTarget; + } + + public void setEffectTarget(String effectTarget) { + this.effectTarget = effectTarget; + } + + public String getEffectDuration() { + return effectDuration; + } + + public void setEffectDuration(String effectDuration) { + this.effectDuration = effectDuration; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + + public int getMaxStackSize() { + return maxStackSize; + } + + public void setMaxStackSize(int maxStackSize) { + this.maxStackSize = maxStackSize; + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/model/Player.java b/dafuweng-backend/src/main/java/com/dafuweng/model/Player.java new file mode 100644 index 0000000..092487d --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/model/Player.java @@ -0,0 +1,116 @@ +package com.dafuweng.model; + +import jakarta.persistence.*; +import java.util.List; + +@Entity +public class Player { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + private String displayName; + private int position; + private int money; + private double gpa; + private int stop; + private int turnOrder; + private boolean isActive; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "role_id", referencedColumnName = "id") + private Role role; + + @OneToMany(mappedBy = "player", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List backpack; + + // Getters and Setters + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public int getMoney() { + return money; + } + + public void setMoney(int money) { + this.money = money; + } + + public double getGpa() { + return gpa; + } + + public void setGpa(double gpa) { + this.gpa = gpa; + } + + public int getStop() { + return stop; + } + + public void setStop(int stop) { + this.stop = stop; + } + + public int getTurnOrder() { + return turnOrder; + } + + public void setTurnOrder(int turnOrder) { + this.turnOrder = turnOrder; + } + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean active) { + isActive = active; + } + + public Role getRole() { + return role; + } + + public void setRole(Role role) { + this.role = role; + } + + public List getBackpack() { + return backpack; + } + + public void setBackpack(List backpack) { + this.backpack = backpack; + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/model/Role.java b/dafuweng-backend/src/main/java/com/dafuweng/model/Role.java new file mode 100644 index 0000000..5c7c989 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/model/Role.java @@ -0,0 +1,80 @@ +package com.dafuweng.model; + +import jakarta.persistence.*; +import java.util.List; + +@Entity +public class Role { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + private String displayName; + private String avatarUrl; + private String description; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "attribute_id", referencedColumnName = "id") + private RoleAttribute attribute; + + @OneToMany(mappedBy = "role", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List skills; + + // Getters and Setters + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getAvatarUrl() { + return avatarUrl; + } + + public void setAvatarUrl(String avatarUrl) { + this.avatarUrl = avatarUrl; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public RoleAttribute getAttribute() { + return attribute; + } + + public void setAttribute(RoleAttribute attribute) { + this.attribute = attribute; + } + + public List getSkills() { + return skills; + } + + public void setSkills(List skills) { + this.skills = skills; + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/model/RoleAttribute.java b/dafuweng-backend/src/main/java/com/dafuweng/model/RoleAttribute.java new file mode 100644 index 0000000..564d708 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/model/RoleAttribute.java @@ -0,0 +1,94 @@ +package com.dafuweng.model; + +import jakarta.persistence.*; + +@Entity +public class RoleAttribute { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private int strength; // 力量 + private int intelligence; // 智力 + private int agility; // 敏捷 + private int luck; // 运气 + private int charm; // 魅力 + + private int maxHealth; // 最大生命值 + private int currentHealth; // 当前生命值 + + private int baseMoney; // 初始金钱 + + // Getters and Setters + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public int getStrength() { + return strength; + } + + public void setStrength(int strength) { + this.strength = strength; + } + + public int getIntelligence() { + return intelligence; + } + + public void setIntelligence(int intelligence) { + this.intelligence = intelligence; + } + + public int getAgility() { + return agility; + } + + public void setAgility(int agility) { + this.agility = agility; + } + + public int getLuck() { + return luck; + } + + public void setLuck(int luck) { + this.luck = luck; + } + + public int getCharm() { + return charm; + } + + public void setCharm(int charm) { + this.charm = charm; + } + + public int getMaxHealth() { + return maxHealth; + } + + public void setMaxHealth(int maxHealth) { + this.maxHealth = maxHealth; + } + + public int getCurrentHealth() { + return currentHealth; + } + + public void setCurrentHealth(int currentHealth) { + this.currentHealth = currentHealth; + } + + public int getBaseMoney() { + return baseMoney; + } + + public void setBaseMoney(int baseMoney) { + this.baseMoney = baseMoney; + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/model/RoleSkill.java b/dafuweng-backend/src/main/java/com/dafuweng/model/RoleSkill.java new file mode 100644 index 0000000..db4ca7e --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/model/RoleSkill.java @@ -0,0 +1,86 @@ +package com.dafuweng.model; + +import jakarta.persistence.*; + +@Entity +public class RoleSkill { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + private String description; + private String type; + private int cooldown; + private int level; + private int maxLevel; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "role_id") + private Role role; + + // Getters and Setters + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public int getCooldown() { + return cooldown; + } + + public void setCooldown(int cooldown) { + this.cooldown = cooldown; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public int getMaxLevel() { + return maxLevel; + } + + public void setMaxLevel(int maxLevel) { + this.maxLevel = maxLevel; + } + + public Role getRole() { + return role; + } + + public void setRole(Role role) { + this.role = role; + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/repository/BackpackItemRepository.java b/dafuweng-backend/src/main/java/com/dafuweng/repository/BackpackItemRepository.java new file mode 100644 index 0000000..1a5c6b7 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/repository/BackpackItemRepository.java @@ -0,0 +1,13 @@ +package com.dafuweng.repository; + +import com.dafuweng.model.BackpackItem; +import com.dafuweng.model.Player; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface BackpackItemRepository extends JpaRepository { + List findByPlayer(Player player); +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/repository/ItemRepository.java b/dafuweng-backend/src/main/java/com/dafuweng/repository/ItemRepository.java new file mode 100644 index 0000000..16ad00b --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/repository/ItemRepository.java @@ -0,0 +1,10 @@ +package com.dafuweng.repository; + +import com.dafuweng.model.Item; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ItemRepository extends JpaRepository { + Item findByName(String name); +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/repository/PlayerRepository.java b/dafuweng-backend/src/main/java/com/dafuweng/repository/PlayerRepository.java new file mode 100644 index 0000000..5e8260f --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/repository/PlayerRepository.java @@ -0,0 +1,10 @@ +package com.dafuweng.repository; + +import com.dafuweng.model.Player; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PlayerRepository extends JpaRepository { + Player findByName(String name); +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/repository/RoleRepository.java b/dafuweng-backend/src/main/java/com/dafuweng/repository/RoleRepository.java new file mode 100644 index 0000000..8cc2c7e --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/repository/RoleRepository.java @@ -0,0 +1,10 @@ +package com.dafuweng.repository; + +import com.dafuweng.model.Role; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface RoleRepository extends JpaRepository { + Role findByName(String name); +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/service/BackpackService.java b/dafuweng-backend/src/main/java/com/dafuweng/service/BackpackService.java new file mode 100644 index 0000000..8420d2f --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/service/BackpackService.java @@ -0,0 +1,102 @@ +package com.dafuweng.service; + +import com.dafuweng.model.BackpackItem; +import com.dafuweng.model.Item; +import com.dafuweng.model.Player; +import com.dafuweng.repository.BackpackItemRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class BackpackService { + @Autowired + private BackpackItemRepository backpackItemRepository; + + @Autowired + private PlayerService playerService; + + @Autowired + private ItemService itemService; + + public List getBackpackByPlayerId(Long playerId) { + Player player = playerService.getPlayerById(playerId); + if (player != null) { + return backpackItemRepository.findByPlayer(player); + } + return null; + } + + public BackpackItem addItemToBackpack(Long playerId, Long itemId, int quantity) { + Player player = playerService.getPlayerById(playerId); + Item item = itemService.getItemById(itemId); + + if (player != null && item != null) { + List backpack = backpackItemRepository.findByPlayer(player); + + // 检查背包中是否已有该物品 + for (BackpackItem existingItem : backpack) { + if (existingItem.getItem().getId().equals(itemId)) { + // 如果已有该物品,增加数量 + existingItem.setQuantity(existingItem.getQuantity() + quantity); + return backpackItemRepository.save(existingItem); + } + } + + // 如果背包中没有该物品,创建新的背包物品 + BackpackItem newItem = new BackpackItem(); + newItem.setPlayer(player); + newItem.setItem(item); + newItem.setQuantity(quantity); + newItem.setEquipped(false); + + return backpackItemRepository.save(newItem); + } + + return null; + } + + public boolean removeItemFromBackpack(Long backpackItemId) { + BackpackItem item = backpackItemRepository.findById(backpackItemId).orElse(null); + + if (item != null) { + backpackItemRepository.delete(item); + return true; + } + + return false; + } + + public boolean useItem(Long backpackItemId) { + BackpackItem item = backpackItemRepository.findById(backpackItemId).orElse(null); + + if (item != null && item.getQuantity() > 0) { + // 实现物品使用逻辑 + item.setQuantity(item.getQuantity() - 1); + + // 如果使用后数量为0,从背包中移除 + if (item.getQuantity() == 0) { + backpackItemRepository.delete(item); + } else { + backpackItemRepository.save(item); + } + + return true; + } + + return false; + } + + public boolean equipItem(Long backpackItemId) { + BackpackItem item = backpackItemRepository.findById(backpackItemId).orElse(null); + + if (item != null) { + item.setEquipped(!item.isEquipped()); + backpackItemRepository.save(item); + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/service/ItemService.java b/dafuweng-backend/src/main/java/com/dafuweng/service/ItemService.java new file mode 100644 index 0000000..106bea4 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/service/ItemService.java @@ -0,0 +1,34 @@ +package com.dafuweng.service; + +import com.dafuweng.model.Item; +import com.dafuweng.repository.ItemRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class ItemService { + @Autowired + private ItemRepository itemRepository; + + public List getAllItems() { + return itemRepository.findAll(); + } + + public Item getItemById(Long id) { + return itemRepository.findById(id).orElse(null); + } + + public Item getItemByName(String name) { + return itemRepository.findByName(name); + } + + public Item saveItem(Item item) { + return itemRepository.save(item); + } + + public void deleteItem(Long id) { + itemRepository.deleteById(id); + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/service/PlayerService.java b/dafuweng-backend/src/main/java/com/dafuweng/service/PlayerService.java new file mode 100644 index 0000000..c0f5ea2 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/service/PlayerService.java @@ -0,0 +1,58 @@ +package com.dafuweng.service; + +import com.dafuweng.model.Player; +import com.dafuweng.repository.PlayerRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class PlayerService { + @Autowired + private PlayerRepository playerRepository; + + public List getAllPlayers() { + return playerRepository.findAll(); + } + + public Player getPlayerById(Long id) { + return playerRepository.findById(id).orElse(null); + } + + public Player getPlayerByName(String name) { + return playerRepository.findByName(name); + } + + public Player savePlayer(Player player) { + return playerRepository.save(player); + } + + public void deletePlayer(Long id) { + playerRepository.deleteById(id); + } + + public void updatePlayerMoney(Long playerId, int amount) { + Player player = getPlayerById(playerId); + if (player != null) { + player.setMoney(player.getMoney() + amount); + playerRepository.save(player); + } + } + + public void updatePlayerPosition(Long playerId, int position) { + Player player = getPlayerById(playerId); + if (player != null) { + player.setPosition(position); + playerRepository.save(player); + } + } + + public void updatePlayerGpa(Long playerId, double gpaChange) { + Player player = getPlayerById(playerId); + if (player != null) { + player.setGpa(player.getGpa() + gpaChange); + playerRepository.save(player); + } + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/java/com/dafuweng/service/RoleService.java b/dafuweng-backend/src/main/java/com/dafuweng/service/RoleService.java new file mode 100644 index 0000000..5521829 --- /dev/null +++ b/dafuweng-backend/src/main/java/com/dafuweng/service/RoleService.java @@ -0,0 +1,34 @@ +package com.dafuweng.service; + +import com.dafuweng.model.Role; +import com.dafuweng.repository.RoleRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class RoleService { + @Autowired + private RoleRepository roleRepository; + + public List getAllRoles() { + return roleRepository.findAll(); + } + + public Role getRoleById(Long id) { + return roleRepository.findById(id).orElse(null); + } + + public Role getRoleByName(String name) { + return roleRepository.findByName(name); + } + + public Role saveRole(Role role) { + return roleRepository.save(role); + } + + public void deleteRole(Long id) { + roleRepository.deleteById(id); + } +} \ No newline at end of file diff --git a/dafuweng-backend/src/main/resources/application.properties b/dafuweng-backend/src/main/resources/application.properties new file mode 100644 index 0000000..fab32ce --- /dev/null +++ b/dafuweng-backend/src/main/resources/application.properties @@ -0,0 +1,28 @@ +# 数据库配置 +spring.datasource.url=jdbc:h2:mem:dafuwengdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect + +# H2控制台配置 +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + +# JPA配置 +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true + +# 服务器配置 +server.port=8080 +server.servlet.context-path=/api + +# 资源配置 +spring.resources.static-locations=classpath:/static/,file:/images/ + +# CORS配置 +spring.web.cors.allowed-origins=* +spring.web.cors.allowed-methods=GET,POST,PUT,DELETE,OPTIONS +spring.web.cors.allowed-headers=* +spring.web.cors.allow-credentials=true \ No newline at end of file diff --git a/dafuweng-frontend/index.html b/dafuweng-frontend/index.html new file mode 100644 index 0000000..02921c8 --- /dev/null +++ b/dafuweng-frontend/index.html @@ -0,0 +1,13 @@ + + + + + + + 大富翁——清华之旅 + + +
+ + + \ No newline at end of file diff --git a/dafuweng-frontend/src/App.vue b/dafuweng-frontend/src/App.vue new file mode 100644 index 0000000..4974239 --- /dev/null +++ b/dafuweng-frontend/src/App.vue @@ -0,0 +1,36 @@ + + + + + \ No newline at end of file diff --git a/dafuweng-frontend/src/components/Backpack.vue b/dafuweng-frontend/src/components/Backpack.vue new file mode 100644 index 0000000..c657d08 --- /dev/null +++ b/dafuweng-frontend/src/components/Backpack.vue @@ -0,0 +1,360 @@ + + + + + \ No newline at end of file diff --git a/dafuweng-frontend/src/components/Dice.vue b/dafuweng-frontend/src/components/Dice.vue new file mode 100644 index 0000000..f58ca0f --- /dev/null +++ b/dafuweng-frontend/src/components/Dice.vue @@ -0,0 +1,144 @@ + + + + + \ No newline at end of file diff --git a/dafuweng-frontend/src/components/GameMap.vue b/dafuweng-frontend/src/components/GameMap.vue new file mode 100644 index 0000000..de249c4 --- /dev/null +++ b/dafuweng-frontend/src/components/GameMap.vue @@ -0,0 +1,193 @@ + + + + + \ No newline at end of file diff --git a/dafuweng-frontend/src/components/PlayerStatus.vue b/dafuweng-frontend/src/components/PlayerStatus.vue new file mode 100644 index 0000000..b4d8bb9 --- /dev/null +++ b/dafuweng-frontend/src/components/PlayerStatus.vue @@ -0,0 +1,212 @@ + + + + + \ No newline at end of file diff --git a/dafuweng-frontend/src/main.js b/dafuweng-frontend/src/main.js new file mode 100644 index 0000000..fa0613a --- /dev/null +++ b/dafuweng-frontend/src/main.js @@ -0,0 +1,5 @@ +import { createApp } from 'vue' +import App from './App.vue' +import './styles.css' + +createApp(App).mount('#app') \ No newline at end of file diff --git a/ke b/ke new file mode 100644 index 0000000..e69de29