我已經創建了這個使用鏈表的專賣板。專賣實施規則
已將值賦予方塊,但需要能夠將這些值的形式添加到玩家類中分配的整數。
任何幫助或建議,將不勝感激(我現在道歉他們還要修訂的意見)的代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MonoPolyFin;
namespace MonoPolyFin
{
public class Square//Creating Squares for the board
{
public Square next;//Declaring the Square as the next node
public string g;//String to store the Square data
public Square(string g)//assigning the string to g
{
this.g = g;
}
public class Board/*The Board class creating the linked list and printing it out to the console window*/
{
public Square head;//Declaring as the head
Square current;//and current
public void Add(Square s)/*The Add method for adding nodes in order to the linked list checking each time to see if the head of
the list is empty */
{
if (head == null)//if the head is empty
{
head = s;//the head equals the string
current = head;//the current node is the head
}
else
{
current.next = s;//if not empty the current node is the next node
current = current.next;//then the next
current.next = head;//keep going round the board through the linked list
}
}
public void Writeline(ref Square gamesquare)//The writeline method to print out in the console
{
Random r = new Random();//Creates a new object using the random method
int n = r.Next(1, 6);//Creates a random number between 1-6
Console.WriteLine(n);//Writes the stored number to the console
Console.WriteLine("Player moves to " + gamesquare.g);//write the gamesquare to the console that is saved in the string g
Console.ReadKey();//read whats in the console and throw it out
if (n <= 1)//If the number is less than 1
{
head = current
;//Move one positions down the list
}
else if (n <= 2)//If the number is less than 2
{
head = head.next.next;//Move two positions down the list
}
else if (n <= 3)//If the number is less than 3
{
head = head.next.next.next;//Move three positions down the list
}
else if (n <= 4)//If the number is less than 4
{
head = head.next.next.next.next;//Move four positions down the list
}
else if (n <= 5)//If the number is less than 5
{
head = head.next.next.next.next.next;//Move five positions down the list
}
else if (n <= 6)//If the number is less than 6
{
head = head.next.next.next.next.next.next;//Move six positions down the list
}
}
}
public class Player1
{
public string Dog;
public int Money = 2000;
public Square position = null;
}
public class Player2
{
public string Car;
public int Money = 2000;
public Square position = null;
}
static void Main(string[] args)//Main method
{
int go = 200;//Value of the square in the linked list
int strand = 220;//Value of the square in the linked list
int trafalger_square = 220;//Value of the square in the linked list
int leicester_square = 280;//Value of the square in the linked list
int piccadilly = 280;//Value of the square in the linked list
int regent_street = 300;//Value of the square in the linked list
int oxford_street = 300;//Value of the square in the linked list
int mayfair = 400;//Value of the square in the linked list
int park_lane = 400;//Value of the square in the linked list
int whitechapel = 60;//Value of the square in the linked list
int old_kent_road = 60;//Value of the square in the linked list
int euston = 100;//Value of the square in the linked list
int islington = 100;//Value of the square in the linked list
int pall_mall = 140;//Value of the square in the linked list
int whitehall = 140;//Value of the square in the linked list
int vine_street = 180;//Value of the square in the linked list
int bow_strett = 180;//Value of the square in the linked list
Board list = new Board();//constructor to create the list
list.Add(new Square("Go Collect £" + go));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Strand £" + strand + " Black"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Trafalger Square £" + trafalger_square + " Black"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Gas"));//Add to the linked list
list.Add(new Square("Leicester Square £" + leicester_square + " Aqua"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Piccadilly £" + piccadilly + " Aqua"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Card"));//Add to the linked list
list.Add(new Square("Regent Street £" + regent_street + " Yellow"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Oxford £" + oxford_street + " Yellow"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Electric"));//Add to the linked list
list.Add(new Square("Mayfair £" + mayfair + " Green"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Park Lane £" + park_lane + " Green"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Jail"));//Add to the linked list
list.Add(new Square("Old Kent Road £" + old_kent_road + " Blue"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Whitechapel £" + whitechapel + " Blue"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Water"));//Add to the linked list
list.Add(new Square("Islington £" + islington + " Red"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Euston £" + euston + " Red"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Card"));//Add to the linked list
list.Add(new Square("Pall Mall £" + pall_mall + " Pink"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Whitehall £" + whitehall + " Pink"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Phone"));//Add to the linked list
list.Add(new Square("Bow Street £" + bow_strett + " Brown"));//Add to the linked list using the Add method also assigning the int value
list.Add(new Square("Vine Street £" + vine_street + " Brown"));//Add to the linked list using the Add method also assigning the int value
for (int i = 0; i <= 10; i++)
{
Player2 car = new Player2();
car.position = list.head;
Console.WriteLine("Car roles the dice and roles");
list.Writeline(ref car.position);
Player1 dog = new Player1();
dog.position = list.head;
Console.WriteLine("Dog roles the dice and roles");
list.Writeline(ref dog.position);
}
}
}
}
忽略這個看起來像作業的事實,你已經發布了一個非常大的代碼牆。請縮小您的代碼,以便僅查看您有問題的代碼。 – gunr2171
無可否認,這是我迄今爲止所做的功課,作業,儘管我尋找的解決方案我自己找不到。我發佈了代碼牆,以便查看代碼的人知道我已經掌握了哪些內容,並且希望能夠向我提供有關在上述問題中添加了代碼的位置的建議。 – itchebantye
恩,我本來期望在它上面觸發的「廣場」上發生一個事件,它執行了一個動作。 PS遊戲的一個有趣的部分是讓業主分心,所以他們沒有注意到你剛剛在mayfair的酒店登陸...... –