Skip to content

Commit

Permalink
Added text adventure..
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown authored and Unknown committed Oct 26, 2018
1 parent ba43156 commit 6dcf805
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@ call adler32 : WELCOME, welcomeLength -> hash;

## Testing

[Test script](test_script.md)
[Test script](test_script.md)

## Other scripts

[Text adventure](text_adventure.md)
124 changes: 124 additions & 0 deletions text_adventure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
[Home](https://puckowski.github.io/concert/)

# Text adventure

Demonstration of some Concert Programming Language concepts.

## Code

```cpp
import math;
import string;
import io;

struct "room";
string description;
string north;
string east;
string south;
string west;
struct;

new "room" "r1";
new "room" "r2";
new "room" "r3";

r1.description = "Lobby";
r1.north = "r2";
r1.east = "";
r1.south = "";
r1.west = "";

r2.description = "Hallway";
r2.north = "r3";
r2.east = "";
r2.south = "r1";
r2.west = "";

r3.description = "Study";
r3.north = "";
r3.east = "";
r3.south = "r2";
r3.west = "";

string currentRoom = "r1";

function printRooms : string as forRoom;
println "You are in: ", forRoom.description;
print "Rooms available: ";

if forRoom.north != "";
print "north ";
end;
if forRoom.east != "";
print "east ";
end;
if forRoom.south != "";
print "south ";
end;
if forRoom.west != "";
print "west ";
end;

println "";
return;

function goToRoom : string as currRoom, string as exitRoom;
string newRoom;

call to_lower_case : exitRoom -> exitRoom;

if exitRoom == "north";
if currRoom.north != "";
newRoom = currRoom.north;
end;
end;

if exitRoom == "east";
if currRoom.east != "";
newRoom = currRoom.east;
end;
end;

if exitRoom == "south";
if currRoom.south != "";
newRoom = currRoom.south;
end;
end;

if exitRoom == "west";
if currRoom.west != "";
newRoom = currRoom.west;
end;
end;
return newRoom;

string input;

println "Welcome to Concert Simple Text Adventure!";
println "Type \"help\" for help.";

# Game loop
while input != "exit";
call printRooms : currentRoom;

println "Go where?";
print "> ";
readln input;
if input != "";
if input == "help";
println "Type name of exit to go to new room.";
else;
string saveOldRoom = currentRoom;
call goToRoom : currentRoom, input -> currentRoom;
if currentRoom == "";
currentRoom = saveOldRoom;
end;
end;
end;
end;

println "Goodbye!";
```

0 comments on commit 6dcf805

Please sign in to comment.