Question: using c# to complete following assignment Run Away! Run Away is a text-based game where the player must outrun a killer rabbit to survive. The
using c# to complete following assignment
Run Away!
Run Away is a text-based game where the player must outrun a killer rabbit to survive.
The Board
- The board is made up of a 5x5 grid of rooms.
- The player always starts randomly in 1 of the 5 rooms on the far left.
- The Rabbit always starts in the center.
- As the Rabbit moves, he leaves behind a fiery trail that is deadly to the player.
Below is a picture 4 turns into the game.
| (Fire) | (Fire) | |||
| (Fire) | (Fire) | Rabbit | ||
| Player |
The Rules
- Each round, both the Rabbit and the player get to move 1 room (not diagonally).
- The Rabbit moves according to the following algorithm:
- If on the same row, move 1 column towards player.
- If on the same column, move 1 row towards player.
- If on a different column and row choose row or column move with 50% random probability.
- The player may choose to move either North, West, South, East, or stay put. To move, the user types W, A, S, or D and then hits Enter. To stay put, the user simply hits Enter. If the player tries to leave the grid she bumps into a wall (staying put).
- If, at the end of the round, the player ends up on the Rabbit or on the fiery trail, she dies.
- If the player survives 15 turns, she wins.
Sample Game 1
Welcome to the Rabbit Cave! You Will Die, Unless You Outrun the Rabbit! Commands: WASD to Move, Q to Quit. . . . . . . . . . . P . R . . . . . . . . . . . . Enter Cmd: q Bye.
Sample Game 2
Welcome to the Rabbit Cave! You Will Die, Unless You Outrun the Rabbit! Commands: WASD to Move, Q to Quit. . . . . . . . . . . . . R . . . . . . . P . . . . Enter Cmd: d . . . . . . . . . . . . * . . . . R . . . P . . . Enter Cmd: d . . . . . . . . . . . . * . . . R * . . . . P . . Enter Cmd: d . . . . . . . . . . . . * . . . * * . . . R . P . Enter Cmd: d . . . . . . . . . . . . * . . . * * . . . * R . P Enter Cmd: d You bump into a wall. . . . . . . . . . . . . * . . . * * . . . * * R P Enter Cmd: w . . . . . . . . . . . . * . . . * * . P . * * * R Enter Cmd: w . . . . . . . . . . . . * . P . * * . R . * * * * Enter Cmd: w . . . . . . . . . P . . * . R . * * . * . * * * * Enter Cmd: a . . . . . . . . P R . . * . * . * * . * . * * * * Enter Cmd: a . . . . . . . P R * . . * . * . * * . * . * * * * Enter Cmd: a . . . . . . P R * * . . * . * . * * . * . * * * * Enter Cmd: a . . . . . P R * * * . . * . * . * * . * . * * * * Enter Cmd: s . . . . . R * * * * P . * . * . * * . * . * * * * Enter Cmd: s . . . . . * * * * * R . * . * P * * . * . * * * * Enter Cmd: s You escape and vow to return with the Holy Hand Grenade! You Win! Game Over.
Sample Game 3
Welcome to the Rabbit Cave! You Will Die, Unless You Outrun the Rabbit! Commands: WASD to Move, Q to Quit. . . . . . . . . . . . . R . . . . . . . P . . . . Enter Cmd: w . . . . . . . . . . . . * . . P . R . . . . . . . Enter Cmd: d The Rabbit Ate You! You Lose! Game Over.
Sample Game 4
Welcome to the Rabbit Cave! You Will Die, Unless You Outrun the Rabbit! Commands: WASD to Move, Q to Quit. . . . . . . . . . . . . R . . P . . . . . . . . . Enter Cmd: d . . . . . . . . . . . R * . . . P . . . . . . . . Enter Cmd: d . . . . . . . . . . . * * . . . R P . . . . . . . Enter Cmd: w You Died in the Rabbit's Flames! You Lose! Game Over.
Board.cs
using System; public class Board { string[,] board; public Board() { board = new string[5, 5]; for (int row = 0; row < 5; row++) { for (int col = 0; col < 5; col++) { board[col, row] = "."; } } }
public string getRoom(Point p) { return board[p.x + 2, 2 - p.y]; }
public void setRoom(Point p, string r) { board[p.x + 2, 2 - p.y] = r; }
public override string ToString() { string s = ""; for (int row = 0; row < 5; row++) { for (int col = 0; col < 5; col++) { s += (board[col, row] + " "); } s += " ";//Console.WriteLine(); } return s; } }
Game.cs
using System; public class Game { Point player; Point rabbit; Board board; string userCmd;
public Game() { board = new Board(); player = new Point(-2, 2); rabbit = new Point(0, 0);
board.setRoom(player, "P"); board.setRoom(rabbit, "R"); }
public void mainLoop() { while (true) { //render Console.WriteLine(board);
//get user input Console.Write("Enter Cmd: "); userCmd = Console.ReadLine().ToUpper();
if (userCmd == "Q") break; //update update(); } }
public void update() {
} }
Point.cs
using System; public class Point { public int x; public int y;
public Point(int x, int y) { this.x = x; this.y = y; }
public override string ToString() { return "(" + x + ", " + y + ")"; } }
Program.cs
using System;
class MainClass { public static void Main(string[] args) { Game g = new Game(); g.mainLoop(); /* Board b = new Board(); Point rabbit = new Point(2, -1); b.setRoom(rabbit, "R"); Console.WriteLine(b); */ //string[,] a = new string[5,5];
//a[2, 1] = "R";
/* Console.WriteLine("Hello World!"); int i = 4; Point p1 = new Point(2, -1); Point p2 = new Point(0, 0);
Console.WriteLine(i); Console.WriteLine(p1.y); Console.WriteLine(p2); */
/* Random rgen = new Random(); for(int i = 0; i < 100; i++) Console.WriteLine(rgen.Next(100, 105)); */ } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
