Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A Sea of Troubles: A Text Adventure Game\n",
"This is a game I designed for my Shakespeare class.\n",
"A note on implementation: I'm offering the software I wrote to make this work for free to anyone who wants to explore this form. Users can simply change the text and structure as befits them. The structure is that of a directed graph (in the mathematical sense). Each text block is a \"node\" and each logical path that may be taken by a user is an \"edge\". Logical loops are a possibility.\n",
"\n",
"## Reflection\n",
"The goal of this project is to explore several themes that tend to come up around Shakespeare and Shakespeare adaptations.\n",
"Though this is an unessay, the result is still a sort of \"loose salley of the mind\", just in a different way from a traditional essay.\n",
"\n",
"**Here's what to look out for:**\n",
"1. The idea of adaptation itself - How do we make an old play relevant? What to we risk when we do this? We have discussed numerous adaptations in class, so I have chosen to explore this further.\n",
"\n",
"2. Intergenerational relations and power dynamics - This theme is prevalant in Hamlet and shows up in numerous other plays. I hope to consider the idea of being silenced or cast aside.\n",
"\n",
"3. Lack of agency and inaction - This is a function of the medium. The whole game really consists of walking down a single hallway and doesn't really give you meaningful choices besides how quickly to do so.\n",
"\n",
"\n",
"\n",
"## Gameplay\n",
"To advance in the game, select an option from the list of options in square brackets (These things --> \\[\\]). You can do this by typing the first word in the brackets (usually capitalized) of the choice you've selected and pressing enter.\n",
"\n",
"Currently, the number of particularly long or interesting interactions is small. I'm working on it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"import time\n",
"\n",
"class Room:\n",
" def __init__(self, Text):\n",
" #The text\n",
" self.text = re.sub(r\"{|}\", \"\", Text)\n",
"\n",
" #Current room and paths to next rooms\n",
" self.roomNum = re.search(r\"[0-9]*~\", self.text).group()[:-1]\n",
" self.nextMatch = re.search(r\"~([0-9]*,)*[0-9]*\", self.text)\n",
" self.nextList = self.nextMatch.group()[1:].split(',')\n",
"\n",
" self.keywordList = re.findall(r\"\\[[A-Z]* \", self.text)\n",
" self.keywords = [i[1:-1] for i in self.keywordList]\n",
"\n",
" def display(self):\n",
" return self.text\n",
"\n",
" def __eq__(self, other):\n",
" if self.roomNum == other.roomNum:\n",
" True\n",
" else:\n",
" False\n",
"\n",
"class Essay:\n",
" def __init__(self, Text):\n",
" self.TextList = re.split(r\"}\\D*{\", Text)\n",
" self.RoomList = [Room(i) for i in self.TextList]\n",
" self.current = self.RoomList[0]\n",
"\n",
" def setCurrentRoom(self, room):\n",
" self.current = room\n",
"\n",
" def query(self, currentRoom):\n",
" Answer = input(\"> \")\n",
" if Answer in self.current.keywords:\n",
" choiceNum = self.current.keywords.index(Answer)\n",
" for i in self.RoomList:\n",
" try:\n",
" if i.roomNum == str(self.current.nextList[choiceNum]):\n",
" self.setCurrentRoom(i)\n",
" break\n",
" except:\n",
" pass\n",
" self.begin()\n",
" else:\n",
" slowprint(\"You can't \" + Answer)\n",
" self.query(self.current)\n",
"\n",
" def begin(self):\n",
" slowprint(self.current.display())\n",
" self.query(self.current)\n",
"\n",
"def slowprint(S):\n",
" for i in S:\n",
" print(i, end = \"\")\n",
" time.sleep(0.05)\n",
" \n",
"E=open(r'GameText.txt', 'r')\n",
"MyPaper = E.read()\n",
"\n",
"MyEssay = Essay(MyPaper)\n",
"MyEssay.begin()\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}