added readme IDK why my test game was instead of it
This commit is contained in:
parent
6741cf3115
commit
26b2de0d67
5 changed files with 15 additions and 359 deletions
4
cat.c
4
cat.c
|
@ -5,8 +5,10 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include<sys/stat.h>
|
#include<sys/stat.h>
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
|
#include<windows.h>
|
||||||
int main(int argc,char *argv[])
|
int main(int argc,char *argv[])
|
||||||
{;
|
{
|
||||||
|
|
||||||
if(argc==1) {
|
if(argc==1) {
|
||||||
read_from_stdin();
|
read_from_stdin();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
365
readme.md
365
readme.md
|
@ -1,357 +1,8 @@
|
||||||
using System;
|
##patricus utils
|
||||||
using System.Collections.Generic;
|
version: 3.4
|
||||||
using System.Linq;
|
simple utilities
|
||||||
using System.Text.Json;
|
##cmpsize
|
||||||
using System.IO;
|
cmpsize file1 optional_file2
|
||||||
|
how big is a file.
|
||||||
namespace PokemonMUD
|
##cat
|
||||||
{
|
POSIX like cat inplementation
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
Game game = new Game();
|
|
||||||
game.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Game
|
|
||||||
{
|
|
||||||
private List<Player> players = new List<Player>();
|
|
||||||
private Dictionary<string, Area> areas = new Dictionary<string, Area>();
|
|
||||||
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<Creature>
|
|
||||||
{
|
|
||||||
new Creature("Pidgey", 50, 10),
|
|
||||||
new Creature("Oddish", 45, 8)
|
|
||||||
});
|
|
||||||
Area vermilionCoast = new Area("Vermilion Coast", "Sandy shores with unique creatures.", creatures: new List<Creature>
|
|
||||||
{
|
|
||||||
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<Item> { new Item("Potion", 10, 20), new Item("Super Potion", 20, 50) });
|
|
||||||
vermilion.StoreItems.AddRange(new List<Item> { 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<List<PlayerData>>(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<string> Keys { get; } = new List<string>();
|
|
||||||
public List<Creature> OwnedCreatures { get; } = new List<Creature>();
|
|
||||||
public List<Item> Inventory { get; } = new List<Item>();
|
|
||||||
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<Area> Connections { get; } = new List<Area>();
|
|
||||||
public bool HasMaster { get; set; }
|
|
||||||
public bool HasHealingCenter { get; set; }
|
|
||||||
public List<Creature> Creatures { get; } = new List<Creature>();
|
|
||||||
public List<Item> StoreItems { get; set; } = new List<Item>(); // Changed to writable property
|
|
||||||
|
|
||||||
public Area(string name, string description, bool hasHealingCenter = false, List<Creature> 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<string> Keys { get; set; }
|
|
||||||
public int Money { get; set; }
|
|
||||||
public List<ItemData> Inventory { get; set; }
|
|
||||||
public List<CreatureData> 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; }
|
|
||||||
}
|
|
||||||
}
|
|
1
utils.h
1
utils.h
|
@ -1,3 +1,4 @@
|
||||||
|
#include<stdbool.h>
|
||||||
#ifndef _WIN64
|
#ifndef _WIN64
|
||||||
#error "this version is windows only"
|
#error "this version is windows only"
|
||||||
#endif
|
#endif
|
1
version.h
Normal file
1
version.h
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0.1
|
1
version.hcode
Normal file
1
version.hcode
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0.1 meow.c
|
Loading…
Add table
Add a link
Reference in a new issue