/data/

rel='alternate' title='Atom feed' href='https://code.fourisland.com/frigidearth/atom/src/com/fourisland/frigidearth/Game.java?h=master' type='application/atom+xml'/>
about summary refs log tree commit diff stats
path: root/src/com/fourisland/frigidearth/Game.java
blob: d31f1b299f6bee6309a7b7b4a8c8cec727cf2b30 (plain) (blame)
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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.fourisland.frigidearth;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author hatkirby
 */
public class Game
{
    public int health = 15;
    public int maxHealth = 15;
    public int level = 1;
    public int experience = 0;
    public List<Item> inventory = new ArrayList<Item>();
    public Item helmet = null;
    public Item sword = null;
    public Item shield = null;
    public Item ring = null;
    public Item shoes = null;
    
    public boolean equipItem(final Item i)
    {
        if ((i.getItemType() != ItemType.Helmet) && (i.getItemType() != ItemType.Sword) && (i.getItemType() != ItemType.Shield) && (i.getItemType() != ItemType.Ring) && (i.getItemType() != ItemType.Shoes))
        {
            throw new IllegalArgumentException("You can only equip helmets, swords, shields, rings and shoes.");
        }
        
        boolean alreadyEquipped = false;
        boolean alreadyEquippedSame = false;
        Item equippedItem = null;
        
        switch (i.getItemType())
        {
            case Helmet:
                if (helmet != null)
                {
                    alreadyEquipped = true;
                    equippedItem = helmet;
                    
                    if (helmet == i)
                    {
                        alreadyEquippedSame = true;
                    }
                }
                
                break;
                
            case Sword:
                if (sword != null)
                {
                    alreadyEquipped = true;
                    equippedItem = sword;
                    
                    if (sword == i)
                    {
                        alreadyEquippedSame = true;
                    }
                }
                
                break;
                
            case Shield:
                if (shield != null)
                {
                    alreadyEquipped = true;
                    equippedItem = shield;
                    
                    if (shield == i)
                    {
                        alreadyEquippedSame = true;
                    }
                }
                
                break;
                
            case Ring:
                if (ring != null)
                {
                    alreadyEquipped = true;
                    equippedItem = ring;
                    
                    if (ring == i)
                    {
                        alreadyEquippedSame = true;
                    }
                }
                
                break;
                
            case Shoes:
                if (shoes != null)
                {
                    alreadyEquipped = true;
                    equippedItem = shoes;
                    
                    if (shoes == i)
                    {
                        alreadyEquippedSame = true;
                    }
                }
                
                break;
        }
        
        if (alreadyEquippedSame)
        {
            ((MapViewGameState) Main.getGameState()).printMessage("You have already equipped " + i.getItemName().toLowerCase());
            
            return false;
        } else if (alreadyEquipped)
        {
            inventory.add(equippedItem);
            ((MapViewGameState) Main.getGameState()).printMessage("You unequip your " + equippedItem.getItemName().toLowerCase() + " and equip " + i.getItemName().toLowerCase());
        } else {
            ((MapViewGameState) Main.getGameState()).printMessage("You equip " + i.getItemName().toLowerCase());
        }
        
        switch (i.getItemType())
        {
            case Helmet:
                helmet = i;
                break;
                
            case Sword:
                sword = i;
                break;
                
            case Shield:
                shield = i;
                break;
                
            case Ring:
                ring = i;
                break;
                
            case Shoes:
                shoes = i;
                break;
        }
        
        return true;
    }
    
    public int getAttackPower()
    {
        return (int) (Math.floor(Math.sqrt(level)) + (sword == null ? 0 : sword.getAttackPower()));
    }
    
    public int getDefense()
    {
        return (helmet == null ? 0 : helmet.getDefense()) + (shield == null ? 0 : shield.getDefense()) + (shoes == null ? 0 : shoes.getDefense());
    }
}