mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-22 20:55:52 +12:00
Implement "Read Books"
This commit is contained in:
parent
0b06cd1810
commit
6c42c57bfe
6 changed files with 243 additions and 1 deletions
55
Horse Isle Server/HorseIsleServer/Game/Book.cs
Normal file
55
Horse Isle Server/HorseIsleServer/Game/Book.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HISP.Game.Services
|
||||
{
|
||||
public class Book
|
||||
{
|
||||
private static List<Book> libaryBooks = new List<Book>();
|
||||
public static Book[] LibaryBooks
|
||||
{
|
||||
get
|
||||
{
|
||||
return libaryBooks.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public int Id;
|
||||
public string Title;
|
||||
public string Author;
|
||||
public string Text;
|
||||
public Book(int id, string title, string author, string text)
|
||||
{
|
||||
Id = id;
|
||||
Title = title;
|
||||
Author = author;
|
||||
Text = text;
|
||||
libaryBooks.Add(this);
|
||||
}
|
||||
|
||||
public static bool BookExists(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetBookById(id);
|
||||
return true;
|
||||
}
|
||||
catch(KeyNotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static Book GetBookById(int id)
|
||||
{
|
||||
foreach(Book libaryBook in LibaryBooks)
|
||||
{
|
||||
if (libaryBook.Id == id)
|
||||
return libaryBook;
|
||||
}
|
||||
throw new KeyNotFoundException("no book with id: " + id.ToString() + " found.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue