repl.it
@AS4/

Dinoepic

Java

No description

fork
loading
Files
  • Main.java
  • Cards.java
  • Dino.java
  • Example.java
  • Player.java
  • Spaces.java
Main.java
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
import java.util.concurrent.ThreadLocalRandom;//Used for generating random numbers
import java.util.Scanner;//Used for reading the users input.
class Main 
{
  public static void main(String[] args) 
  {
    Scanner scan = new Scanner(System.in);
    System.out.println("Dino-opoly!");//Title
        int valid = 0;//This codes checks until valid doesn't equal 0 so one needs to initialise it.
        while (valid == 0)//The code is repeated until valid doesn't equal 0.
        {
          System.out.println("██████╗ ██╗███╗   ██╗ ██████╗        ██████╗ ██████╗  ██████╗ ██╗  ██╗   ██╗\n██╔══██╗██║████╗  ██║██╔═══██╗      ██╔═══██╗██╔══██╗██╔═══██╗██║  ╚██╗ ██╔╝\n██║  ██║██║██╔██╗ ██║██║   ██║█████╗██║   ██║██████╔╝██║   ██║██║   ╚████╔╝ \n██║  ██║██║██║╚██╗██║██║   ██║╚════╝██║   ██║██╔═══╝ ██║   ██║██║    ╚██╔╝  \n██████╔╝██║██║ ╚████║╚██████╔╝      ╚██████╔╝██║     ╚██████╔╝███████╗██║   \n╚═════╝ ╚═╝╚═╝  ╚═══╝ ╚═════╝        ╚═════╝ ╚═╝      ╚═════╝ ╚══════╝╚═╝   ");// A decorative DINO-OPOLY in text art (Credit : http://patorjk.com/software/taag/)
            System.out.println("Before we play Dino-opoly, would you like to see a user guide telling you how to play the game?\n(Y/N)");
            String choice = scan.nextLine();
            if ("Y".equals(choice))
            {//It displays some instructions.
               System.out.println("\n- You and up to 3 friends move around a board with 26 spaces. You will move around by rolling two dice which are added together to determine how far you will move. On the text board you are represent by the (Player N)th letter. So for example Player 1 is represented by the letter A.");
               System.out.println("- If a player rolls a double, they are to draw a card from the deck. The card will contain a scenario (e.g. 'You have won the lottery' or 'You owe debt') and an amount of money they player is given or must pay.");
               System.out.println("- When a player passes start they are given £500. If they land on start they are given £1000.");
               System.out.println("- Landing on 'miss a turn' means they miss their next turn.");
               System.out.println("- Landing on the 'river cruise' on space 7 means that the player MUST travel on the river cruise to space '20' at the end of the river cruise. If they land on the river cruise on space '20', then the player MUST travel to space '7' at the end of the river cruise.");
               System.out.println("- If you land on a Dinosaur space, then you'll be given the option to buy the dinosuar for a certain price and you can choose to level it up for an extra price.");
               System.out.println("- After you've had your turn, before the next player goes you will be given an option to 1. Continue, 2. Build Houses or 3. Quit");
               System.out.println("- If you press '1', then you will do nothing and the next player will go.\n- If you press '2', the you will able to build a house provided you have enough money.\n  NOTE: The higher the number on the board, the more expensive the house is. (e.g. building a house on space '26' will be more expensive than buliding a house on space '1'). NOTE: Once you have built the house, you cannot undo this action!\n- If you press '3' then you will quit the game forever.");
               System.out.println("- If you lose all of your money, then you lose the game.");
               System.out.println("- The last player to still have money left wins!\n");
               System.out.println("- Now that you have read these simple instruction. LET'S PLAY!\n\n");
               valid = 1;
            }
            else if ("N". equals(choice))//If the user types 'N' then they do not get the instructions.
            {
                System.out.println("Okay then. LET'S PLAY!\n\n");
                valid = 1;
            }
            else
            {
               System.out.println("That is not a valid option");//Error checking if the user does not type Y/N
            }
            //end if
        }  
        //end while  
  ////BOARD SPACES\\\\ 
  Spaces[] spaces = new Spaces[26];//Spaces is a class which is an array of the 26 board spaces.
  Cards[] cards = new Cards[20];///Cpaces is a class which is an array of the 20 cards.
  spaces[0] = new Spaces(0,"Go");//Non-dino boards spaces are in the form new Spaces( Number,"Name");
  spaces[1] = new Spaces(1,"Oviraptor","Oviraptor is a small quick Dinosaur. Hopefully you'll make a quick profit.");//Dino boards spaces are in the form new Spaces( Number,"Name","Description");
  spaces[2] = new Spaces(2,"Velociraptor","This raptor is well known for appearing in the Jurassic Park series. Hopefully it will rapt your imagination.");
  spaces[3] = new Spaces(3,"Brachiosaurus","This giant dinosaur is priced at an attractive low price.");
  spaces[4] = new Spaces(4,"Compsognathus","This dinosaur is one of the smallest. It has a small price too!");
  spaces[5] = new Spaces(5,"Becklespinax","Buy this dinosaur at a low price!");
  spaces[6] = new Spaces(6,"Triceratop","This well-known dinosaur is a bargain.");
  spaces[7] = new Spaces(7,"Jungle River Cruise");
  spaces[8] = new Spaces(8,"Afrovenator","Discount T-Rex/African Hunter");
  spaces[9] = new Spaces(9,"Stegosaurus","Cheap for a well-known dinosaur/");
  spaces[10] = new Spaces(10,"Agilisaurus","A cheap herbivore which should you should consider.");
  spaces[11] = new Spaces(11,"Alamosauraus","A scary dinosaur at a nice low price.");
  spaces[12] = new Spaces(12,"Albertaceratops","A dinosaur which was found in Canada has a cool introductory price!");
  spaces[13] = new Spaces(13,"Miss A turn!");
  spaces[14] = new Spaces(14,"Albertosaurus","T-Rex - Walmart version. A bargain!");
  spaces[15] = new Spaces(15,"Alectrosaurus","Apparently an eagle lizard, but it is at a good price.");
  spaces[16] = new Spaces(16,"Alioramus"," A T-rex clone but cheaper.");
  spaces[17] = new Spaces(17,"Alvarezsaurus","Notable for having a really long tail. However the stories of the Dinosaur making a profit are also long...");
  spaces[18] = new Spaces(18,"Bambiraptor","Not to be confused with a Deer, according to the game's co-creator it is hard.");
  spaces[19] = new Spaces(19,"Pterodactyl","A flying high Pterosaurs for a flying high price!");
  spaces[20] = new Spaces(20,"Jungle River Cruise");
  spaces[21] = new Spaces(21,"Bellusaurus","A fine lizard at a fine price.");
  spaces[22] = new Spaces(22,"Brachytrachelo","Small dino at a respective price!");
  spaces[23] = new Spaces(23,"Archaeopteryx","Not an actual dinosaur - but it is flying in the market!");
  spaces[24] = new Spaces(24,"Yandusaurus","A mid-Jurassic dino being sold now!");
  spaces[25] = new Spaces(25,"T-Rex","Do not mess with the orignal one.");
  ////HAPPENING CARDS\\\\
  cards[0] = new Cards(1, "You’ve found a fossil, sell it for a lot of money", 2000);//If the first variable is a 1 then you gain money. The string is the description when the cards goes into play. The number is the 
  cards[1] = new Cards(0, "The Meteor has wiped all of you dinosaurs", 2000);
  cards[2] = new Cards(1, "A Dinosaur has laid an egg!", 200);
  cards[3] = new Cards(0, "A raptor has accidently eaten some of your money (YIPES!)", 200);
  cards[4] = new Cards(1, "You’ve successfully created a working time-machine!", 500);
  cards[5] = new Cards(0, "A Pterosaurs has swiped your money!", 500);
  cards[6] = new Cards(1, "You are the King of the Prehistoric Period!", 750);
  cards[7] = new Cards(0, "You can’t spell ‘Archaeopteryx’! You’ve lost the spelling bee", 750);
  cards[8] = new Cards(1, "Your dinosaur has won the roaring competition", 800);
  cards[9] = new Cards(0, "Your dinosaur has a cold, you must spend some money on medicine", 800);
  cards[10] = new Cards(1, "Your dinosaur has discover some gold!", 420);
  cards[11] = new Cards(0, "You’ve mistaken a meat eater for a plant eater!", 420);
  cards[12] = new Cards(1, "Your dinosaur has won a 100m sprint!", 550);
  cards[13] = new Cards(0, "Your dinosaur has lost all of its teeth!", 550);
  cards[14] = new Cards(1, "Your dinosaur has learnt how to code! Profit off of this!", 330);
  cards[15] = new Cards(0, "Two dinosaurs fought, one is badly injured. Spend money to heal it.", 700);
  cards[16] = new Cards(1, "Your dinosaur has won a beauty competition", 400);
  cards[17] = new Cards(0, "You’ve mistaken a Dinosaur for a Pterosaurs!", 400);
  cards[18] = new Cards(1, "Your dinosaur has dodged the meteor!", 350);
  cards[19] = new Cards(0, "The Blizzard has Struck!", 350);
    int a=0;int Playern=0;//a is used for a counter in naming all of the players. Playern is an important variable for actions that involve all of the players;
    
    
    while ((Playern<2) || (Playern>9))//Currently only 2-8 players are allowed to play. Technically infinitely many players could play.
    {
    System.out.print("Type the number of players: ");
     
    Playern = Integer.parseInt(scan.nextLine());//Parses the string to an interger.
    a=0;
    }
    //end while
    
    String c;
    Player[] players = new Player[Playern];
    while (a < Playern)
    {
      System.out.println("Type the Player "+(a+1)+"'s name.");
      c=scan.nextLine();
      players[a]= new Player(c);
      System.out.println("Hi " + c);
      a++;
    }
    if (a>5){
      System.out.println("Also if more than 4 players are on a board space at the same time it will replace the letters with the letters XXXX");
    }
    //end while

    System.out.println("\n─────────███─────────\n─────────█$█─────────\n─────█████$██████────\n───███████$████████──\n──████████$████████──\n─█████████$████████──\n─█████───█$█──████───\n─████────█$█─────────\n─█████████$█─────────\n─█████████$█████─────\n──████████$███████───\n────██████$█████████─\n───────███$█████████─\n─────────█$█─████████\n─────────█$█──███████\n──████───█$█──███████\n─█████████$█████████─\n██████████$█████████─\n─█████████$████████──\n───███████$██████────\n─────────█$█─────────\n─────────███─────────");

    ////GAMELOOP\\\\
    int lastplayer=19;
    int lastlastplayer=20;
    int Playernow= Playern - 1;//Every turn the player counter + 1. Therefore if we set the variable to the playern we will go on to the first player because Player 1 is represented by player 0; after the last player it will go back to the first player.
    int Playerlast=0;
    int position=0;
    int getmoney=0;
    String Answer="a";
    int rand1=0;
    int rand2=0;
    int rand3=0;
    int rent=0;
    char ans='2';//I've called it a string so that if a users adds in a N then it won't crash
    int ans2=0;
    int turns=0;
    boolean continueon=true;//When continueon == false then the game stops
    int x;int y;//used for the for counter
    //String[] pos = {"    ", "    ","    ","    ","    ","    ","    ","    ","    ","    ","    ","    ","    ","    ","    ","    ","    ","    ", "    ", "    ", "    ", "    ", "    ", "    ", "    ", "    "};
   String[] pos = {"", "","","","","","","","","","","","","","","","","", "", "", "", "", "", "", "", ""};//

    String[] charlist = {"A","B","C","D","E","F","G","H"};//Since the maximum number of players is 8. I have put 8 players.
    int[] positions= {0,0,0,0,0,0,0,0,0};
    System.out.println("Lets play some Dino-opoly");
    while (continueon==true)
    {
      turns++;
     
 
       
       //Playernow;
      Playernow++; 
      if (Playernow>=Playern)
      {
          Playernow=0;
      }
      //lastplayer=Playernow;
      //end if 
    
    
    if ((players[Playernow].Getnotplaying())==0) 
    {  
      y=0;
    for (x=0;x<Playern;x++){
      y=y+players[x].Getnotplaying();
    }
    System.out.println(y);
    y=Playern-y;
    if (y==1){
     continueon=false;
    }

      
     
    
    if (players[Playernow].GetMissATurn()==1) {
      players[Playernow].SetMissATurn(0);
    }   
    else if (continueon==true){

    ////THE BOARD INTERFACE\\\\
    for (x=0;x<26;x++){
      pos[x]="";
      for (y=0;y<Playern;y++){
        if (positions[y]==x){
          if ((pos[x]).length()<4){
          pos[x]=pos[x] + charlist[y];
          }
          else{
            pos[x]="XXXX";
          }
        }
      }
    }
    for (x=0;x<26;x++){
      while (pos[x].length()<4){
        pos[x]=pos[x]+" ";
      }
    }
    System.out.println(" ______ ______ ______ ______ ______ ______ ______ ______\n|      |      |      |      |      |      |      |River |\n|START |  1   |  2   |  3   |  4   |  5   |  6   |Cruise|\n| " + pos[0] + " | " + pos[1] + " | " + pos[2] + " | " + pos[3] + " | " + pos[4] + " | " + pos[5] + " | " + pos[6] + " | " + pos[7] + " |\n|______|______|______|______|______|______|______|______|");
    System.out.println("|      |                                         |      |\n|  25  |                                         |  8   |\n| " + pos[25] + " |                                         | " + pos[8] + " |\n|______|                                         |______|");
    System.out.println("|      |                                         |      |\n|  24  |                                         |  9   |\n| " + pos[24] + " |                                         | " + pos[9] + " |\n|______|                                         |______|");
    System.out.println("|      |                                         |      |\n|  23  |                                         |  10  |\n| " + pos[23] + " |                                         | " + pos[10] + " |\n|______|                                         |______|");
    System.out.println("|      |                                         |      |\n|  22  |                                         |  11  |\n| " + pos[22] + " |                                         | " + pos[11] + " |\n|______|                                         |______|");
    System.out.println("|      |                                         |      |\n|  21  |                                         |  12  |\n| " + pos[21] + " |                                         | " + pos[12] + " |\n|______|______ ______ ______ ______ ______ ______|______|");
    System.out.println("|River |      |      |      |      |      |      | Miss |\n|Cruise|  19  |  18  |  17  |  16  |  15  |  14  |a turn|\n| " + pos[20] + " | " + pos[19] + " | " + pos[18] + " | " + pos[17] + " | " + pos[16] + " | " + pos[15] + " | " + pos[14] + " | " + pos[13] + " |\n|______|______|______|______|______|______|______|______|");
    ////Print Board\\\\
    position=players[Playernow].Getposition();
    System.out.println((players[Playernow].GetName())+ " - Player "+ (Playernow + 1) + " is playing"+ "currently on space-"+ position +".");
    System.out.println("===Turn==");
    
    rand1=ThreadLocalRandom.current().nextInt(1,6);
    rand2=ThreadLocalRandom.current().nextInt(1,6);
    System.out.println("You rolled a " + rand1 + "&" + rand2 + "(=" +  (rand1 + rand2) + ")!");
    System.out.println(" _____     _____ \n" +"|     |   |     |\n" +"|  "+rand1+"  |   |  "+rand2+"  |\n" +"|_____|   |_____|");
    getmoney=players[Playernow].GetMoney();
  
    if (rand1==rand2)
    {
      rand3=ThreadLocalRandom.current().nextInt(0,19);
      System.out.println("You rolled a double now you can pickup a card.");
      rand3=cards[rand3].GetCards();
      if (rand3>0){
        System.out.println("You gained £"+ rand3 +"!");
      }
      if (rand3<0){
        System.out.println("You paid £" + (0- rand3) + "!");
      }
      getmoney= getmoney + rand3;
    }
    //end if
    
    ////ADJUST BOARD\\\\
    Playerlast=position;
    position= position + rand1 + rand2;
    if (position>=26)
    {
        position = position - 26;   
    }
    //end if
    
    System.out.println("You have landed on '"+spaces[position].GetName() +"' position: "+ position);
    
    
    //System.out.println("");
    getmoney= getmoney + spaces[position].GetEffect( Playerlast , position, Playernow, getmoney);
    position=Example.a;
    if (!((position==0)||(position==7)||(position==13)||(position==20)) && (spaces[position].GetOwner(position) != Playernow) &&  (spaces[position].GetOwner(position) != 9))
    {
      System.out.println("Rent time");
      rent=spaces[position].Getrent(Playernow,position);
      getmoney=getmoney-rent;
      System.out.println("You paid £" + rent+ " in rent to " + players[spaces[position].GetOwner(position)].GetName()+ "(Player "+ (spaces[position].GetOwner(position)+1) +")!");
      players[Playernow].TakeMoney(rent);
      players[spaces[position].GetOwner(position)].PlusMoney(rent);
    }
    //end if
    players[Playernow].PlusMoney( getmoney - players[Playernow].GetMoney());
    players[Playernow].SetMissATurn(Example.b);
    ////KIMON'S CODE HERE!\\\\
    players[Playernow].Setposition(position);
    if(getmoney<0){
      players[Playernow].Setnotplaying(1);
      System.out.println(" #     # ####### #     #    #       #######  #####  ####### ### \n  #   #  #     # #     #    #       #     # #     # #       ### \n   # #   #     # #     #    #       #     # #       #       ### \n    #    #     # #     #    #       #     #  #####  #####    #  \n    #    #     # #     #    #       #     #       # #           \n    #    #     # #     #    #       #     # #     # #       ### \n    #    #######  #####     ####### #######  #####  ####### ### \n");  
      
    }
    else{
      ans='N';
      while (!((ans=='1')||(ans=='2'))){
      System.out.println("________________\n|              |\n|  1:End turn  |\n|              |\n|   2:Build    |\n|    Houses    |\n|              |\n|   3:Quit     |\n|______________|");
      ans=(scan.nextLine()+"x").charAt(0);//added an x in case the user doesn't enter anything
      if (ans=='1'){
        System.out.println();
      }
      else if (ans=='2'){
        System.out.println("---Build---");
        y=0;
        for (x=0;x<26;x++){
          if (!((x==0)||(x==7)||(x==13)||(x==20))){
            if (spaces[x].GetOwner(x)==Playernow){
              System.out.println("Space "+ (x)+ " - " +spaces[x].GetName()+"Houses- "+ spaces[x].returnlevel(x));
              y++;     
            }
        }
        }
        if (y==0){
          System.out.println("--You currently have no houses---");
        }
        while (!(ans=='3')){
          System.out.println("_________________\n|1-Build a house|\n|2-See a rent   |\n|3- Quit mode   |\n_________________");
          ans=(scan.nextLine()+"x").charAt(0);
          if (ans=='1'){
            System.out.println("Type in your property number.");
            //ans=(scan.nextLine()+"x").charAt(0);
            ans2=Integer.parseInt('0' + scan.nextLine()); 
            if (!((ans2==0)||(ans2==7)||(ans2==13)||(ans2==20)||(ans2>25)||(ans2<0))){
              if(spaces[ans2].GetOwner(ans2) == Playernow){
                getmoney=players[Playernow].GetMoney();
                System.out.println("You chose "+spaces[ans2].GetName()+" which currently has "+spaces[ans2].returnlevel(ans2)+" house(s).");
                ans2=spaces[ans2].promotelevel(ans2,getmoney);
                if (ans2>0){
                  players[Playernow].TakeMoney(ans2);
                   System.out.println("You now have £"+players[Playernow].GetMoney());  
                }
                } 
              else{
                System.out.println("You don't own this property");
              }
            }
            else{
              System.out.println("You can't own one of these properties.");
            }
          }
          else if (ans=='2'){
            System.out.println("Input the space :");
            ans2=(Integer.parseInt('0' + scan.nextLine()));
            if (!((ans2==0)||(ans2==7)||(ans2==13)||(ans2==20)||(ans2>25)||(ans2<0))){
              spaces[ans2].GetRents(ans2);
            }
          }
          else if (ans=='3'){
            System.out.println("---End of Building mode---");
          }
          else{
            System.out.println("Please enter in a '1','2' or a '3'.");
          }
        }
      }
      else if(ans=='3'){
        System.out.println("Are you sure? (1- Yes 0- No)");
        ans=(scan.nextLine()+"x").charAt(0);
        if (ans=='1'){
          System.out.println("Good luck into the future");
          players[Playernow].Setnotplaying(1);
      System.out.println(" #     # ####### #     #    #       #######  #####  ####### ### \n  #   #  #     # #     #    #       #     # #     # #       ### \n   # #   #     # #     #    #       #     # #       #       ### \n    #    #     # #     #    #       #     #  #####  #####    #  \n    #    #     # #     #    #       #     #       # #           \n    #    #     # #     #    #       #     # #     # #       ### \n    #    #######  #####     ####### #######  #####  ####### ### \n");
        }
        else{
          System.out.println("You chose not to quit- how very brave!");
          ans='N';
        }
      }
      else{
        System.out.println("Please enter in a '1','2' or a '3'.");
      }
      }
    players[Playernow].Setposition(position);
    positions[Playernow] = position;
    }
    }
    //end else
    }
    //end IF which is miles away   
    }//end while
    System.out.println("End of game.");
    
    if (players[Playernow].GetMoney()<0){
      System.out.println("It is a draw!\n That is very lucky.");
    }
    else{
      Playernow++;

System.out.println("     _______________\n" +"    |@@@@|     |####|\n" +"    |@@@@|     |####|\n" +"    |@@@@|     |####|\n" +"    \\@@@@|     |####/\n" +"     \\@@@|     |###/\n" +"      `@@|_____|##'\n" +"        (PLAYER "+ Playernow +")\n" +"        .-'''''-.\n" +"      .'  * * *  `.\n" +"     :  *       *  :\n" +"    : ~  Y  O  U  ~ :\n" +"    : ~  W  I  N  ~ :\n" +"     :  *       *  :\n" +"      `.  * * *  .'\n" +"        `-.....-'");
Playernow--;
System.out.println( players[Playernow].GetName() +" (Player "+ (Playernow+1) + ") won the game of Dino-opoly after "+ (turns-Playern) + " turns.");
    }
//end while  
scan.close();
    }
    //end while
    //end void
}
//end main