forked from cfrantzidis/DungeonExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cs
More file actions
109 lines (97 loc) · 3.9 KB
/
Copy pathGame.cs
File metadata and controls
109 lines (97 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Media;
namespace DungeonExplorer
{
@@ -10,17 +9,102 @@ internal class Game
public Game()
{
// Initialize the game with one room and one player
// Initialize rooms
Room room1 = new Room("A damp, cold room with seemingly little light... You can see a light towards the South.");
Room room2 = new Room("An old prison cell with a monster and exit tunnel to the East.");
Room room3 = new Room("A portal chamber containing a treasure chest.");
// Connect rooms
room1.South = room2;
room2.North = room1;
room3.West = room2;
room2.East = room3;
// Create Player
Console.Write("Enter player name: ");
string playerName = Console.ReadLine()?.Trim();
if (string.IsNullOrWhiteSpace(playerName))
{
playerName = "Adventurer";
}
player = new Player(playerName, 100);
player.EnterRoom(room1);
currentRoom = room1;
// Add items in rooms
room1.CreateItem("Stick");
room3.CreateItem("Gold");
}
public void Start()
{
// Change the playing logic into true and populate the while loop
bool playing = false;
while (playing)
while (player.Health > 0)
{
// Code your playing logic here
Console.WriteLine("\nChoose an action:");
Console.WriteLine("1 - View room description");
Console.WriteLine("2 - Move to another room");
Console.WriteLine("3 - View player stats");
Console.WriteLine("4 - Pick up an item");
Console.WriteLine("5 - Exit game");
string action = Console.ReadLine()?.Trim();
if (action == "1")
{
Console.WriteLine(player.CurrentRoom.GetDescription());
}
else if (action == "2")
{
Console.WriteLine("Which way do you want to go?");
Console.WriteLine("1 - North");
Console.WriteLine("2 - East");
Console.WriteLine("3 - South");
Console.WriteLine("4 - West");
string direction = Console.ReadLine()?.Trim();
switch (direction)
{
case "1": player.Move("North"); break;
case "2": player.Move("East"); break;
case "3": player.Move("South"); break;
case "4": player.Move("West"); break;
default: Console.WriteLine("Invalid direction! Choose 1, 2, 3 or 4."); break;
}
}
else if (action == "3")
{
player.DisplayStatus();
}
else if (action == "4")
{
if (!string.IsNullOrEmpty(player.CurrentRoom.RoomItem))
{
player.PickUpItem(player.CurrentRoom.RoomItem);
Console.WriteLine($"You picked up: {player.CurrentRoom.RoomItem}");
player.CurrentRoom.RemoveItem(); // Proper removal
}
else
{
Console.WriteLine("There's nothing to pick up.");
}
}
else if (action == "5")
{
Console.WriteLine("Exiting the game...");
break;
}
else
{
Console.WriteLine("Invalid option. Choose between options 1-5.");
}
}
Console.WriteLine("Game over.");
}
}