Spaces:
Sleeping
Sleeping
Commit
·
dcffdde
1
Parent(s):
b3b7541
a3
Browse files- Dockerfile +26 -0
- app.py +48 -0
- packages.txt +1 -0
Dockerfile
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
# Instalar Java
|
| 4 |
+
RUN apt-get update && \
|
| 5 |
+
apt-get install -y default-jdk && \
|
| 6 |
+
apt-get clean && \
|
| 7 |
+
rm -rf /var/lib/apt/lists/*
|
| 8 |
+
|
| 9 |
+
# Verificar instalação do Java
|
| 10 |
+
RUN java -version && javac -version
|
| 11 |
+
|
| 12 |
+
# Configurar diretório de trabalho
|
| 13 |
+
WORKDIR /code
|
| 14 |
+
|
| 15 |
+
# Copiar requirements e instalar dependências Python
|
| 16 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 17 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 18 |
+
|
| 19 |
+
# Copiar código da aplicação
|
| 20 |
+
COPY . /code
|
| 21 |
+
|
| 22 |
+
# Expor porta
|
| 23 |
+
EXPOSE 7860
|
| 24 |
+
|
| 25 |
+
# Comando para executar a aplicação
|
| 26 |
+
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -3,6 +3,37 @@ import os
|
|
| 3 |
import subprocess
|
| 4 |
import time
|
| 5 |
from collections import deque
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Criar pasta para armazenar as classes Java
|
| 8 |
os.makedirs("combat_classes", exist_ok=True)
|
|
@@ -429,6 +460,23 @@ public class Projectile {
|
|
| 429 |
"""
|
| 430 |
|
| 431 |
def run_battle(code1, code2, screen_width, battlefield_height, p1_start_pos, p2_start_pos, team1_health, team2_health):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
# Caminhos dos arquivos Java
|
| 433 |
aircraft_path = "combat_classes/Aircraft.java"
|
| 434 |
projectile_path = "combat_classes/Projectile.java"
|
|
|
|
| 3 |
import subprocess
|
| 4 |
import time
|
| 5 |
from collections import deque
|
| 6 |
+
import shutil
|
| 7 |
+
|
| 8 |
+
def check_and_install_java():
|
| 9 |
+
"""Verifica se Java está instalado e tenta instalar se necessário"""
|
| 10 |
+
try:
|
| 11 |
+
# Verificar se javac está disponível
|
| 12 |
+
result = subprocess.run(["javac", "-version"], capture_output=True, text=True)
|
| 13 |
+
if result.returncode == 0:
|
| 14 |
+
return True, "Java já está instalado"
|
| 15 |
+
except FileNotFoundError:
|
| 16 |
+
pass
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
# Tentar instalar Java usando apt-get
|
| 20 |
+
print("🔧 Instalando Java...")
|
| 21 |
+
subprocess.run(["apt-get", "update"], check=True, capture_output=True)
|
| 22 |
+
subprocess.run(["apt-get", "install", "-y", "default-jdk"], check=True, capture_output=True)
|
| 23 |
+
|
| 24 |
+
# Verificar se a instalação funcionou
|
| 25 |
+
result = subprocess.run(["javac", "-version"], capture_output=True, text=True)
|
| 26 |
+
if result.returncode == 0:
|
| 27 |
+
return True, "Java instalado com sucesso"
|
| 28 |
+
except Exception as e:
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
# Se chegou até aqui, não conseguiu instalar
|
| 32 |
+
return False, "Não foi possível instalar Java automaticamente"
|
| 33 |
+
|
| 34 |
+
# Verificar Java na inicialização
|
| 35 |
+
java_available, java_message = check_and_install_java()
|
| 36 |
+
print(f"Status do Java: {java_message}")
|
| 37 |
|
| 38 |
# Criar pasta para armazenar as classes Java
|
| 39 |
os.makedirs("combat_classes", exist_ok=True)
|
|
|
|
| 460 |
"""
|
| 461 |
|
| 462 |
def run_battle(code1, code2, screen_width, battlefield_height, p1_start_pos, p2_start_pos, team1_health, team2_health):
|
| 463 |
+
# Verificar se Java está disponível
|
| 464 |
+
if not java_available:
|
| 465 |
+
yield f"""
|
| 466 |
+
<div style="padding:20px; background-color:#ffe6e6; border:2px solid #ff4444; border-radius:5px; margin:10px;">
|
| 467 |
+
<h3 style="color:#cc0000;">❌ Java não está disponível</h3>
|
| 468 |
+
<p>Este aplicativo requer Java para compilar e executar as aeronaves.</p>
|
| 469 |
+
<p><strong>Soluções:</strong></p>
|
| 470 |
+
<ul>
|
| 471 |
+
<li>Execute localmente com Java instalado</li>
|
| 472 |
+
<li>Use um ambiente Docker com Java</li>
|
| 473 |
+
<li>Aguarde enquanto tentamos instalar Java automaticamente...</li>
|
| 474 |
+
</ul>
|
| 475 |
+
<p><em>Status: {java_message}</em></p>
|
| 476 |
+
</div>
|
| 477 |
+
"""
|
| 478 |
+
return
|
| 479 |
+
|
| 480 |
# Caminhos dos arquivos Java
|
| 481 |
aircraft_path = "combat_classes/Aircraft.java"
|
| 482 |
projectile_path = "combat_classes/Projectile.java"
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
default-jdk
|