diff options
Diffstat (limited to 'game.py')
| -rw-r--r-- | game.py | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/game.py b/game.py deleted file mode 100644 index c8927b5..0000000 --- a/game.py +++ /dev/null | |||
| @@ -1,126 +0,0 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | |||
| 3 | try: | ||
| 4 | input = raw_input | ||
| 5 | except NameError: | ||
| 6 | pass | ||
| 7 | |||
| 8 | from field import Field | ||
| 9 | |||
| 10 | class Help: | ||
| 11 | def setState(self,l): | ||
| 12 | self.loop = l | ||
| 13 | |||
| 14 | def printHelp(self): | ||
| 15 | print("") | ||
| 16 | print("Listed commands:") | ||
| 17 | print(" try\t<x>\t<y>\tTests for mines") | ||
| 18 | print(" flag\t<x>\t<y>\tPlaces flag") | ||
| 19 | print(" ?\t<x>\t<y>\tPlaces questionmark") | ||
| 20 | print(" restart\t\tStarts new game") | ||
| 21 | print(" quit or exit\t\tQuits game") | ||
| 22 | print(" help\t\t\tPrints list of commands") | ||
| 23 | self.loop.command() | ||
| 24 | |||
| 25 | class Setup: | ||
| 26 | def setState(self,l): | ||
| 27 | self.loop = l | ||
| 28 | |||
| 29 | def setup(self): | ||
| 30 | print("") | ||
| 31 | print("Select diffeculty:") | ||
| 32 | print(" 1. Beginner\t\t(10 mines, 9x9)") | ||
| 33 | print(" 2. Intermediate\t(40 mines, 16x16)") | ||
| 34 | print(" 3. Expert\t\t(99 mines, 30x16)") | ||
| 35 | print(" 4. Custom") | ||
| 36 | print("") | ||
| 37 | |||
| 38 | n = input("Choice: ") | ||
| 39 | n = n.split() | ||
| 40 | choice = int(n[0]) | ||
| 41 | |||
| 42 | if choice == 1: | ||
| 43 | w = 9 | ||
| 44 | h = 9 | ||
| 45 | m = 10 | ||
| 46 | elif choice == 2: | ||
| 47 | w = 16 | ||
| 48 | h = 16 | ||
| 49 | m = 40 | ||
| 50 | elif choice == 3: | ||
| 51 | w = 30 | ||
| 52 | h = 16 | ||
| 53 | m = 99 | ||
| 54 | elif choice == 4: | ||
| 55 | w = int(input("Width: ")) | ||
| 56 | h = int(input("Heigt: ")) | ||
| 57 | m = int(input("Mines: ")) | ||
| 58 | else: | ||
| 59 | print(str(choice) + " is not a option.") | ||
| 60 | self.setup() | ||
| 61 | |||
| 62 | minefield = Field(w,h,m) | ||
| 63 | self.loop.setMinefield(minefield) | ||
| 64 | self.loop.command() | ||
| 65 | |||
| 66 | class Loop: | ||
| 67 | def setStates(self,s,h,e): | ||
| 68 | self.setup = s | ||
| 69 | self.end = e | ||
| 70 | self.help = h | ||
| 71 | |||
| 72 | def setMinefield(self,m): | ||
| 73 | self.minefield = m | ||
| 74 | |||
| 75 | def command(self): | ||
| 76 | self.minefield.printField() | ||
| 77 | if(self.minefield.cleared()): | ||
| 78 | self.end.endGame(False) | ||
| 79 | |||
| 80 | command = input("Command >> ") | ||
| 81 | c = command.split(' ') | ||
| 82 | |||
| 83 | if c[0] == "try": | ||
| 84 | if self.minefield.guess(ord(c[1])-65,int(c[2])-1): | ||
| 85 | self.minefield.printField() | ||
| 86 | self.end.endGame(True) | ||
| 87 | self.command() | ||
| 88 | elif c[0] == "flag": | ||
| 89 | self.minefield.flag(ord(c[1])-65,int(c[2])-1) | ||
| 90 | self.command() | ||
| 91 | elif c[0] == "?": | ||
| 92 | self.minefield.question(ord(c[1])-65,int(c[2])-1) | ||
| 93 | self.command() | ||
| 94 | elif c[0] == "restart": | ||
| 95 | self.setup.setup() | ||
| 96 | elif c[0] == "quit" or c[0] == "exit": | ||
| 97 | exit() | ||
| 98 | elif c[0] == "help": | ||
| 99 | self.help.printHelp() | ||
| 100 | else: | ||
| 101 | print(c[0] + " is not a recognized command") | ||
| 102 | self.help.printHelp() | ||
| 103 | |||
| 104 | class End: | ||
| 105 | def setState(self,s): | ||
| 106 | self.setup = s | ||
| 107 | |||
| 108 | def restart(self): | ||
| 109 | choice = input("Do you want to start again? [y/n] ") | ||
| 110 | choice = choice.split() | ||
| 111 | choice = choice[0] | ||
| 112 | if choice == "y": | ||
| 113 | self.setup.setup() | ||
| 114 | elif choice == "n": | ||
| 115 | exit() | ||
| 116 | else: | ||
| 117 | print(str(choice) + " is not a valid choice") | ||
| 118 | self.restart() | ||
| 119 | |||
| 120 | def endGame(self,m): | ||
| 121 | print("") | ||
| 122 | if m: | ||
| 123 | print("You hit a mine :o") | ||
| 124 | else: | ||
| 125 | print("You won :D") | ||
| 126 | self.restart() \ No newline at end of file | ||
