Skip to content

Commit

Permalink
GreedySnakeGame upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Aizhouym authored Oct 14, 2023
1 parent 870b007 commit 2759d4c
Show file tree
Hide file tree
Showing 11 changed files with 5,441 additions and 0 deletions.
101 changes: 101 additions & 0 deletions WareHouse/GreedySnakeGame_THUNLP_20231008212648/ChatChainConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"chain": [
{
"phase": "DemandAnalysis",
"phaseType": "SimplePhase",
"max_turn_step": -1,
"need_reflect": "True"
},
{
"phase": "LanguageChoose",
"phaseType": "SimplePhase",
"max_turn_step": -1,
"need_reflect": "True"
},
{
"phase": "Coding",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "False"
},
{
"phase": "CodeCompleteAll",
"phaseType": "ComposedPhase",
"cycleNum": 10,
"Composition": [
{
"phase": "CodeComplete",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "False"
}
]
},
{
"phase": "CodeReview",
"phaseType": "ComposedPhase",
"cycleNum": 3,
"Composition": [
{
"phase": "CodeReviewComment",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "False"
},
{
"phase": "CodeReviewModification",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "False"
}
]
},
{
"phase": "Test",
"phaseType": "ComposedPhase",
"cycleNum": 3,
"Composition": [
{
"phase": "TestErrorSummary",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "False"
},
{
"phase": "TestModification",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "False"
}
]
},
{
"phase": "EnvironmentDoc",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "True"
},
{
"phase": "Manual",
"phaseType": "SimplePhase",
"max_turn_step": 1,
"need_reflect": "False"
}
],
"recruitments": [
"Chief Executive Officer",
"Counselor",
"Chief Human Resource Officer",
"Chief Product Officer",
"Chief Technology Officer",
"Programmer",
"Code Reviewer",
"Software Test Engineer",
"Chief Creative Officer"
],
"clear_structure": "True",
"brainstorming": "False",
"gui_design": "True",
"git_management": "False",
"self_improve": "False"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Design a Greedy Snake game with the following rules and features:
1.The game starts with a snake of length 1 and a single food item on the grid.2.The player controls the snake's movement using arrow keys (or swipe gestures in a mobile version).3.The snake moves continuously in the direction it's facing, and the player's goal is to eat as much food as possible to grow longer.4.When the snake consumes a piece of food, its length increases, and a new piece of food appears at a random location on the grid.5.The game ends if the snake collides with the game boundaries or itself 6.Implement a scoring system to keep track of the player's score based on the number of food items eaten.7.Ensure that the game has visually appealing graphics, intuitive controls, and smooth animation.8.Provide options to adjust the game's difficulty level, such as increasing the snake's speed or changing the grid size.8.Include sound effects for actions like eating food or game over.9.Make the game robust by handling edge cases and ensuring it runs smoothly without crashes.10.The player should be able to start a new game or exit the game at any time.Please generate the code and UI elements necessary for this Greedy Snake game, and ensure that it is playable and enjoyable for users.

Large diffs are not rendered by default.

