@PixelBitez/

Dragon Eye RPG

C#

This is an RPG made for the AI competition. The game is intelligent by generating a story and determining enemy moves.

fork
loading
Files
  • main.cs
  • main.exe
  • wowree.JPG
main.cs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
using System;
using System.Collections.Generic;

class Item{
  public string ItemType;
  public string ItemName;
  public int ItemLevel;
  public int Damage;
  public int Value;
}

class Enemy{
  public int Level;
  public int Health;
  public string Race;
  public int Damage;
  public int Defense;
}

class Player{
  public string Name;
  public int Level;
  public int Health;
  public string Race;
  public int Damage;
  public int GP;
  public int Defense;
  public int xp;
  public List<Item> Inventory = new List<Item>();
}

class MainClass {
  public static void Main (string[] args) {
    string[] Places = {"Griglagg", "Ravenwood", "Dunwich", "Greenwood"};
    Player MainPlayer = MakePlayer();
    Item newStick = new Item();
    newStick.ItemType = "Weapon";
    newStick.ItemName = "Stick";
    newStick.Value = 0;
    newStick.Damage = 5;
    newStick.ItemLevel = 1;
    MainPlayer.Inventory.Add(newStick);
    RenderInventory(MainPlayer);
    Random rnd = new Random();
    Console.WriteLine("Your adventure begins..");
    while (true){
      if (MainPlayer.xp > MainPlayer.Level*500){
        MainPlayer.xp = 0;
        MainPlayer.Damage += rnd.Next(5, 11);
        MainPlayer.Defense += rnd.Next(5, 11);
        Console.WriteLine(MainPlayer.Name + " leveled up!");
        MainPlayer.Level++;
      }
      System.Threading.Thread.Sleep(1000);
      int travel = rnd.Next(0,5);
      if (travel == 1){
        string place = Places[rnd.Next(0,Places.Length)];
        Console.WriteLine("You travel to " + place);
      }else{
        int action = rnd.Next(0,4); // 0 combat, 1 quest, 2 someone asks for gold, 3 find something
        switch (action){
          case 0:
            Combat(MainPlayer);
            break;
          case 1:
            Console.WriteLine("A fellow " + MainPlayer.Race + " asks " + MainPlayer.Name + " for 10 Gold Pieces, do you accept?\r1. Yes\r2. No");
            string Answer = Console.ReadLine();
            if (Answer == "1"){
              MainPlayer.GP -= 10;
              Console.WriteLine("You gave the " + MainPlayer.Race + " 10 Gold Pieces.");
            }else if (Answer == "2"){
              Console.WriteLine("You refused to give the " + MainPlayer.Race + "Gold Pieces.");
            }else if (Answer != "1" && Answer != "2"){
              Console.WriteLine("You refused to give the " + MainPlayer.Race + "Gold Pieces.");
            }
            break;
          case 2:
            Console.WriteLine("Someone walks up to " + MainPlayer.Name + ", and asks him/her to slay a monster.");
            System.Threading.Thread.Sleep(500);
            if (rnd.Next(0,2) == 1){
              Console.WriteLine(MainPlayer.Name + " accepted the offer.");
              Combat(MainPlayer);
            }else{
              Console.WriteLine(MainPlayer.Name + " declined the offer.");
            }
            break;
          case 3:
            int rItem = rnd.Next(0,2);
            string[] citemsList = {"Potatoe", "Carrot", "Potion", "Spider Eye", "Rope", "Cake", "Jerkey", "somtin special ;)"};
            string[] witemsList = {"Greatsword", "Axe", "Sword", "Knife", "Dagger"};
            if (rItem == 0){
              Item newItem = new Item();
              newItem.ItemName = citemsList[rnd.Next(0,citemsList.Length)];
              newItem.Damage = rnd.Next(MainPlayer.Damage,MainPlayer.Damage+10);
              newItem.ItemLevel = MainPlayer.Level;
              newItem.Value = 0;
              newItem.ItemType = "Food";
              MainPlayer.Inventory.Add(newItem);
              Console.WriteLine("You found a " + newItem.ItemName + ".");
            }else if (rItem == 1){
              Item newItem = new Item();
              newItem.ItemName = witemsList[rnd.Next(0,witemsList.Length)];
              newItem.Damage = rnd.Next(MainPlayer.Damage,MainPlayer.Damage+10);
              newItem.ItemLevel = MainPlayer.Level;
              newItem.Value = 0;
              newItem.ItemType = "Weapon";
              MainPlayer.Inventory.Add(newItem);
              Console.WriteLine("You found a " + newItem.ItemName + ".");
            }
            break;
        }
      }
    }
  }
  public static void Combat(Player defPlr){
    Enemy newEnemy = new Enemy();
    Random rnd = new Random();
    int randomRace = rnd.Next(0,6);
    switch (randomRace){
      case 0:
        newEnemy.Race = "Orc";
        break;
      case 1:
        newEnemy.Race = "Bandit";
        break;
      case 2:
        newEnemy.Race = "Giant";
        break;
      case 3:
        newEnemy.Race = "Dragon";
        break;
      case 4:
        newEnemy.Race = "Elf";
        break;
      case 5:
        newEnemy.Race = "Dwarf";
        break;
    }
    newEnemy.Damage = defPlr.Damage+rnd.Next(-5,6);
    newEnemy.Defense = defPlr.Defense+rnd.Next(-5,6);
    newEnemy.Level = defPlr.Level+rnd.Next(-2,3);
    Console.WriteLine("A level " + newEnemy.Level + " " + newEnemy.Race + " started a fight.");
    newEnemy.Health = 100;
    bool Fighting = true;
    bool Success = false;
    while (Fighting){
      if (newEnemy.Health <= 0){
        Fighting = false;
        Win(defPlr);
      }
      if (defPlr.Health <= 0){
        Fighting = false;
        Lose(defPlr);
      }
      if (Fighting){
        int DefenseVal = 0;
        System.Threading.Thread.Sleep(100);
        Console.WriteLine("Its your turn, you can:\r1. Attack\r2. Defend\r3. Use Item.");
        Console.WriteLine(defPlr.Name + "'s Health: " + defPlr.Health);
        Console.WriteLine(newEnemy.Race + "'s Health: " + newEnemy.Health);
        string plrInput = Console.ReadLine();
        switch (plrInput){
          case "1":
            bool Success1 = false;
            Console.WriteLine("Attack with what?");
            string writeatkItem = Console.ReadLine();
            int itemDamage = 0;
            foreach (Item fItem in defPlr.Inventory){
              if (fItem.ItemName == writeatkItem){
                Success1 = true;
                itemDamage = fItem.Damage;
                Console.WriteLine(defPlr.Name + " attacked enemy " + newEnemy.Race + " with a " + fItem.ItemName + ", the " + newEnemy.Race + " lost " + (itemDamage+defPlr.Damage) + " health.");
              }
            }
            if (Success1){
              Success = true;
              Success1 = false;
              newEnemy.Health -= (defPlr.Damage+itemDamage);
            }
            break;
          case "2":
            Success = true;
            DefenseVal = defPlr.Defense;
            break;
          case "3":
            bool Success2 = false;
            Console.WriteLine("Use what item?");
            string writeuseItem = Console.ReadLine();
            int itemHeal = 0;
            foreach (Item nItem in defPlr.Inventory){
              if (nItem.ItemName == writeuseItem){
                itemHeal = nItem.Damage;
                Console.WriteLine(defPlr.Name + " healed " + itemHeal + " with a " + nItem.ItemName + ".");
                Success2 = true;
              }
            }
            if (Success2){
              defPlr.Health += itemHeal;
              Success = true;
            }
            break;
        }
        System.Threading.Thread.Sleep(100);
        RenderInventory(defPlr);
        System.Threading.Thread.Sleep(100);
        RenderStats(defPlr);
        System.Threading.Thread.Sleep(100);
        if (Success){
          Success = false;
        }else if (Success == false){
          Console.WriteLine("Incorrect input, turn skipped.");
        }
        if (newEnemy.Health < 25){
          int willHeal = rnd.Next(0, 3);
          if (willHeal == 1){
            newEnemy.Health += newEnemy.Defense;
            Console.WriteLine(newEnemy.Race + " healed " + newEnemy.Defense + ".");
          }else{
            if (DefenseVal > 0){
              Console.WriteLine(newEnemy.Race + " attacks.");
              System.Threading.Thread.Sleep(100);
              Console.WriteLine(defPlr.Name + " defends.");
              defPlr.Health -= newEnemy.Damage-DefenseVal;
              DefenseVal = 0;
            }else{
              Console.WriteLine(newEnemy.Race + " attacks, " + defPlr.Name + " loses " + newEnemy.Damage + " health.");
              defPlr.Health -= newEnemy.Damage;
            }
          }
        }
        if (DefenseVal > 0){
          Console.WriteLine(newEnemy.Race + " attacks.");
          System.Threading.Thread.Sleep(100);
          Console.WriteLine(defPlr.Name + " defends.");
          defPlr.Health -= newEnemy.Damage-DefenseVal;
          DefenseVal = 0;
        }else{
          Console.WriteLine(newEnemy.Race + " attacks, " + defPlr.Name + " loses " + newEnemy.Damage + " health.");
          defPlr.Health -= newEnemy.Damage;
        }
      }
    }
  }
  public static Player MakePlayer(){
    Player newPlayer = new Player();
    Console.WriteLine("Welcome to Dragon Eye, a terminal RPG!");
    System.Threading.Thread.Sleep(2000);
    Console.WriteLine("This game was created for the AI competition on repl.it");
    System.Threading.Thread.Sleep(2000);
    Console.WriteLine("---Create your character---");
    Console.Write("Name: ");
    string plrName = Console.ReadLine();
    Console.Write("Race(Dwarf, Human, Giant, etc...): ");
    string plrRace = Console.ReadLine();
    newPlayer.Level = 1;
    newPlayer.Health = 100;
    newPlayer.Damage = 5;
    newPlayer.Defense = 5;
    newPlayer.xp = 0;
    newPlayer.GP = 10;
    newPlayer.Race = plrRace;
    newPlayer.Name = plrName;
    RenderStats(newPlayer);
    return newPlayer;
  }
  public static void RenderStats(Player mainPlr){
    Console.WriteLine("[Damage: " + mainPlr.Damage + "][Level: " + mainPlr.Level + "][Defense: " + mainPlr.Defense + "][xp: " + mainPlr.xp + "][Health: " + mainPlr.Health + "/100][GP: " + mainPlr.GP + "]");
  }
  public static void RenderInventory(Player newPlr){
    string logString = "";
    foreach (var itN in newPlr.Inventory){
      logString = logString + "<" + itN.ItemName + ">";
    }
    Console.WriteLine("---Inventory---");
    Console.WriteLine(logString);
    Console.WriteLine("------");
  }
  public static void Win(Player cdefPlayer){
    Console.WriteLine(cdefPlayer.Name + " won the fight!");
    Random rnd = new Random();
    int xpReward = rnd.Next(1,1000);
    int goldReward = rnd.Next(1,10);
    Console.WriteLine("Rewards: " + xpReward + " xp, " + goldReward + " Gold Peices.");
    cdefPlayer.xp += xpReward;
    cdefPlayer.GP += goldReward;
    cdefPlayer.Health = 100;
  }
  public static void Lose(Player mdefPlayer){
    Console.WriteLine(mdefPlayer.Name + " lost the fight.");
    mdefPlayer.Health = 100;
  }
}