コード例 #1
0
    def create_coins(self, rows, columns, board):
        num = 10
        for i in range(num):
            tmp = int((columns - 10) / num)
            y = random.randint(tmp * i + 3, (tmp * (i + 1)) - 2)
            x = random.randint(15, rows - 15)
            obj = coins(x, y)
            obj.print(board)

        return board
コード例 #2
0
ファイル: test_coins.py プロジェクト: heitorschueroff/ctci
 def test_coins(self):
     self.assertEqual(1, coins(0))
     self.assertEqual(1, coins(3))
     self.assertEqual(2, coins(5))
     self.assertEqual(4, coins(10))
     self.assertEqual(9, coins(20))
     self.assertEqual(13, coins(25))
コード例 #3
0
 def put_coins_block(self, screen_no):
     '''
     Puts a coin block (of random height and width) at a random position on the given screen_no
     The counting of the screen_no starts from 1
     '''
     h = random.randint(2, 7)
     w = random.randint(10, 30)
     xpos = random.randint(3, self._rows - 2)  # man anything is enough
     ypos = random.randint(
         int((screen_no - 1) * global_stuff.screen_length),
         int(screen_no * global_stuff.screen_length))  # 1st screen
     if (global_stuff.debug == 1):
         print(ypos)
     for i in range(h):
         for j in range(w):
             c = coins(xpos + i, ypos + j)
             try:
                 c.write_self_on_board(self)
             except:
                 continue
コード例 #4
0
class marios(person):
    '''o
	  -H-
	  +'+
	'''
    coi = coins()
    b = boxes()
    obs = obstacles()
    ene = enemies()

    coin = coi.coin
    changed_coin = coi.changed_coin
    block = obs.block
    enemy_0 = ene.enemy_0
    enemy_1 = ene.enemy_1

    boss_defeat = 0
    mario_pos_x = 40
    mario_pos_y = -7
    hand_coin = 0
    mario = [[' ', 'o', ' '], ['-', 'H', '-'], ['+', '\'', '+']]
    store = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]
    dif_x = dif_y = 0
    death_flag = 0
    kill = 0

    def coins_m(self, inp):
        if (boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x + 3]
                == marios.coin and inp == 'd'):
            boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x +
                                              3] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x - 1]
              == marios.coin and inp == 'a'):
            boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x -
                                              1] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x + 4]
              == marios.coin and inp == 'd'):
            boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x +
                                              4] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x - 2]
              == marios.coin and inp == 'a'):
            boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x -
                                              2] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x + 5]
              == marios.coin and inp == 'd'):
            boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x +
                                              5] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x - 3]
              == marios.coin and inp == 'a'):
            boxes.box[marios.mario_pos_y + 1][marios.mario_pos_x -
                                              3] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 4][marios.mario_pos_x - 1]
              == marios.coin and inp == 'l'):
            boxes.box[marios.mario_pos_y + 4][marios.mario_pos_x -
                                              1] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 4][marios.mario_pos_x - 2]
              == marios.coin and inp == 'l'):
            boxes.box[marios.mario_pos_y + 4][marios.mario_pos_x -
                                              2] = marios.changed_coin
            marios.hand_coin += 1
        elif (boxes.box[marios.mario_pos_y + 4][marios.mario_pos_x - 3]
              == marios.coin and inp == 'l'):
            boxes.box[marios.mario_pos_y + 4][marios.mario_pos_x -
                                              3] = marios.changed_coin
            marios.hand_coin += 1

    def frame_check_m(self, inp):
        if marios.mario_pos_x < (boxes.frame - 97):
            if inp == 'a':
                return 3
        if marios.mario_pos_x >= 1445 and marios.boss_defeat != 1:
            if inp == 'd':
                return 3

    def obstacles_m(self, inp):
        #not passing through tubes
        if boxes.box[marios.mario_pos_y + 2][marios.mario_pos_x + 5] in [
                *marios.block, marios.enemy_0
        ]:
            if inp == 'd':
                return 3
        if boxes.box[marios.mario_pos_y + 2][marios.mario_pos_x - 3] in [
                *marios.block, marios.enemy_0
        ]:
            if inp == 'a':
                return 3

        #standing on tubes
        if boxes.box[marios.mario_pos_y +
                     3][marios.mario_pos_x] in marios.block or boxes.box[
                         marios.mario_pos_y + 3][marios.mario_pos_x +
                                                 2] in marios.block:
            if inp == 'l':
                return 3

    def start_m(self):
        for i in range(3):
            for j in range(3):
                marios.store[i][j] = boxes.box[-7 + i][marios.mario_pos_x + j]
                boxes.box[-7 + i][marios.mario_pos_x + j] = marios.mario[i][j]

    def input_m(self, inp):
        if inp == 'w':
            marios.mario_pos_y -= 3
            marios.dif_y = 3
        elif inp == 'l':
            if boxes.box[marios.mario_pos_y +
                         5][marios.mario_pos_x] == marios.enemy_0 or boxes.box[
                             marios.mario_pos_y + 5][marios.mario_pos_x +
                                                     2] == marios.enemy_0:
                enemies.enemy_store[(marios.mario_pos_x - 5) //
                                    80][1] = enemies.enemy_store[
                                        (marios.mario_pos_x - 5) //
                                        80][0] = marios.enemy_1
                marios.kill += 1
            marios.mario_pos_y += 3
            marios.dif_y = -3
        elif inp == 'a':
            if boxes.box[marios.mario_pos_y +
                         2][marios.mario_pos_x -
                            2] == marios.enemy_0 or boxes.box[
                                marios.mario_pos_y + 2][marios.mario_pos_x -
                                                        3] == marios.enemy_0:
                enemies.enemy_store[(marios.mario_pos_x - 5) //
                                    80][1] = enemies.enemy_store[
                                        (marios.mario_pos_x - 5) //
                                        80][0] = marios.enemy_1
                marios.death_flag = 1
            marios.mario_pos_x -= 3
            marios.dif_x = -3
        elif inp == 'd':
            if boxes.box[marios.mario_pos_y +
                         2][marios.mario_pos_x +
                            4] == marios.enemy_0 or boxes.box[
                                marios.mario_pos_y + 2][marios.mario_pos_x +
                                                        5] == marios.enemy_0:
                enemies.enemy_store[(marios.mario_pos_x - 5) //
                                    80][1] = enemies.enemy_store[
                                        (marios.mario_pos_x - 5) //
                                        80][0] = marios.enemy_1
                marios.death_flag = 1
            marios.mario_pos_x += 3
            marios.dif_x = 3

    def move_m(self):
        for i in range(3):
            for j in range(3):
                boxes.box[marios.mario_pos_y + marios.dif_y +
                          i][marios.mario_pos_x + j -
                             marios.dif_x] = marios.store[i][j]
                marios.store[i][j] = boxes.box[marios.mario_pos_y +
                                               i][marios.mario_pos_x + j]
                boxes.box[marios.mario_pos_y + i][marios.mario_pos_x +
                                                  j] = marios.mario[i][j]

    def __init__(self, inp):
        marios.dif_x = marios.dif_y = marios.death_flag = 0
        person.__init__(self, marios.mario_pos_x, marios.mario_pos_y)
        if inp == '0':
            self.start_m()
        self.coins_m(inp)
        if self.frame_check_m(inp) == 3:
            return
        if self.obstacles_m(inp) == 3:
            return
        if self.input_m(inp) == 3:
            return
        self.move_m()
