Chủ đề: Giúp đỡ về game phiêu lưu
-
22-10-2013, 09:24 AM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Giúp đỡ về game phiêu lưu
Hi các bạn. Hiện giờ mình đang có bài tập về cái game này. Luât chơi của game rất đơn giản chỉ cần đi thu thập những món đồ như đèn pin(tỏuch), ví(wallet), hay điện thoại(phone) và túi xách(handbag)... và người chơi chỉ được phép lượm 4 món tối đa. Nhưng gio xách vẫn lượm được cho dù người chơi đã đầy thùng đồ. Một khi đã lượm được gỏi xách thì có thể lươm thêm được 2 món đồ nữa. Những đồ vật kia có thể ném ra ngoài ngoại trừ gio xách (handbag). Mình add code đậy mong pro nào hướng dẫn cho mình.
/**
* Inventory takes care of items that the player is carrying
*
* @author
* @version
*/
public class Inventory
{
/**
* Whether the player has each item
*/
private boolean hasItem[] = new boolean[Item.values().length];
/**
* max number of items the player can carry without the handbag
*/
private static final int MAX_ITEMS = 4;
/**
* Keeps track of how many things the player is carrying
*/
private int numItems = 0;
/**
* This method can be used to have the player pick up an item
*
* @param item the thing to pick up
* @param location where the things is picked up from
*/
public void pickUp(Item item, Location location)
{
if(youHave(item))
{
System.out.println("You already have the " + item + "!");
}
else if(!location.isHere(item))
{
System.out.println("There is no " + item + " here!");
}
else if(numItems < MAX_ITEMS)
{
location.removeItem(item);
hasItem[item.ordinal()] = true;
numItems++;
System.out.println("ok");
}
else
{
System.out.println("You can't carry any more!");
}
}
/**
* This method can be used to have the player drop an item
*
* @param item the item to drop
* @param location where to drop it
*/
public void drop(Item item, Location location)
{
if(!hasItem[item.ordinal()])
{
System.out.println("You don't have the " + item + "!");
}
else
{
hasItem[item.ordinal()] = false;
location.addItem(item);
numItems--;
System.out.println("ok");
}
}
/**
* This method checks whether the player currently has the item
*
* @param item which item
*
* @return true if he/she does
*/
public boolean youHave(Item item)
{
return hasItem[item.ordinal()];
}
/**
* This method prints a list of what the player is currently carrying
*/
public void listWhatYouHave()
{
if (hasItem[6]) // item is a handbag
{
System.out.println("You are carrying these items in your handbag:");
}
else
{
System.out.println("You are carrying:");
}
for (int ii = 0; ii < 6; ii++)
{
if (hasItem[ii])
{
switch (ii)
{
case 0:
System.out.println("Torch");
break;
case 1:
System.out.println("Wallet");
break;
case 2:
System.out.println("Keys");
break;
case 3:
System.out.println("Ring");
break;
case 4:
System.out.println("USB");
break;
case 5:
System.out.println("Mobile");
break;
default:
System.out.println("Invalid item!");
break;
}
}
}
}
/**
* This method checks whether an item is currently in the room,
* or being carried by the player
*
* @param the item to check
* @location where to check for it
*
* @return true if the item is here
*/
public boolean isHere(Item item, Location location)
{
return youHave(item) || location.isHere(item);
}
}
Mình không biết chỉnh 2 cái method
pickup() method và
drop() method cho phù hơp với cái túi xách. Mong mọi người chỉ giáo. Cảm ơn mọi người rất nhiều!View more random threads:
- hướng dẫn bài tập với mẫu singleton
- Xin hướng dẫn cách trích rút nội dung trong HTML ....
- [HELP] Lượng giác ngược
- Điểm mạnh của framework hibernate
- Hỏi cách tạo 1 project java và debug với Jcreator cho người mới học.
- Lỗi lập trình socket trong java
- Hướng dẫn lập trình game cờ tướng bằng Java
- Cho em hỏi về lỗi NullPointerException
- Cần Host Free hỗ trợ Java(Spring, Hibernate) connect database SQL Server Express 2005
- Hỏi về game java tetris - xếp hình
-
22-10-2013, 03:11 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Có pro nào hướng dẫn giúp mình với. Thanks
-
20-11-2013, 10:12 AM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
http://adcvietnam.net/
Dưới ánh nắng mặt trời đang lên, những đống pallet nhựa An Giang trải dài mênh mông như những bức tranh tự nhiên đầy sắc màu. Mỗi chiếc pallet nhựa không chỉ là một vật dụng thông thường mà còn là...
Pallet nhựa An Giang giao hàng...