diff --git a/cat.c b/cat.c index 1be1c6d..e3562cb 100644 --- a/cat.c +++ b/cat.c @@ -5,8 +5,10 @@ #include #include #include +#include int main(int argc,char *argv[]) -{; +{ + if(argc==1) { read_from_stdin(); return 0; diff --git a/readme.md b/readme.md index d9c69ad..6e5a0d3 100644 --- a/readme.md +++ b/readme.md @@ -1,357 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json; -using System.IO; - -namespace PokemonMUD -{ - class Program - { - static void Main(string[] args) - { - Game game = new Game(); - game.Run(); - } - } - - class Game - { - private List players = new List(); - private Dictionary areas = new Dictionary(); - private Random random = new Random(); - private const string SaveFile = "playerdata.json"; - - public Game() - { - InitializeAreas(); - InitializePlayer(); - } - - private void InitializeAreas() - { - // Cities with healing centers - Area cerulean = new Area("Cerulean City", "A bustling city with a gym and healing center.", hasHealingCenter: true); - Area vermilion = new Area("Vermilion City", "A port city with a gym and healing center.", hasHealingCenter: true); - - // Adjacent areas with unique creatures - Area ceruleanFields = new Area("Cerulean Fields", "Grassy fields with unique creatures.", creatures: new List - { - new Creature("Pidgey", 50, 10), - new Creature("Oddish", 45, 8) - }); - Area vermilionCoast = new Area("Vermilion Coast", "Sandy shores with unique creatures.", creatures: new List - { - new Creature("Krabby", 55, 12), - new Creature("Tentacool", 50, 9) - }); - - // Connect areas - cerulean.Connections.Add(ceruleanFields); - ceruleanFields.Connections.Add(cerulean); - vermilion.Connections.Add(vermilionCoast); - vermilionCoast.Connections.Add(vermilion); - - areas.Add("Cerulean City", cerulean); - areas.Add("Vermilion City", vermilion); - areas.Add("Cerulean Fields", ceruleanFields); - areas.Add("Vermilion Coast", vermilionCoast); - - // Add masters - cerulean.HasMaster = true; - vermilion.HasMaster = true; - - // Add store items directly to the lists - cerulean.StoreItems.AddRange(new List { new Item("Potion", 10, 20), new Item("Super Potion", 20, 50) }); - vermilion.StoreItems.AddRange(new List { new Item("Potion", 10, 20), new Item("Antidote", 5, 10) }); - } - - private void InitializePlayer() - { - if (File.Exists(SaveFile)) - { - string json = File.ReadAllText(SaveFile); - var savedPlayers = JsonSerializer.Deserialize>(json); - foreach (var data in savedPlayers) - { - Player player = new Player(data.Name, areas[data.CurrentArea]); - player.Keys.AddRange(data.Keys); - player.Money = data.Money; - player.Inventory.AddRange(data.Inventory.Select(i => new Item(i.Name, i.Effect, i.Price))); - player.OwnedCreatures.AddRange(data.OwnedCreatures.Select(c => new Creature(c.Name, c.MaxHealth, c.Attack) { Health = c.Health })); - players.Add(player); - } - Console.WriteLine("Loaded saved player data."); - } - else - { - Console.Write("Enter your player name: "); - string name = Console.ReadLine(); - Player player = new Player(name, areas["Cerulean City"]); - players.Add(player); - } - } - - private void SavePlayerData() - { - var playerData = players.Select(p => new PlayerData - { - Name = p.Name, - CurrentArea = p.CurrentArea.Name, - Keys = p.Keys, - Money = p.Money, - Inventory = p.Inventory.Select(i => new ItemData { Name = i.Name, Effect = i.Effect, Price = i.Price }).ToList(), - OwnedCreatures = p.OwnedCreatures.Select(c => new CreatureData { Name = c.Name, Health = c.Health, MaxHealth = c.MaxHealth, Attack = c.Attack }).ToList() - }).ToList(); - string json = JsonSerializer.Serialize(playerData, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(SaveFile, json); - Console.WriteLine("Player data saved."); - } - - public void Run() - { - while (true) - { - Player currentPlayer = players[0]; // Simplified: single player for console - Console.WriteLine($"\nYou are in {currentPlayer.CurrentArea.Name}: {currentPlayer.CurrentArea.Description}"); - Console.WriteLine("Commands: move [area], talk, heal, challenge [player], buy [item], who, quit"); - Console.Write("Enter command: "); - string[] input = Console.ReadLine().ToLower().Split(' ', 2); - string command = input[0]; - string argument = input.Length > 1 ? input[1] : ""; - - try - { - switch (command) - { - case "move": - MovePlayer(currentPlayer, argument); - break; - case "talk": - TalkToMaster(currentPlayer); - break; - case "heal": - HealCreatures(currentPlayer); - break; - case "challenge": - ChallengePlayer(currentPlayer, argument); - break; - case "buy": - BuyItem(currentPlayer, argument); - break; - case "who": - ShowWhoList(); - break; - case "quit": - SavePlayerData(); - return; - default: - Console.WriteLine("Unknown command."); - break; - } - } - catch (Exception ex) - { - Console.WriteLine($"Error: {ex.Message}"); - } - } - } - - private void MovePlayer(Player player, string areaName) - { - Area targetArea = player.CurrentArea.Connections.Find(a => a.Name.ToLower() == areaName.ToLower()); - if (targetArea == null) - throw new Exception("Cannot move there."); - player.CurrentArea = targetArea; - EncounterWildCreature(player); - } - - private void EncounterWildCreature(Player player) - { - if (player.CurrentArea.Creatures.Count > 0 && random.Next(0, 100) < 30) // 30% chance - { - Creature wild = player.CurrentArea.Creatures[random.Next(player.CurrentArea.Creatures.Count)]; - Console.WriteLine($"A wild {wild.Name} appears!"); - Battle(player, wild); - } - } - - private void TalkToMaster(Player player) - { - if (!player.CurrentArea.HasMaster) - throw new Exception("No master here."); - if (!player.Keys.Contains(player.CurrentArea.Name)) - { - player.Keys.Add(player.CurrentArea.Name); - Console.WriteLine($"You received the {player.CurrentArea.Name} key!"); - } - else - { - Console.WriteLine("You already have this city's key."); - } - } - - private void HealCreatures(Player player) - { - if (!player.CurrentArea.HasHealingCenter) - throw new Exception("No healing center here."); - foreach (var creature in player.OwnedCreatures) - { - creature.Health = creature.MaxHealth; - Console.WriteLine($"{creature.Name} was fully healed!"); - } - } - - private void ChallengePlayer(Player player, string targetName) - { - Player target = players.Find(p => p.Name.ToLower() == targetName.ToLower() && p.CurrentArea == player.CurrentArea); - if (target == null) - throw new Exception("Player not found or not in this area."); - if (target == player) - throw new Exception("Cannot challenge yourself."); - if (!player.OwnedCreatures.Any(c => c.Health > 0)) - throw new Exception("Your creatures are too weak to battle."); - Console.WriteLine($"Challenging {target.Name}!"); - Battle(player, target.OwnedCreatures.First(c => c.Health > 0)); // Battle with first healthy creature - } - - private void Battle(Player player, Creature opponent) - { - Creature playerCreature = player.OwnedCreatures.FirstOrDefault(c => c.Health > 0); - if (playerCreature == null) - throw new Exception("All your creatures have fainted!"); - Console.WriteLine($"{playerCreature.Name} vs {opponent.Name}!"); - - while (playerCreature.Health > 0 && opponent.Health > 0) - { - opponent.Health -= playerCreature.Attack; - Console.WriteLine($"{playerCreature.Name} deals {playerCreature.Attack} damage to {opponent.Name}. {opponent.Name} HP: {opponent.Health}"); - if (opponent.Health <= 0) - break; - playerCreature.Health -= opponent.Attack; - Console.WriteLine($"{opponent.Name} deals {opponent.Attack} damage to {playerCreature.Name}. {playerCreature.Name} HP: {playerCreature.Health}"); - } - - if (playerCreature.Health <= 0) - Console.WriteLine($"{playerCreature.Name} fainted! You lose the battle."); - else - Console.WriteLine($"{opponent.Name} fainted! You win the battle."); - } - - private void BuyItem(Player player, string itemName) - { - if (player.CurrentArea.StoreItems.Count == 0) - throw new Exception("No store here."); - Item item = player.CurrentArea.StoreItems.Find(i => i.Name.ToLower() == itemName.ToLower()); - if (item == null) - throw new Exception("Item not found."); - if (player.Money < item.Price) - throw new Exception("Not enough money."); - player.Money -= item.Price; - player.Inventory.Add(item); - Console.WriteLine($"Bought {item.Name} for {item.Price} coins. Money left: {player.Money}"); - } - - private void ShowWhoList() - { - Console.WriteLine("Players online:"); - foreach (Player p in players) - { - Console.WriteLine($"{p.Name} in {p.CurrentArea.Name} with {p.Keys.Count} key(s): {string.Join(", ", p.Keys)}"); - } - } - } - - class Player - { - public string Name { get; } - public Area CurrentArea { get; set; } - public List Keys { get; } = new List(); - public List OwnedCreatures { get; } = new List(); - public List Inventory { get; } = new List(); - public int Money { get; set; } = 100; - - public Player(string name, Area startingArea) - { - Name = name; - CurrentArea = startingArea; - OwnedCreatures.Add(new Creature("Bulbasaur", 100, 15)); - } - } - - class Area - { - public string Name { get; } - public string Description { get; } - public List Connections { get; } = new List(); - public bool HasMaster { get; set; } - public bool HasHealingCenter { get; set; } - public List Creatures { get; } = new List(); - public List StoreItems { get; set; } = new List(); // Changed to writable property - - public Area(string name, string description, bool hasHealingCenter = false, List creatures = null) - { - Name = name; - Description = description; - HasHealingCenter = hasHealingCenter; - if (creatures != null) - Creatures.AddRange(creatures); - } - } - - class Creature - { - public string Name { get; } - public int Health { get; set; } - public int MaxHealth { get; } - public int Attack { get; } - - public Creature(string name, int health, int attack) - { - Name = name; - Health = health; - MaxHealth = health; - Attack = attack; - } - } - - class Item - { - public string Name { get; } - public int Price { get; } - public int Effect { get; } - - public Item(string name, int effect, int price) - { - Name = name; - Effect = effect; - Price = price; - } - } - - // Data classes for JSON serialization - class PlayerData - { - public string Name { get; set; } - public string CurrentArea { get; set; } - public List Keys { get; set; } - public int Money { get; set; } - public List Inventory { get; set; } - public List OwnedCreatures { get; set; } - } - - class ItemData - { - public string Name { get; set; } - public int Effect { get; set; } - public int Price { get; set; } - } - - class CreatureData - { - public string Name { get; set; } - public int Health { get; set; } - public int MaxHealth { get; set; } - public int Attack { get; set; } - } -} \ No newline at end of file +##patricus utils +version: 3.4 +simple utilities +##cmpsize +cmpsize file1 optional_file2 +how big is a file. +##cat +POSIX like cat inplementation \ No newline at end of file diff --git a/utils.h b/utils.h index 8c70d86..9c8c9a7 100644 --- a/utils.h +++ b/utils.h @@ -1,3 +1,4 @@ +#include #ifndef _WIN64 #error "this version is windows only" -#endif +#endif \ No newline at end of file diff --git a/version.h b/version.h new file mode 100644 index 0000000..49d5957 --- /dev/null +++ b/version.h @@ -0,0 +1 @@ +0.1 diff --git a/version.hcode b/version.hcode new file mode 100644 index 0000000..9e45084 --- /dev/null +++ b/version.hcode @@ -0,0 +1 @@ +0.1 meow.c