277 changes: 277 additions & 0 deletions WareHouse/GreedySnakeGame_THUNLP_20231008212648/PhaseConfig.json

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions WareHouse/GreedySnakeGame_THUNLP_20231008212648/RoleConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"Chief Executive Officer": [
"{chatdev_prompt}",
"You are Chief Executive Officer. Now, we are both working at ChatDev and we share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"Your main responsibilities include being an active decision-maker on users' demands and other key policy issues, leader, manager, and executor. Your decision-making role involves high-level decisions about policy and strategy; and your communicator role can involve speaking to the organization's management and employees.",
"Here is a new customer's task: {task}.",
"To complete the task, I will give you one or more instructions, and you must help me to write a specific solution that appropriately solves the requested instruction based on your expertise and my needs."
],
"Chief Product Officer": [
"{chatdev_prompt}",
"You are Chief Product Officer. we are both working at ChatDev. We share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"You are responsible for all product-related matters in ChatDev. Usually includes product design, product strategy, product vision, product innovation, project management and product marketing.",
"Here is a new customer's task: {task}.",
"To complete the task, you must write a response that appropriately solves the requested instruction based on your expertise and customer's needs."
],
"Counselor": [
"{chatdev_prompt}",
"You are Counselor. Now, we share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"Your main responsibilities include asking what user and customer think and provide your valuable suggestions. ",
"Here is a new customer's task: {task}.",
"To complete the task, I will give you one or more instructions, and you must help me to write a specific solution that appropriately solves the requested instruction based on your expertise and my needs."
],
"Chief Technology Officer": [
"{chatdev_prompt}",
"You are Chief Technology Officer. we are both working at ChatDev. We share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"You are very familiar to information technology. You will make high-level decisions for the overarching technology infrastructure that closely align with the organization's goals, while you work alongside the organization's information technology (\"IT\") staff members to perform everyday operations.",
"Here is a new customer's task: {task}.",
"To complete the task, You must write a response that appropriately solves the requested instruction based on your expertise and customer's needs."
],
"Chief Human Resource Officer": [
"{chatdev_prompt}",
"You are Chief Human Resource Officer. Now, we are both working at ChatDev and we share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"You are a corporate officer who oversees all aspects of human resource management and industrial relations policies, practices and operations for an organization. You will be involved in board staff recruitment, member selection, executive compensation, and succession planning. Besides, You report directly to the chief executive officer (CEO) and am a member of the most senior-level committees of a company (e.g., executive committee or office of CEO).",
"Here is a new customer's task: {task}.",
"To complete the task, you must write a response that appropriately solves the requested instruction based on your expertise and customer's needs."
],
"Programmer": [
"{chatdev_prompt}",
"You are Programmer. we are both working at ChatDev. We share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"You can write/create computer software or applications by providing a specific programming language to the computer. You have extensive computing and coding experience in many varieties of programming languages and platforms, such as Python, Java, C, C++, HTML, CSS, JavaScript, XML, SQL, PHP, etc,.",
"Here is a new customer's task: {task}.",
"To complete the task, you must write a response that appropriately solves the requested instruction based on your expertise and customer's needs."
],
"Code Reviewer": [
"{chatdev_prompt}",
"You are Code Reviewer. we are both working at ChatDev. We share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"You can help programmers to assess source codes for software troubleshooting, fix bugs to increase code quality and robustness, and offer proposals to improve the source codes.",
"Here is a new customer's task: {task}.",
"To complete the task, you must write a response that appropriately solves the requested instruction based on your expertise and customer's needs."
],
"Software Test Engineer": [
"{chatdev_prompt}",
"You are Software Test Engineer. we are both working at ChatDev. We share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"You can use the software as intended to analyze its functional properties, design manual and automated test procedures to evaluate each software product, build and implement software evaluation test programs, and run test programs to ensure that testing protocols evaluate the software correctly.",
"Here is a new customer's task: {task}.",
"To complete the task, you must write a response that appropriately solves the requested instruction based on your expertise and customer's needs."
],
"Chief Creative Officer": [
"{chatdev_prompt}",
"You are Chief Creative Officer. we are both working at ChatDev. We share a common interest in collaborating to successfully complete a task assigned by a new customer.",
"You direct ChatDev's creative software's and develop the artistic design strategy that defines the company's brand. You create the unique image or music of our produced software's and deliver this distinctive design to consumers to create a clear brand image which is a fundamental and essential work throughout the company.",
"Here is a new customer's task: {task}.",
"To complete the task, you must write a response that appropriately solves the requested instruction based on your expertise and customer's needs."
]
}
98 changes: 98 additions & 0 deletions WareHouse/GreedySnakeGame_THUNLP_20231008212648/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'''
Greedy Snake Game
'''
import pygame
import random
# Initialize the game
pygame.init()
# Set up the game window
window_width = 800
window_height = 600
window = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption("Greedy Snake Game")
# Define colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
# Define game variables
snake_size = 20
snake_speed = 10
clock = pygame.time.Clock()
# Define the Snake class
class Snake:
def __init__(self):
self.x = window_width // 2
self.y = window_height // 2
self.direction = "RIGHT"
self.length = 1
self.body = []
def move(self):
if self.direction == "UP":
self.y -= snake_size
elif self.direction == "DOWN":
self.y += snake_size
elif self.direction == "LEFT":
self.x -= snake_size
elif self.direction == "RIGHT":
self.x += snake_size
def draw(self):
for part in self.body:
pygame.draw.rect(window, GREEN, (part[0], part[1], snake_size, snake_size))
def check_collision(self):
if self.x < 0 or self.x >= window_width or self.y < 0 or self.y >= window_height:
return True
for part in self.body[1:]:
if self.x == part[0] and self.y == part[1]:
return True
return False
# Define the Food class
class Food:
def __init__(self):
self.x = random.randint(0, (window_width - snake_size) // snake_size) * snake_size
self.y = random.randint(0, (window_height - snake_size) // snake_size) * snake_size
def draw(self):
pygame.draw.rect(window, RED, (self.x, self.y, snake_size, snake_size))
# Initialize the snake and food
snake = Snake()
food = Food()
# Game loop
running = True
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP and snake.direction != "DOWN":
snake.direction = "UP"
elif event.key == pygame.K_DOWN and snake.direction != "UP":
snake.direction = "DOWN"
elif event.key == pygame.K_LEFT and snake.direction != "RIGHT":
snake.direction = "LEFT"
elif event.key == pygame.K_RIGHT and snake.direction != "LEFT":
snake.direction = "RIGHT"
# Move the snake
snake.move()
# Check collision with food
if snake.x == food.x and snake.y == food.y:
snake.length += 1
food = Food()
# Update the snake's body
snake.body.insert(0, (snake.x, snake.y))
if len(snake.body) > snake.length:
snake.body.pop()
# Check collision with snake's body or boundaries
if snake.check_collision():
running = False
# Clear the window
window.fill(BLACK)
# Draw the snake and food
snake.draw()
food.draw()
# Update the display
pygame.display.update()
# Set the game speed
clock.tick(snake_speed)
# Quit the game
pygame.quit()
66 changes: 66 additions & 0 deletions WareHouse/GreedySnakeGame_THUNLP_20231008212648/manual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Greedy Snake Game User Manual

## Introduction

Welcome to the Greedy Snake Game! This game is a classic arcade-style game where you control a snake and try to eat as much food as possible to grow longer. The game features visually appealing graphics, intuitive controls, and smooth animation to provide an enjoyable gaming experience.

## Installation

To play the Greedy Snake Game, you need to install the following dependencies:

- Python 3.x
- Pygame library

You can install the Pygame library by running the following command:

```
pip install pygame
```

## Starting the Game

To start the Greedy Snake Game, follow these steps:

1. Open a terminal or command prompt.
2. Navigate to the directory where you have saved the game files.
3. Run the following command to start the game:

```
python main.py
```

## Game Controls

- Use the arrow keys (up, down, left, right) to control the snake's movement.
- Press the "Enter" key to start a new game or exit the game.

## Game Rules

1. The game starts with a snake of length 1 and a single food item on the grid.
2. The player controls the snake's movement using arrow keys.
3. The snake moves continuously in the direction it's facing.
4. The player's goal is to eat as much food as possible to grow longer.
5. When the snake consumes a piece of food, its length increases, and a new piece of food appears at a random location on the grid.
6. The game ends if the snake collides with the game boundaries or itself.
7. The player's score is based on the number of food items eaten.
8. The game difficulty level can be adjusted by increasing the snake's speed or changing the grid size.
9. Sound effects are included for actions like eating food or game over.

## Game Interface

The game interface consists of a grid where the snake and food items are displayed. The snake is represented by green rectangles, and the food items are represented by red rectangles. The score is displayed at the top of the screen.

## Game Over

The game ends when the snake collides with the game boundaries or itself. A "Game Over" message is displayed, along with the player's final score. To start a new game, press the "Enter" key.

## Adjusting Difficulty Level

To adjust the game's difficulty level, you can modify the following variables in the `settings.py` file:

- `snake_speed`: Controls the speed of the snake. Increase the value to make the snake move faster.
- `window_width` and `window_height`: Control the size of the game window. Increase or decrease the values to change the grid size.

## Conclusion

Enjoy playing the Greedy Snake Game! Try to beat your high score and challenge your friends to see who can eat the most food. Have fun!
39 changes: 39 additions & 0 deletions WareHouse/GreedySnakeGame_THUNLP_20231008212648/menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'''
Game Menu
'''
import pygame
# Initialize the game
pygame.init()
# Set up the game window
window_width = 800
window_height = 600
window = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption("Greedy Snake Game")
# Define colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
# Define game variables
menu_font = pygame.font.Font(None, 36)
# Define the menu function
def menu():
running = True
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
running = False
# Clear the window
window.fill(BLACK)
# Draw the menu text
text = menu_font.render("Press Enter to Start", True, WHITE)
text_rect = text.get_rect(center=(window_width // 2, window_height // 2))
window.blit(text, text_rect)
# Update the display
pygame.display.update()
# Run the menu function
menu()
# Quit the game
pygame.quit()
Loading

0 comments on commit 2759d4c

Please sign in to comment.