File size: 3,841 Bytes
82fa936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1132acb
82fa936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

"""
Main Entry Point - Gradio UI
"""

import gradio as gr
from game_world import SmurfWorld
from entities import LifeStage, BuildingType
from ai_behavior import Personality
from config import FPS
from logging_config import setup_logging

# Configure logging (enabled/disabled via config.LOGGING_ENABLED)
setup_logging()

class SmurfGame:
    def __init__(self):
        self.world = SmurfWorld()
        self.running = True
    
    def game_loop(self):
        if self.running:
            self.world.update()
        return self.world.render()
    
    def toggle_pause(self):
        self.running = not self.running
        return "Resume" if not self.running else "Pause"
    
    def spawn_new_smurf(self):
        smurf = self.world.spawn_smurf(life_stage=LifeStage.ADULT)
        return f"Spawned {smurf.smurf_name}! Total: {len([s for s in self.world.smurfs if s.is_alive])}"
    
    def get_stats(self) -> str:
        alive = [s for s in self.world.smurfs if s.is_alive]
        stats = f"""### Village Statistics

**Population:**
- πŸ‘₯ Alive: {len(alive)}
- πŸ‘Ά Babies: {len([s for s in alive if s.life_stage == LifeStage.BABY])}
- πŸ§’ Children: {len([s for s in alive if s.life_stage == LifeStage.CHILD])}
- πŸ§‘ Adults: {len([s for s in alive if s.life_stage == LifeStage.ADULT])}
- πŸ‘΄ Elders: {len([s for s in alive if s.life_stage == LifeStage.ELDER])}
- πŸͺ¦ Died: {len(self.world.graves)}

**Personalities:**
- πŸ”¨ Workers: {len([s for s in alive if s.personality == Personality.WORKER])}
- πŸ—ΊοΈ Explorers: {len([s for s in alive if s.personality == Personality.EXPLORER])}
- 😴 Lazy: {len([s for s in alive if s.personality == Personality.LAZY])}
- 🀝 Social: {len([s for s in alive if s.personality == Personality.SOCIAL])}

**Resources:**
- πŸ„ Mushrooms: {len([r for r in self.world.resources if r.resource_type == 'mushroom' and not r.is_depleted()])}
- 🫐 Berries:{len([r for r in self.world.resources if r.resource_type == 'berry' and not r.is_depleted()])}
- πŸͺ΅ Wood:  {len([r for r in self.world.resources if r.resource_type == 'wood' and not r.is_depleted()])}

**Buildings:**
- Houses: {len([b for b in self.world.buildings if b.building_type == BuildingType.HOUSE])}
- Storage: {len([b for b in self.world.buildings if b.building_type == BuildingType.STORAGE])}
- Workshops: {len([b for b in self.world.buildings if b.building_type == BuildingType.WORKSHOP])}
- Town Hall: {len([b for b in self.world.buildings if b.building_type == BuildingType.TOWNHALL])}

**Village Score:** {self.world.village_score}
"""
        return stats

game = SmurfGame()

# UI
with gr.Blocks(title="Smurf Village") as demo:
    gr.Markdown("# πŸ„ Smurf Village - Complete Life Simulation")
    gr.Markdown("**Watch your Smurfs live, work, socialize, age, and build a thriving village!**")
    
    with gr.Row():
        with gr.Column(scale=3):
            game_display = gr.Image(label="Smurf Village World", height=600)
            timer = gr.Timer(value=1/FPS)
            
            with gr.Row():
                pause_btn = gr.Button("Pause", scale=1)
                spawn_btn = gr.Button("Spawn Adult Smurf", scale=1)
        
        with gr.Column(scale=1):
            status = gr.Textbox(label="Status", value="Village starting...")
            stats_display = gr.Markdown(game.get_stats())
            
            gr.Markdown("""
            ### Enjoy watching your village grow! πŸ„
            """)
    
    # Events
    timer.tick(fn=game.game_loop, outputs=game_display, show_progress="hidden")
    pause_btn.click(fn=game.toggle_pause, outputs=pause_btn)
    spawn_btn.click(fn=game.spawn_new_smurf, outputs=status)
    
    stats_timer = gr.Timer(value=2)
    stats_timer.tick(fn=game.get_stats, outputs=stats_display, show_progress="hidden")

if __name__ == "__main__":
    demo.launch()