/
against
/
CyberPunk_Game_Python
Обзор
Документация
Войти
/
against
/
CyberPunk_Game_Python
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
main.py
129 строк
5 KB
Svyat Against
Get Alpha Version 2.0
25 сен 2025, 14:21
25 сен 2025, 14:21
3af6857
Код
Авторство
О чём код?
import os, sys from random import randint, choice from time import sleep from string import ascii_letters import socket # Создаем серверный сокет server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HEALTH = 100 HEALTH_AI = 100 DamagePlayer = 25 DamageAI = 20 player_input = "" Chance_to_heal = 75 #Step_First_Player = True pass_to_move_player = 0 pass_to_move_enemy = 1 Chance_to_strike = 10 word_commands = [["attack"], ["protect"], ["boost"]] while (game_type:=input("Choose game type:\n0 - with AI(only)\n1 - with IP player(multiplayer)\n Your choose: ")) not in "10": ... def cyber_print(string): flags = [randint(5, 20) for _ in range(len(string))] while any(flags): temp = "".join(string[i] if not flags[i] else choice(ascii_letters) for i in range(len(string))) flags = [i-1 if i>0 else 0 for i in flags] print(f"\r{temp}", end="") sleep(0.1) print(f"\r{string}") def Player(player_input) -> cyber_print: global DamagePlayer global HEALTH global HEALTH_AI global pass_to_move_player global pass_to_move_enemy global Step_First_Player if player_input in word_commands[0]: pass_to_move_player = 1 if randint(0, 5): damage = DamagePlayer + randint(-Chance_to_strike, Chance_to_strike) HEALTH_AI -= damage cyber_print(f"Completed attack. You take damage: {damage}. Health enemy system {HEALTH_AI}") else: cyber_print(f"You fail attack. You get system ddos-attack, but system ignoring...") elif player_input in word_commands[1]: pass_to_move_player += 2 if randint(0, 5): HEALTH += randint(Chance_to_heal%Chance_to_heal, Chance_to_heal%(Chance_to_heal // 2)) cyber_print(f"Completed protect. State your system: {HEALTH}. You pass next step...") else: cyber_print(f"You fail protect. You get system ddos-cyber secure, but system ignoring...") elif player_input in word_commands[2]: pass_to_move_player += 3 if randint(0, 5): DamagePlayer += randint(1, Chance_to_strike) cyber_print(f"Completed boosted damage. Your next damage attack is {DamagePlayer}. You get move late {pass_to_move_player-1} enemy moves") else: cyber_print(f"You fail boost. You get boost attack system, but system ignoring...") #else: #cyber_print(f"You fail command. You get command {player_input}, but system ignoring...") def Enemy(): #Функция противника AI global HEALTH global HEALTH_AI global DamageAI global pass_to_move_player global pass_to_move_enemy type_move = randint(0, 2) if type_move == 0: damage = DamageAI + randint(-Chance_to_strike, Chance_to_strike) HEALTH -= damage cyber_print(f"Enemy Attack for you. His take damage {damage}. Your health is {HEALTH}! Next move...") pass_to_move_enemy = 1 elif type_move == 1: HEALTH_AI += randint(Chance_to_heal % Chance_to_heal, Chance_to_heal%(Chance_to_heal // 2)) pass_to_move_enemy += 2 cyber_print(f"Enemy protected. State his system: {HEALTH_AI}. You pass next step...") elif type_move == 2: DamageAI += randint(1, Chance_to_strike) pass_to_move_enemy += 3 cyber_print(f"Completed boosted damage. Enemies next damage attack is {DamageAI}") def get_local_ip(): hostname = socket.gethostname() local_ip = socket.gethostbyname(hostname) return local_ip os.system("clear") cyber_print(f"Your IP-adress, use for connect other players: {get_local_ip()}") if __name__ == "__main__": while True: if game_type=="0": try: if pass_to_move_player==0 and pass_to_move_enemy>0: player_input = input("Enter command (q - to exit) ").lower() Player(player_input) pass_to_move_enemy -= 1 sleep(3) os.system("clear") elif pass_to_move_player>0: Enemy() pass_to_move_player -= 1 if player_input in ['q','quit','exit']: print("You exit from game... Shutdown cyber system") break if HEALTH <= 0: cyber_print("Your system is failed. Data files is deleted...") break elif HEALTH_AI <= 0: cyber_print("You give the enemy data files and destroy enemy system. Good...") break except Exception: print("Ваше значение не является командой")