Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/DaFuWeng.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added __pycache__/draw.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/game.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/player.cpython-312.pyc
Binary file not shown.
54 changes: 54 additions & 0 deletions dafuweng-backend/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.dafuweng</groupId>
<artifactId>dafuweng-backend</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<java.version>17</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions dafuweng-backend/src/main/java/com/dafuweng/Application.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
191 changes: 191 additions & 0 deletions dafuweng-backend/src/main/java/com/dafuweng/DataInitializer.java
Original file line number Diff line number Diff line change
@@ -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<Item> 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("道具数据已存在,无需重复加载。");
}
}
}
Original file line number Diff line number Diff line change
@@ -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<BackpackItem> getBackpackByPlayerId(@PathVariable Long playerId) {
return backpackService.getBackpackByPlayerId(playerId);
}

@PostMapping("/add")
public ResponseEntity<BackpackItem> 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<Void> 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<Void> 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<Void> equipItem(@PathVariable Long backpackItemId) {
boolean result = backpackService.equipItem(backpackItemId);
if (result) {
return ResponseEntity.noContent().build();
} else {
return ResponseEntity.notFound().build();
}
}
}
Loading