Skip to content

Instantly share code, notes, and snippets.

@sandrockcstm
Created September 13, 2017 22:44
Show Gist options
  • Save sandrockcstm/b245f1ef36218acdadde2ee13e91e7d4 to your computer and use it in GitHub Desktop.
Save sandrockcstm/b245f1ef36218acdadde2ee13e91e7d4 to your computer and use it in GitHub Desktop.
Console RPG created by sandrockcstm - https://repl.it/JMY2/247
using System;
using System.Collections;
namespace Bestiary
{
public class Monster
{
public string Name { get; set; }
public double Hp { get; set; }
public double Atk { get; set; }
public double Def { get; set; }
public Monster()
{
Name = "Default";
Hp = 0;
Atk = 0;
Def = 0;
}
}
public class Slime : Monster
{
public void makeSlime()
{
Name = "Slime";
Hp = 15;
Atk = 1;
Def = 10;
}
}
public class Revenant : Monster
{
public void makeRevenant()
{
Name = "Revenant";
Hp = 15;
Atk = 10;
Def = 20;
}
}
}
using System;
using System.Collections;
using Bestiary;
using PlayerStats;
//Battle system is contained in this namespace.
namespace BattleSpace
{
class Combat
{
public string playerName;
public double playerHp;
public double playerAtk;
public double playerDef;
public string monsterName;
public double monsterHp;
public double monsterAtk;
public double monsterDef;
public double dmgDealt;
//public int miss;
//public int def;
public double dmgReduct (double atk, double def, string attacker)
{
int miss;
if(def > 50)
{
miss = (int)def - 50;
def = 50;
}
else
{
def = def;
miss = 0;
}
//Console.WriteLine("def is " + def);
def = def / 100;
//Console.WriteLine("def is " + def);
def = 1 - def;
//Console.WriteLine("atk is " + atk + " def is " + def);
double workingDmg = atk * def;
workingDmg = Math.Ceiling(workingDmg);
//Console.WriteLine("workingDmg after Math.Ceiling is " + workingDmg);
Random rnd = new Random();
int seed = rnd.Next(1, 100);
//Console.WriteLine("Seed is " + seed);
if(seed <= miss)
{
Console.WriteLine("Miss!");
return 0;
}
else
{
//Console.WriteLine("workingDmg is " + workingDmg);
Console.WriteLine(attacker + " deals " + workingDmg + " damage!");
return workingDmg;
}
}
public bool runCombat (string playerName, string monsterName, double monsterHp, double monsterAtk, double monsterDef) //Begins combat.
{
Player p = new Player();
this.playerName = playerName;
playerDef = p.PlayerDef;
playerHp = p.PlayerHp;
playerAtk = p.PlayerAtk;
Console.WriteLine("You encountered a " + monsterName + "!");
//Console.WriteLine("monsterDef is " + monsterDef);
while(playerHp > 0 && monsterHp > 0)
{
Console.WriteLine(playerName + " has " + playerHp + " HP");
Console.WriteLine(monsterName + " has " + monsterHp + " HP");
Console.WriteLine("What will you do? ATTACK or RUN?");
string c = Console.ReadLine();
c = c.ToUpper();
switch(c)
{
case "ATTACK":
dmgDealt = dmgReduct(playerAtk, monsterDef, playerName);
monsterHp -= dmgDealt;
this.dmgDealt = dmgReduct(monsterAtk, playerDef, monsterName);
playerHp -= dmgDealt;
break;
case "RUN":
playerHp -= monsterAtk;
Console.WriteLine(monsterName + " does " + monsterAtk + " damage! There's no escape!");
break;
default:
Console.WriteLine("Not a valid entry");
break;
}
}
if (playerHp > 0)
{
return true;
}
else if (playerHp <= 0)
{
return false;
}
else
{
throw new System.Exception("Value of playerStats is not valid");
}
}
}
}
using System;
using System.Collections;
using BattleSpace;
using PlayerStats;
using StorySpace;
static class Program
{
static void Main(string[] args)
{
Player p = new Player();
Console.WriteLine("What is your name?");
p.PlayerName = Console.ReadLine(); //Sets the player character's name
Story s = new Story(); //Instantiates the story class so that it can //be called.
if(s.Act1(p.PlayerName))
{
Console.WriteLine("You are victorious!");
}
else
{
Console.WriteLine("Game Over!");
}
}
}
using System;
using System.Collections;
namespace PlayerStats
{
class Player
{
public string PlayerName { get; set; } = "Default";
public double PlayerHp { get; set; } = 25;
public double PlayerAtk { get; set; } = 10;
public double PlayerDef { get; set; } = 5;
}
}
using System;
using System.Collections;
using BattleSpace;
using Bestiary;
using PlayerStats;
namespace StorySpace
{
class Story
{
private string playerName;
public void NextLine(string text)
{
Console.Write(text);
Console.ReadLine();
}
public bool Act1(string playerName)
{
this.playerName = playerName;
NextLine("You awake in a dark corridor... how did you get here?");
NextLine("It smells like darkness in here. Nothing but mold and mildew and... is that rotten flesh you smell?");
NextLine("You try not to think about it.");
Console.WriteLine("You should try to find your way out of here. Who knows if anyone will ever find you, or why you were brought here in the first place. You can CALL for help, SEARCH the area for supplies, EXPLORE the room, or WAIT.");
string c = "Default";
Combat combat = new Combat();
bool torch = false;
bool flint = false;
int waitTimer = 0;
bool i = true;
Slime slime = new Slime();
slime.makeSlime();
while(i)
{
c = Console.ReadLine();
c = c.ToUpper();
switch(c)
{
case "INVENTORY":
if(torch && flint)
{
Console.WriteLine("You are carrying an unlit torch, and a flint with which to light it...");
break;
}
else if(torch)
{
Console.WriteLine("You are carrying an unlit torch.");
break;
}
else if (flint)
{
Console.WriteLine("You found a piece of flint, which could light something for you.");
break;
}
else
{
Console.WriteLine("Your pockets are empty.");
break;
}
case "CALL":
Console.WriteLine("You let out a boisterous call, which echoes through the room. Your ears ring with your own call. You wait a minute or two but hear no response.");
break;
case "SEARCH":
Console.WriteLine("You move around on your hands and knees, looking for something to help you. You find a TORCH. If you can figure out how to light it, you might be able to see a way out.");
torch = true;
break;
case "EXPLORE":
Console.WriteLine("You search along the walls of the room for something, anything, to aid you. You find the DOOR, but it will neither budge nor open. You search around on the floor and find some FLINT. If you can find a TORCH, you may be able to see more detail in the room and find a way out.");
flint = true;
break;
case "WAIT":
if(waitTimer >= 2)
{
Console.Clear();
Console.WriteLine("Something drips on you from the ceiling!");
if(combat.runCombat(playerName, slime.Name, slime.Hp, slime.Atk, slime.Def))
{
Console.Clear();
Console.WriteLine("The Slime is gone. Probably best to get out of here quick.");
break;
}
else
{
return false;
//break;
}
}
else if(waitTimer < 3)
{
Console.WriteLine("You wait for a long time, but nothing happens.");
waitTimer++;
}
else
{
throw new Exception("waitTimer value invalid");
/*break;
waitTimer += waitTimer;*/
}
break;
case "TORCH":
{
if (flint)
{
Console.WriteLine("You manage to light a flame to illuminate the room. To call it a dungeon would be generous. It's a small room with stone walls and an uneven stone floor. More of a cave-closet if anything. You see an uneven section of the wall and realize that there is a hidden SWITCH built into the wall. Perhaps you should push it?");
break;
}
else if (torch)
{
Console.WriteLine("Without some way to light this it's just a useless stick.");
break;
}
else
{
Console.WriteLine("I don't understand what you're saying. Your options are CALL, SEARCH, EXPLORE, or WAIT.");
break;
}
}
case "SWITCH":
{
if(flint && torch)
{
Console.WriteLine("You push the hidden switch, the door opens!");
return true;
}
else
{
Console.WriteLine("I don't understand what you're saying. Your options are CALL, SEARCH, EXPLORE, OR WAIT.");
break;
}
}
default:
{
Console.WriteLine("I don't understand what you're saying. Your options are CALL, SEARCH, EXPLORE, or WAIT.");
break;
}
}
}
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment