~noskcaj/ubuntu/vivid/iagno/3.14.2

« back to all changes in this revision

Viewing changes to src/player.vala

  • Committer: Package Import Robot
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2014-04-26 10:39:57 UTC
  • mfrom: (1.1.4) (0.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140426103957-uh2q0azqvx4zlzyr
Tags: 1:3.12.1-1
* New upstream release.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * Copyright (C) 2013 Michael Catanzaro
 
4
 *
 
5
 * This file is part of Iagno.
 
6
 *
 
7
 * Iagno is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * Iagno is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with Iagno.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
public enum Player
 
22
{
 
23
    NONE,
 
24
    LIGHT,
 
25
    DARK;
 
26
 
 
27
    public string to_string ()
 
28
    {
 
29
        switch (this)
 
30
        {
 
31
        case LIGHT:
 
32
            return "L";
 
33
        case DARK:
 
34
            return "D";
 
35
        default:
 
36
            warn_if_fail (this == NONE);
 
37
            return " ";
 
38
        }
 
39
    }
 
40
 
 
41
    public static Player from_char (char c)
 
42
        requires (c == 'L' || c == 'D' || c == ' ')
 
43
    {
 
44
        switch (c)
 
45
        {
 
46
        case 'L':
 
47
            return LIGHT;
 
48
        case 'D':
 
49
            return DARK;
 
50
        case ' ':
 
51
            return NONE;
 
52
        default:
 
53
            warn_if_reached ();
 
54
            return NONE;
 
55
        }
 
56
    }
 
57
 
 
58
    public static Player flip_color (Player p)
 
59
        requires (p == Player.LIGHT || p == Player.DARK)
 
60
    {
 
61
        if (p == Player.LIGHT)
 
62
            return Player.DARK;
 
63
        else
 
64
            return Player.LIGHT;
 
65
    }
 
66
}
 
67