コード例 #5
0
def createcoins():
    for i in range(20):
        bc.append(coins(random.randint(60,bossarea),random.randint(1,height-5),bc))  
コード例 #6
0
 def do_coins(self, line):
     print coins.coins()
コード例 #7
0
ファイル: bloocoin.py プロジェクト: QuantSoft/bloocoin-client
 def do_coins(self, line):
     print coins.coins()
コード例 #8
0
def main():
#	from constants import *
	surface=[[' ' for x in range(width)]for y in range(height)]
	screen=set_screen(surface,width,height)                     #setting the basic screen
	surface_copy=copy.deepcopy(surface)
	surface[queen_x][queen_y]='Q'

	# creating instances
	Fire=fireball(surface,surface_copy,width,height)
	prince=player(surface,29,2)
	donk1=donkey(surface,9,2,-1)
	Donkey=[donk1]
	Coins=coins(width,height)
	Key=key(width,height,key_x,key_y)

	Coins.generate_coins()
	Coins.place_coins(surface)
	level=1
	lives=3
	score=0
	queen_captured=False
	key_captured=False
	running=True
	print '\n\n'
	print_surface(surface,score,lives,level)


	while running:
		surface=copy.deepcopy(surface_copy)
		x='s'
		if queen_captured==False:
			x=getchar()
		#	time.sleep(0.04)
			if x=='q':
				print 'You have decided to exit the game.'
				break
		else:
			queen_captured=False
			surface=Coins.place_coins(surface)
			
		if ord(x)==32:
			player_pos=prince.get_pos()
			surface[player_pos[0]-1][player_pos[1]]='P'
			surface[queen_x][queen_y]='Q'
			for i in range(len(Donkey)):
				surface=Donkey[i].donk_move(Fire,surface,Fire.flag%3)	
			surface=Fire.update_balls_location(surface)
			surface=Coins.place_coins(surface)
			print_surface(surface,score,lives,level)
			time.sleep(0.3)
			
			surface=copy.deepcopy(surface_copy)
			surface[player_pos[0]][player_pos[1]]='P'
			surface[queen_x][queen_y]='Q'
			for i in range(len(Donkey)):
				surface=Donkey[i].donk_move(Fire,surface,Fire.flag%3)	
			surface=Fire.update_balls_location(surface)
			surface=Coins.place_coins(surface)

			if Fire.fireball_hits_player(surface)==-1 :
				surface[player_pos[0]][player_pos[1]]='+'
				lives-=1
				score-=25
				running=False
				print_surface(surface,score,lives,level)
				
			for i in range(len(Donkey)):
				if  Donkey[i].donk_hits_player(surface)==-1:
					surface[player_pos[0]][player_pos[1]]='+'
					lives-=1
					score-=25
					running=False
					print_surface(surface,score,lives,level)


			if running==False:
				if lives>0:
					print 'You lost a life.'
					time.sleep(1.5)
					surface=copy.deepcopy(surface_copy)
					surface=prince.reset_player_pos(surface)
					surface[queen_x][queen_y]='Q'
					for i in range(len(Donkey)):
						surface=Donkey[i].donk_move(Fire,surface,Fire.flag%3)	
					surface=Coins.place_coins(surface)
					Fire.remove_fireballs()
					print_surface(surface,score,lives,level)
					running=True
				else:
					print 'You lost a life.'
					print "Game Over!! "

			else:
				print_surface(surface,score,lives,level)
				time.sleep(0.3)

			continue
			
		surface=prince.move(surface,x)
	#	surface=make_surface_move(surface)
		surface[queen_x][queen_y]='Q'
		for i in range(len(Donkey)):
			surface=Donkey[i].donk_move(Fire,surface,Fire.flag%3)	
		surface=Fire.update_balls_location(surface)
		surface=Coins.place_coins(surface)
		if prince.queen_captured(queen_x,queen_y):
			surface[queen_x][queen_y]='*'
			print_surface(surface,score,lives,level)
			queen_captured=True
			time.sleep(1.5)
		
		if queen_captured==True:
			print 'You have successfully completed level : ' +str(level)
			
			if level<3:
				level+=1
				if level==3:
					donk2=donkey(surface,8,7,1)
					Donkey.append(donk2)
				print 'proceeding to level : ' + str(level)
				surface_copy=Key.change_level(surface_copy,level)
				surface=prince.reset_player_pos(surface)
				Coins.generate_coins()
				Fire.remove_fireballs()
				continue
				
			else :
				print 'You have won the game.'
				break
			

		if Key.player_gets_key(surface)==True:
			surface_copy=Key.restore_surface_copy(surface_copy)
			surface=Key.restore_surface_copy(surface)
			surface[key_x][key_y]='P'
			time.sleep(1)
			print 'You got the key.'
			print 'Now the queen is free.'
			print_surface(surface,score,lives,level)
			continue
			
			
		player_pos=prince.get_pos()
		
		if Fire.fireball_hits_player(surface)==-1  or Fire.check_for_swap(surface,prince.cur_dir)==-1:
			surface[player_pos[0]][player_pos[1]]='+'
			lives-=1
			score-=25
			running=False
			
		for i in range(len(Donkey)):
			if running==True:
				if Donkey[i].donk_hits_player==-1:
					surface[player_pos[0]][player_pos[1]]='+'
					lives-=1
					score-=25
					running=False
				
			
		if Coins.player_gets_a_coin(player_pos[0],player_pos[1])==1:
			score+=5

		print_surface(surface,score,lives,level)
		if running==False:
			if lives>0:
				print 'You lost a life.'
				time.sleep(1.5)
				surface=copy.deepcopy(surface_copy)
				surface=prince.reset_player_pos(surface)
				surface[queen_x][queen_y]='Q'
				for i in range(len(Donkey)):
					surface=Donkey[i].donk_move(Fire,surface,Fire.flag%3)	
				surface=Coins.place_coins(surface)
				Fire.remove_fireballs()
				print_surface(surface,score,lives,level)
				running=True
			else:
				print 'You lost a life.'
				print "Game Over!! "
コード例 #9
0
ファイル: something.py プロジェクト: sisd/Laal_Mario
from os import system
from input import Input
from time import sleep
from boxes import boxes
from clouds import clouds
from mountains import mountains
from land import land
from obstacles import obstacles
from enemies import enemies
from marios import marios
from coins import coins
#from Boss import boss

#bos = boss()
mtn = mountains()
con = coins()
obs = obstacles()
lnd = land()
ino = Input()
bxx = boxes()
cld = clouds()
mro = marios('0')
ene = enemies()

death = 0
x = 0
gravity = 0
ite = 0
time_points = 10000

コード例 #10
0
 def _coinsdeclare(self, board):
     for i in range(50):
         a = coins(board)